比赛 |
4043级2023省选练习赛5 |
评测结果 |
AAAAAAAAAA |
题目名称 |
市场 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
5.286 s |
代码语言 |
C++ |
内存使用 |
15.23 MiB |
提交时间 |
2023-03-13 19:36:05 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=100000+5;
const ll inf=0x3f3f3f3f3f3f;
int n,q;
ll a[N];
struct segtree{
int l,r;ll mn,mx,sum,tag;
}tr[N<<2];
void pushup(int pt){
tr[pt].mn=min(tr[pt*2].mn,tr[pt*2+1].mn);
tr[pt].mx=max(tr[pt*2].mx,tr[pt*2+1].mx);
tr[pt].sum=tr[pt*2].sum+tr[pt*2+1].sum;
}
void build(int pt,int l,int r){
tr[pt]={l,r,inf,-inf,0,0};
if (l==r){
tr[pt].mn=tr[pt].mx=tr[pt].sum=a[l];return ;
}
int mid=(l+r)/2;
build(pt*2,l,mid);build(pt*2+1,mid+1,r);
pushup(pt);
}
void spread(int pt){
if (tr[pt].tag){ll w=tr[pt].tag;
tr[pt*2].mn+=w;tr[pt*2].mx+=w;tr[pt*2].tag+=w;
tr[pt*2].sum+=w*(tr[pt*2].r-tr[pt*2].l+1);
tr[pt*2+1].mn+=w;tr[pt*2+1].mx+=w;tr[pt*2+1].tag+=w;
tr[pt*2+1].sum+=w*(tr[pt*2+1].r-tr[pt*2+1].l+1);
tr[pt].tag=0;
}
}
void change(int pt,int x,int y,ll w){
int l=tr[pt].l,r=tr[pt].r;
if (x<=l&&r<=y){
tr[pt].mn+=w;tr[pt].mx+=w;
tr[pt].sum+=w*(tr[pt].r-tr[pt].l+1);tr[pt].tag+=w;
return ;
}spread(pt);
int mid=(l+r)/2;
if (x<=mid)change(pt*2,x,y,w);
if (mid+1<=y)change(pt*2+1,x,y,w);
pushup(pt);
}
void divide(int pt,int x,int y,ll w){
int l=tr[pt].l,r=tr[pt].r;
if (x<=l&&r<=y){
ll xa=tr[pt].mx-floor(1.0*tr[pt].mx/w),ya=tr[pt].mn-floor(1.0*tr[pt].mn/w);
if (xa==ya){
tr[pt].mn-=xa;tr[pt].mx-=xa;
tr[pt].sum-=xa*(tr[pt].r-tr[pt].l+1);tr[pt].tag-=xa;
return ;
}
}
spread(pt);
int mid=(l+r)/2;
if (x<=mid)divide(pt*2,x,y,w);
if (mid+1<=y)divide(pt*2+1,x,y,w);
pushup(pt);
}
ll query1(int pt,int x,int y){
int l=tr[pt].l,r=tr[pt].r;
if (x<=l&&r<=y)return tr[pt].mn;
spread(pt);
int mid=(l+r)/2;ll ans=inf;
if (x<=mid)ans=min(ans,query1(pt*2,x,y));
if (mid+1<=y)ans=min(ans,query1(pt*2+1,x,y));
pushup(pt);return ans;
}
ll query2(int pt,int x,int y){
int l=tr[pt].l,r=tr[pt].r;
if (x<=l&&r<=y)return tr[pt].sum;
spread(pt);
int mid=(l+r)/2;ll ans=0;
if (x<=mid)ans+=query2(pt*2,x,y);
if (mid+1<=y)ans+=query2(pt*2+1,x,y);
pushup(pt);return ans;
}
int main(){
freopen ("2017market.in","r",stdin);
freopen ("2017market.out","w",stdout);
scanf("%d%d",&n,&q);
for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
build(1,1,n);
for (int i=1;i<=q;i++){
int opt,l,r,c;scanf("%d%d%d",&opt,&l,&r);
l++;r++;
if (opt==1){
scanf("%lld",&c);change(1,l,r,c);
}
if (opt==2){
scanf("%lld",&c);divide(1,l,r,c);
}
if (opt==3){
printf("%lld\n",query1(1,l,r));
}
if (opt==4){
printf("%lld\n",query2(1,l,r));
}
}
}