QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#69592 | #5098. 第一代图灵机 | JohnAlfnov | 20 | 1641ms | 207648kb | C++14 | 3.9kb | 2022-12-28 21:00:14 | 2022-12-28 21:00:17 |
Judging History
answer
//Code by Lightningfall
//Start coding on ????/??/??
//Finish debugging on ????/??/??
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int a[200005],c[200005];
int op[200005],o1[200005],o2[200005];
int lst[200005],nxt[200005],pre[200005];
int pp[200005];
long long s[200005];
int ti[200005];
set<int>se[200005];
int T=0,gg=0;
vector<pair<int,int>>sm[800005];
void add(int l,int r,int o,int ll,int rr,int x,int v){
if(l>=ll&&r<=rr){
sm[o].emplace_back(x,v);
return;
}
int mid=(l+r)>>1;
if(mid>=ll)add(l,mid,o<<1,ll,rr,x,v);
if(mid<rr)add(mid+1,r,o<<1|1,ll,rr,x,v);
}
void update(int x,int y){
add(0,gg,1,ti[x],T-1,x,pre[x]);
ti[x]=T;
}
int mx[800005],lz[800005];
long long xx[800005];
struct apple{
int o,mx,lz;
long long xx;
apple(int o=0,int mx=0,int lz=0,long long xx=0):
o(o),mx(mx),lz(lz),xx(xx){}
};
stack<apple>st;
void logg(int o){
st.emplace(apple(o,mx[o],lz[o],xx[o]));
}
void build(int l,int r,int o){
if(l==r){
xx[o]=s[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,o<<1);
build(mid+1,r,o<<1|1);
mx[o]=max(mx[o<<1],mx[o<<1|1]);
xx[o]=max(xx[o<<1],xx[o<<1|1]);
}
void pushdown(int l,int r,int o,int vc){
if(!lz[o])return;
int mid=(l+r)>>1;
if(vc)logg(o<<1),logg(o<<1|1);
lz[o<<1]=lz[o],lz[o<<1|1]=lz[o];
mx[o<<1]=lz[o],mx[o<<1|1]=lz[o];
xx[o<<1]=s[mid]-s[lz[o]-1],xx[o<<1|1]=s[r]-s[lz[o]-1];
lz[o]=0;
}
void modify(int l,int r,int o,int ll,int rr,int f,int mm){
if(mm>f)return;
if(l==r&&max(mm,mx[o])>f)return;
if(l>=ll&&r<=rr&&max(mm,mx[o])<=f){
logg(o);
lz[o]=mx[o]=f;
xx[o]=s[r]-s[f-1];
return;
}
logg(o);
pushdown(l,r,o,1);
int mid=(l+r)>>1;
int MM=max(mm,mx[o<<1]);
if(mid>=ll)modify(l,mid,o<<1,ll,rr,f,mm);
if(mid<rr)modify(mid+1,r,o<<1|1,ll,rr,f,MM);
mx[o]=max(mx[o<<1],mx[o<<1|1]);
xx[o]=max(xx[o<<1],xx[o<<1|1]);
}
long long query(int l,int r,int o,int ll,int rr){
if(l>=ll&&r<=rr)return xx[o];
int mid=(l+r)>>1;
pushdown(l,r,o,0);
long long ans=0;
if(mid>=ll)ans=max(ans,query(l,mid,o<<1,ll,rr));
if(mid<rr)ans=max(ans,query(mid+1,r,o<<1|1,ll,rr));
return ans;
}
vector<int>xw[200005];
int find(int l,int r,int o,int x){
if(l==r){
if(mx[o]>x)return l;
return l+1;
}
int mid=(l+r)>>1;
pushdown(l,r,o,0);
if(mx[o<<1]>x)return find(l,mid,o<<1,x);
return find(mid+1,r,o<<1|1,x);
}
int xm[200005];
void solve(int l,int r,int o){
while(st.size())st.pop();
for(auto pi:sm[o]){
int x=pi.first,y=pi.second;
modify(1,n,1,x,n,y+1,0);
}
stack<apple>stt=st;
if(l==r){
for(auto tt:xw[l]){
int L=o1[tt],R=o2[tt];
int wz=find(1,n,1,L);
long long ans=0;
if(wz-1>=L)ans=max(ans,s[min(R,wz-1)]-s[L-1]);
if(wz<=R)ans=max(ans,query(1,n,1,wz,R));
printf("%lld\n",ans);
}
}else{
int mid=(l+r)>>1;
solve(l,mid,o<<1);
solve(mid+1,r,o<<1|1);
}
while(stt.size()){
auto at=stt.top();
stt.pop();
lz[at.o]=at.lz;
mx[at.o]=at.mx;
xx[at.o]=at.xx;
}
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;++i)scanf("%d",&a[i]),s[i]=a[i]+s[i-1];
for(int i=1;i<=n;++i)scanf("%d",&c[i]);
for(int i=1;i<=n;++i)nxt[i]=n+1,ti[i]=T;
for(int i=1;i<=m;++i){
se[i].emplace(0);
se[i].emplace(n+1);
}
for(int i=1;i<=n;++i){
pre[i]=pp[i]=lst[c[i]],nxt[lst[c[i]]]=i;
lst[c[i]]=i;
se[c[i]].emplace(i);
xm[i]=max(xm[i-1],pp[i]);
}
for(int i=1;i<=q;++i)
scanf("%d%d%d",&op[i],&o1[i],&o2[i]),gg+=(op[i]-1);
for(int i=1;i<=q;++i){
if(op[i]==2){
++T;
int x=o1[i],cc=o2[i];
if(cc==c[x])continue;
auto it=se[cc].upper_bound(x);
int wz=*it;
--it;
int zw=*it;
if(nxt[x]<=n)update(nxt[x],pre[x]);
pre[nxt[x]]=pre[x],nxt[pre[x]]=nxt[x];
update(x,zw);
pre[x]=zw,nxt[zw]=x;
if(wz<=n)update(wz,x);
pre[wz]=x,nxt[x]=wz;
se[c[x]].erase(x);
c[x]=cc;
se[c[x]].emplace(x);
}else{
xw[T].emplace_back(i);
}
}
for(int i=1;i<=n;++i)add(0,gg,1,ti[i],gg,i,pre[i]);
build(1,n,1);
solve(0,gg,1);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 25ms
memory: 38524kb
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:
118571 90725 79596 95154 95154 94493 72411 100567 100567 100567 100567 90725 100567 100567 90725 118571 94493 95154 58191 118571 100567 100567 100567 39374 89208 118571 99923 100567 100567 95724 87252 100567 118571 100567 100567 100567 100567 100567 100567 26617 100567 99923 100567 118571 100567 100...
result:
wrong answer 993rd lines differ - expected: '107743', found: '118571'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 1641ms
memory: 207648kb
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:
1232419 1222519 1232419 1232419 1232419 1232419 1232419 1232419 1232419 1232419 1040511 1148070 1232419 1232419 1232419 1232419 1206368 1206368 1232419 1232419 1232419 1222519 1167757 1206368 1214212 1222519 1232419 1222519 1222519 1160928 1011843 1232419 1232419 1189403 1222519 1232419 1222519 1148...
result:
wrong answer 63943rd lines differ - expected: '1108903', found: '1094982'
Subtask #3:
score: 20
Accepted
Test #5:
score: 20
Accepted
time: 300ms
memory: 111372kb
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:
46702944 46702944 38383720 38615532 38615532 42801975 39035571 46702944 46702944 46702944 27438528 38402892 46702944 46702944 42801975 42323113 39035571 42323113 46702944 46702944 46702944 41821993 46702944 34075405 46702944 38615532 46702944 28680653 46702944 42801975 42801975 38025842 46702944 467...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 322ms
memory: 111484kb
input:
200000 20000 200000 35105 74665 63960 162062 164953 63344 145369 115837 108866 61866 110690 123641 106889 65531 115933 163273 7531 128251 158561 169221 149787 40911 54465 92737 73473 10609 62701 89599 40007 40272 7318 129047 171198 90131 111281 85645 174001 140289 135851 26785 136485 31989 16313 888...
output:
43816163 35764822 45394839 45394839 45394839 43816163 45394839 43816163 40900280 38802753 45394839 45394839 43816163 34715395 45394839 43816163 43816163 45394839 43816163 45394839 45394839 43816163 35764822 45394839 43816163 43816163 16638306 45394839 35764822 45394839 34921501 45394839 45394839 409...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 394ms
memory: 111400kb
input:
200000 20000 200000 80203 178041 44172 21001 54489 120807 60663 147301 166763 49071 98913 115641 30627 164382 54165 165057 46105 9628 57953 86346 8273 137848 44871 119728 107309 132201 72483 198451 58505 185062 27039 49401 172444 101505 180973 59256 44859 53105 195233 161425 132423 2566 189331 15869...
output:
44318499 33827474 43556508 44318499 43556508 38914187 44318499 43556508 47858466 44318499 40709211 43556508 35706654 43556508 44318499 44318499 47858466 44318499 35359541 43556508 43556508 43556508 47858466 31755901 43556508 44318499 43556508 43556508 44318499 44318499 44318499 44318499 43556508 443...
result:
ok 200000 lines
Test #8:
score: 0
Accepted
time: 327ms
memory: 111184kb
input:
200000 20000 200000 69757 155771 81753 9285 168151 179881 122502 198324 140481 33185 155861 173423 117211 80727 63754 167913 121921 185921 182266 24801 167005 191511 77176 176741 117041 42534 10209 6241 83970 67652 164225 155249 125057 23841 71911 133150 79732 125061 7111 29841 142343 129299 155501 ...
output:
54623112 54623112 54623112 36983972 41889300 49604086 43664569 54623112 42438674 39404039 43664569 35418806 43664569 54623112 49604086 49604086 42438674 54623112 54623112 33869050 54623112 42438674 36847615 39404039 54623112 54623112 43664569 49604086 42438674 54623112 54623112 43664569 49604086 424...
result:
ok 200000 lines
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%