QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#78174 | #3272. 简单数据结构 | tricyzhkx | 20 | 0ms | 0kb | C++14 | 4.8kb | 2023-02-17 10:30:20 | 2023-02-17 10:30:24 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
typedef vector<int> vi;
ll a[200010];
vi vec[200010];
struct Query
{
int op,l,r;
ll v;
}que[200010];
struct Point
{
ll x,y;
int t;
Point(ll _x=0,ll _y=0,int _t=0):x(_x),y(_y),t(_t){}
Point operator-(const Point &a)const{return Point(x-a.x,y-a.y);}
ll operator*(const Point &a)const{return x*a.y-y*a.x;}
bool operator<(const Point &a)const
{
if(x!=a.x) return x<a.x;
return y<a.y;
}
ll calc(ll p){return y-x*p;}
}b[200010],stk[200010];
struct Seg1
{
ll sum[600010],w[600010],tag[600010];
void build(int rt,int l,int r)
{
if(l==r) return sum[rt]=a[l],w[rt]=l,void();
int mid=(l+r)/2;
build(rt*2,l,mid);build(rt*2+1,mid+1,r);
sum[rt]=sum[rt*2]+sum[rt*2+1];
w[rt]=w[rt*2]+w[rt*2+1];
}
void push(int rt,ll t){tag[rt]+=t;sum[rt]+=t*w[rt];}
void pushdown(int rt)
{
if(!tag[rt]) return;
push(rt*2,tag[rt]);push(rt*2+1,tag[rt]);
tag[rt]=0;
}
void update(int rt,int l,int r,int x)
{
if(l==r) return w[rt]=sum[rt]=0,void();
pushdown(rt);
int mid=(l+r)/2;
if(x<=mid) update(rt*2,l,mid,x);
else update(rt*2+1,mid+1,r,x);
sum[rt]=sum[rt*2]+sum[rt*2+1];
w[rt]=w[rt*2]+w[rt*2+1];
}
ll query(int rt,int l,int r,int x,int y)
{
if(l>y || r<x) return 0;
if(x<=l && r<=y) return sum[rt];
pushdown(rt);
int mid=(l+r)/2;
return query(rt*2,l,mid,x,y)+query(rt*2+1,mid+1,r,x,y);
}
}S1;
struct Seg2
{
ll sum[600010],cnt[600010],w[600010],tag[600010],add[600010];
pli minn[600010];
void build(int rt,int l,int r)
{
tag[rt]=-1;minn[rt]={1e18,0};
if(l==r) return;
int mid=(l+r)/2;
build(rt*2,l,mid);build(rt*2+1,mid+1,r);
}
void pushtag(int rt,ll t)
{
add[rt]=0;tag[rt]=t;sum[rt]=t*cnt[rt];
if(cnt[rt]) minn[rt].first=t;
}
void pushadd(int rt,ll a)
{
add[rt]+=a;sum[rt]+=a*w[rt];
if(cnt[rt]) minn[rt].first+=a*minn[rt].second;
}
void pushdown(int rt)
{
if(tag[rt]>=0)
{
pushtag(rt*2,tag[rt]);pushtag(rt*2+1,tag[rt]);
tag[rt]=-1;
}
if(add[rt])
{
pushadd(rt*2,add[rt]);pushadd(rt*2+1,add[rt]);
add[rt]=0;
}
}
void update(int rt,int l,int r,ll v)
{
if(l==r)
{
if(minn[rt].first>=v) pushtag(rt,v);
return;
}
pushdown(rt);
int mid=(l+r)/2;
if(minn[rt*2+1].first<v) update(rt*2+1,mid+1,r,v);
else pushtag(rt*2+1,v),update(rt*2,l,mid,v);
sum[rt]=sum[rt*2]+sum[rt*2+1];
minn[rt]=min(minn[rt*2],minn[rt*2+1]);
}
void update(int rt,int l,int r,int x,ll y)
{
if(l==r) return cnt[rt]=1,minn[rt]={y,x},w[rt]=x,sum[rt]=y,void();
pushdown(rt);
int mid=(l+r)/2;
if(x<=mid) update(rt*2,l,mid,x,y);
else update(rt*2+1,mid+1,r,x,y);
sum[rt]=sum[rt*2]+sum[rt*2+1];
minn[rt]=min(minn[rt*2],minn[rt*2+1]);
cnt[rt]=cnt[rt*2]+cnt[rt*2+1];
w[rt]=w[rt*2]+w[rt*2+1];
}
ll query(int rt,int l,int r,int x,int y)
{
if(l>y || r<x) return 0;
if(x<=l && r<=y) return sum[rt];
pushdown(rt);
int mid=(l+r)/2;
return query(rt*2,l,mid,x,y)+query(rt*2+1,mid+1,r,x,y);
}
}S2;
void solve(int l,int r,const vi &Q,const vi &S)
{
if(S.empty() || Q.empty()) return;
if(l==r)
{
for(int i:S)
if(b[Q[0]].calc(i)<a[i])
vec[l].push_back(i);
return;
}
int mid=(l+r)/2,tp=0,cur=1;
vi L,R,QL,QR;
for(int i:Q)
if(b[i].t<=mid)
{
QL.push_back(i);
while(tp>1 && (b[i]-stk[tp])*(stk[tp]-stk[tp-1])>=0) tp--;
stk[++tp]=b[i];
}
else QR.push_back(i);
int sz=S.size();
for(int i=0;i<sz-1;i++) assert(S[i]<S[i+1]);
for(int i:S)
{
ll minn=1e18;
for(int j=1;j<=tp;j++) minn=min(minn,stk[j].calc(i));
while(cur<tp && stk[cur].calc(i)>stk[cur+1].calc(i)) cur++;
assert(minn==stk[cur].calc(i));
if(stk[cur].calc(i)<a[i]) L.push_back(i);
else R.push_back(i);
}
solve(l,mid,QL,L);solve(mid+1,r,QR,R);
}
int main()
{
int n,q,cur=0,cnt=0;
cin>>n>>q;
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=q;i++)
{
scanf("%d",&que[i].op);
if(que[i].op==1) scanf("%lld",&que[i].v);
else if(que[i].op==3) scanf("%d%d",&que[i].l,&que[i].r);
}
for(int i=1;i<=q;i++)
{
if(que[i].op==1) b[++cnt]=Point(cur,que[i].v,i);
else if(que[i].op==2) cur++;
}
sort(b+1,b+cnt+1);
vi S(n),Q(cnt);
iota(S.begin(),S.end(),1);
iota(Q.begin(),Q.end(),1);
solve(1,q,Q,S);
S1.build(1,1,n);S2.build(1,1,n);
for(int i=1;i<=q;i++)
{
if(que[i].op==1) S2.update(1,1,n,que[i].v);
else if(que[i].op==2) S1.push(1,1),S2.pushadd(1,1);
else printf("%lld\n",S1.query(1,1,n,que[i].l,que[i].r)+S2.query(1,1,n,que[i].l,que[i].r));
for(int j:vec[i])
{
int cur=0;
for(int k=1;k<i;k++)
if(que[k].op==1)
assert(a[j]+(ll)j*cur<=que[k].v);
else if(que[k].op==2) cur++;
assert(a[j]+(ll)j*cur>que[i].v);
S1.update(1,1,n,j),S2.update(1,1,n,j,que[i].v);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
result:
Subtask #2:
score: 20
Accepted
Subtask #3:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%