QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#882467 | #5098. 第一代图灵机 | _FJqwq | 0 | 885ms | 201452kb | C++23 | 3.9kb | 2025-02-05 07:17:09 | 2025-02-05 07:17:10 |
Judging History
answer
// by wkc
#pragma target("avx512f,sse2,sse3,sse4,sse4.2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=250005,M=5000005,inf=1e18;
int n,m,q,a[N],col[N],ql[N],qr[N];
ll sum[N],maxx[N*4];
#define lc k<<1
#define rc k<<1|1
#define ls lc,l,mid
#define rs rc,mid+1,r
struct T{int x,y;};vector<T>v[N*4];
void change(int k,int l,int r,int x,int y,int v1,int v2){
if(x<=l&&r<=y){
v[k].push_back(T{v1+1,v2});
return ;
}
int mid=l+r>>1;
if(x<=mid) change(ls,x,y,v1,v2);
if(mid<y) change(rs,x,y,v1,v2);
}
int tim[N],tot;set<int>s[N];
void ins1(int x,int y,int z){
s[x].insert(y);
auto i=s[x].find(y);auto j=i,p=i;
j++;p--;
if(i!=s[x].begin())if(j!=s[x].end()){change(1,1,q,tim[*j],z,(*p),(*j));}
if(j!=s[x].end()) tim[*j]=z;
if(i!=s[x].begin()) tim[*i]=z;
}
void del1(int x,int y,int z){
auto i=s[x].find(y);auto j=i,p=i;
j++;p--;
if(j!=s[x].end()){change(1,1,q,tim[*j],z,(*i),(*j));}
if(i!=s[x].begin()){change(1,1,q,tim[*i],z,(*p),(*i));}
if(i!=s[x].begin())if(j!=s[x].end()) tim[*j]=z;
s[x].erase(i);
}
struct node{int tag,pre;ll ans2;}tree[N*4];
void build1(int k,int l,int r){
tree[k].pre=1,tree[k].ans2=-inf;
if(l==r){maxx[k]=sum[l];return ;}
int mid=l+r>>1;
build1(ls),build1(rs);
maxx[k]=max(maxx[lc],maxx[rc]);
}
ll ask1(int k,int l,int r,int x,int y){
if(x<=l&&r<=y) return maxx[k];
int mid=l+r>>1;
if(x<=mid&&mid<y) return max(ask1(ls,x,y),ask1(rs,x,y));
if(x<=mid) return ask1(ls,x,y);
return ask1(rs,x,y);
}
int top;struct A{int p;node w;}stk[M];
void pushdown(int k){
stk[++top]=A{lc,tree[lc]};
stk[++top]=A{rc,tree[rc]};
if(tree[k].tag){
tree[lc].pre=tree[rc].pre=tree[k].tag;
tree[lc].tag=tree[rc].tag=tree[k].tag;
tree[lc].ans2=maxx[lc]-sum[tree[k].tag-1];
tree[rc].ans2=maxx[rc]-sum[tree[k].tag-1];
tree[k].tag=0;
}
}
void pushup(int k){
tree[k].pre=max(tree[lc].pre,tree[rc].pre);
tree[k].ans2=max(tree[lc].ans2,tree[rc].ans2);}
int ask(int k,int l,int r,int d){
stk[++top]=A{k,tree[k]};
if(l==r) return l+(tree[k].pre<=d);
int mid=l+r>>1;
pushdown(k);
if(tree[k].pre<=d) return ask(rs,d);
return ask(ls,d);
}
void change2(int k,int l,int r,int x,int y,int d){
stk[++top]=A{k,tree[k]};
if(x<=l&&r<=y){
tree[k].tag=tree[k].pre=d;
tree[k].ans2=maxx[k]-sum[d-1];
return ;
}
int mid=l+r>>1;
pushdown(k);
if(x<=mid) change2(ls,x,y,d);
if(mid<y) change2(rs,x,y,d);
pushup(k);
}
ll ask2(int k,int l,int r,int x,int y){
stk[++top]=A{k,tree[k]};
if(x<=l&&r<=y) return tree[k].ans2;
int mid=l+r>>1;
pushdown(k);
if(x<=mid&&mid<y) return max(ask2(ls,x,y),ask2(rs,x,y));
if(x<=mid) return ask2(ls,x,y);
return ask2(rs,x,y);
}
void work(int k,int l,int r){
int las=top,p;
// printf("%d %d %d\n",k,l,r);
for(T e:v[k]){
// printf(":::%d %d\n",e.x,e.y);
p=ask(1,1,n,e.x)-1;
if(e.y<=p) change2(1,1,n,e.y,p,e.x);
}
if(l==r){
if(ql[l]!=0){
int pos;ll ans=0;
pos=ask(1,1,n,ql[l])-1;
if(ql[l]<=pos) ans=max(ans,ask1(1,1,n,ql[l],min(qr[l],pos))-sum[ql[l]-1]);
// printf("::%d %d %d %d\n",pos,ql[l],ask1(1,1,n,ql[l],pos),sum[ql[l]-1]);
if(pos+1<=qr[l]) ans=max(ans,ask2(1,1,n,max(ql[l],pos+1),qr[l]));
printf("%lld\n",ans);
}
}
else{
int mid=l+r>>1;
work(ls);
work(rs);
}
while(top>las){
tree[stk[top].p]=stk[top].w;
top--;
}
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;i++) scanf("%d",&col[i]);
// for(int i=1;i<=n;i++) s[col[i]].insert(i);
for(int i=1;i<=n;i++) ins1(col[i],i,1);
for(int i=1,op,x,y;i<=q;i++){
scanf("%d%d%d",&op,&x,&y);
if(op==2){
del1(col[x],x,i);
// s[col[x]].erase(x);
col[x]=y;
// s[col[x]].insert(x);
ins1(col[x],x,i);
}
else ql[i]=x,qr[i]=y;
}
for(int i=1;i<=n;i++) del1(col[i],i,q);
build1(1,1,n);
work(1,1,q);
return 0;
}
/*
3 3 3
20 4 6
1 1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 14ms
memory: 36376kb
input:
5000 200 5000 2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...
output:
152550 144241 101276 119040 119040 94493 121553 144241 144796 144796 119040 144241 144241 144241 128064 152550 94493 95154 85415 127909 144796 144241 144241 57034 113232 144241 124717 144241 144241 95724 128064 144241 152550 144241 144241 144241 144796 144241 144241 41220 144241 144796 144796 152550...
result:
wrong answer 1st lines differ - expected: '118571', found: '152550'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 885ms
memory: 201452kb
input:
200000 10 200000 55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28870726 0 0 0 0 0 0 135242812 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 333508054 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 326583209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 325056459 0 0 0 0 0 0 0 0...
result:
wrong answer 1st lines differ - expected: '1232419', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 403ms
memory: 166628kb
input:
200000 20000 200000 30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...
output:
6621858508 13603822015 931223557 2620475833 750333254 13603822015 3005023565 9921961872 13603822015 2836756946 125441385 38402892 3319086817 13603822015 13603822015 13603822015 4220592768 13603822015 13603822015 4642753825 13603822015 11169544999 3380344537 1694960013 13336827144 2557945957 13603822...
result:
wrong answer 1st lines differ - expected: '46702944', found: '6621858508'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%