QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#390327 | #3272. 简单数据结构 | marher | 20 | 10ms | 44152kb | C++14 | 4.0kb | 2024-04-15 11:53:04 | 2024-04-15 11:53:04 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=6e5+50,inf=1e18;
struct ask
{
int opt,v,l,r;
}Q[N];
int n,a[N],q,v[N],fir[N],m,tot,ch[N][2],vi[N],ro;
vector<int>tmp,in[N];
#define mid ((l+r)>>1)
struct line
{
int k,b;
int f(int x)
{
return k*x+b;
}
}mi[N];
void insert(int&x,int l,int r,line d)
{
if(!x)x=++tot;
if(!vi[x]||(mi[x].f(l)>=d.f(l)&&mi[x].f(r)>=d.f(r))){mi[x]=d;vi[x]=1;return;}
if(mi[x].f(l)<=d.f(l)&&mi[x].f(r)<=d.f(r))return;
if(mi[x].f(mid)>=d.f(mid))swap(d,mi[x]);if(l==r)return;
if(d.f(l)<=mi[x].f(l))insert(ch[x][0],l,mid,d);else insert(ch[x][1],mid+1,r,d);
}
int find(int x,int l,int r,int d)
{
if(!vi[x])return inf;
if(l==r)return mi[x].f(d);
return min(mi[x].f(d),(d<=mid?find(ch[x][0],l,mid,d):find(ch[x][1],mid+1,r,d)));
}
void clear()
{
for(int i=1;i<=tot;i++)ch[i][0]=ch[i][1]=vi[i]=0;
tot=ro=0;
}
void solve(int l,int r,vector<int>tmp)
{
if(tmp.empty())return;
if(l==r)
{
for(auto x:tmp)if(x*fir[l]+a[x]>=v[l])in[l].push_back(x);
return;
}
for(int i=l;i<=mid;i++)insert(ro,1,n,(line){-fir[i],v[i]});
vector<int>L,R;
for(auto x:tmp)
{
if(a[x]>=find(1,1,n,x))L.push_back(x);
else R.push_back(x);
}
clear();solve(l,mid,L);solve(mid+1,r,R);
}
int sum[N],ad[N],la[N],mx[N],mxad[N],val[N],num[N],tad[N],cm[N],siz[N];
#define ls (x<<1)
#define rs (x<<1|1)
#define LS ls,l,mid
#define RS rs,mid+1,r
void up1(int x)
{
sum[x]=sum[ls]+sum[rs];
ad[x]=ad[ls]+ad[rs];
}
void up2(int x)
{
if(siz[rs])mx[x]=mx[rs],mxad[x]=mxad[rs];
val[x]=val[ls]+val[rs];tad[x]=tad[ls]+tad[rs];siz[x]=siz[ls]+siz[rs];
}
void mk1(int x,int d)
{
la[x]+=d;
sum[x]+=d*ad[x];
}
void mk2(int x,int d)
{
num[x]+=d;
val[x]+=d*tad[x];
mx[x]+=d*mxad[x];
}
void mk3(int x,int w)
{
if(!siz[x])return;
cm[x]=w;mx[x]=w;val[x]=w*siz[x];num[x]=0;
}
void down1(int x)
{
if(!la[x])return;
mk1(ls,la[x]);mk1(rs,la[x]);
la[x]=0;
}
void down2(int x)
{
if(cm[x]!=inf)mk3(ls,cm[x]),mk3(rs,cm[x]),cm[x]=inf;
if(!num[x])return;
mk2(ls,num[x]);mk2(rs,num[x]);
num[x]=0;
}
void build(int x,int l,int r)
{
cm[x]=inf;
if(l==r)
{
sum[x]=a[l];ad[x]=l;
return;
}
build(LS);build(RS);up1(x);
}
void del(int x,int l,int r,int d)
{
if(l==r)
{
sum[x]=la[x]=ad[x]=0;
return;
}
down1(x);
if(d<=mid)del(LS,d);else del(RS,d);
up1(x);
}
void insert(int x,int l,int r,int d,int w)
{
if(l==r)
{
mx[x]=val[x]=w;tad[x]=mxad[x]=l;siz[x]=1;
return;
}
down2(x);
if(d<=mid)insert(LS,d,w);else insert(RS,d,w);
up2(x);
}
void solve(int x,int l,int r,int d)
{
if(mx[x]<=d)return;
if(l==r)return mk3(x,d);
down2(x);
if(mx[ls]>=d)mk3(rs,d),solve(LS,d);
else solve(RS,d);
up2(x);
}
int find(int x,int l,int r,int L,int R)
{
if(L<=l&&R>=r)return sum[x]+val[x];
down1(x);down2(x);
int ans=0;
if(L<=mid)ans+=find(LS,L,R);
if(R>mid)ans+=find(RS,L,R);
return ans;
}
main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i],tmp.push_back(i);
for(int i=1;i<=q;i++)
{
cin>>Q[i].opt;
if(Q[i].opt==2)fir[m+1]++;
if(Q[i].opt==1)
{
m++;fir[m+1]=fir[m];
cin>>Q[i].v;v[m]=Q[i].v;
}
if(Q[i].opt==3)cin>>Q[i].l>>Q[i].r;
}
if(m)solve(1,m,tmp);
build(1,1,n);m=0;
for(int i=1;i<=q;i++)
{
if(Q[i].opt==1)
{
++m;
solve(1,1,n,v[m]);
for(auto x:in[m])del(1,1,n,x),insert(1,1,n,x,v[m]);
}
if(Q[i].opt==2)mk1(1,1),mk2(1,1);
if(Q[i].opt==3)cout<<find(1,1,n,Q[i].l,Q[i].r)<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 10ms
memory: 43984kb
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:
512185934 455189773 121665669 462801410 431269939 45671866 498282444 726635165 222004631 41963113 542872235 1107582840 340629089 2144625 455404212 220461451 20719635 108759503 22099550 34631220 55848925 92362584 36949030 86469096 43509864 50829332 1334865 76069109 114623436 13564322 79974466 1523008...
result:
wrong answer 4th numbers differ - expected: '408693244', found: '462801410'
Subtask #2:
score: 20
Accepted
Subtask #3:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 44152kb
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:
512185934 455189773 121665669 462801410 431269939 45671866 498282444 726635165 222004631 41963113 542872235 1107582840 340629089 2144625 455404212 220461451 20719635 108759503 22099550 34631220 55848925 92362584 36949030 86469096 43509864 50829332 1334865 76069109 114623436 13564322 79974466 1523008...
result:
wrong answer 4th numbers differ - expected: '408693244', found: '462801410'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%