QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345291 | #5098. 第一代图灵机 | zzafanti | 0 | 399ms | 28312kb | C++20 | 2.4kb | 2024-03-06 19:07:54 | 2024-03-06 19:07:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using E=long long;
vector<E> sum;
struct segment{
vector<E> maxx,s;
segment(int sz){
maxx=s=vector<E>(sz*4+2);
}
E getnum(int u,int l,int r,int val){
if(maxx[u]<=val) return sum[r]-sum[val];
if(l==r) return s[u];
int mid=(l+r)>>1;
if(maxx[u<<1]>val) return max(s[u],getnum(u<<1,l,mid,val));
return max(sum[mid]-sum[val],getnum(u<<1|1,mid+1,r,val));
}
void maintain(int u,int l,int r){
int mid=(l+r)>>1;
maxx[u]=max(maxx[u<<1],maxx[u<<1|1]);
s[u]=getnum(u<<1|1,mid+1,r,maxx[u<<1]);
}
void modify(int u,int l,int r,int pos,int val){
if(l==r){
maxx[u]=val;
s[u]=sum[l]-sum[val];
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) modify(u<<1,l,mid,pos,val);
else modify(u<<1|1,mid+1,r,pos,val);
maintain(u,l,r);
}
E query(int u,int l,int r,int L,int R){
if(L<=l&&r<=R){
return getnum(u,l,r,L-1);
}
int mid=(l+r)>>1;
E ret=0;
if(L<=mid) ret=query(u<<1,l,mid,L,R);
if(mid<R) ret=max(ret,query(u<<1|1,mid+1,r,L,R));
return ret;
}
};
int main(){
#ifdef zzafanti
freopen("in.in","r",stdin);
#endif // zzafanti
cin.tie(nullptr),cout.tie(nullptr)->sync_with_stdio(false);
int n,m,Q;
cin>>n>>m>>Q;
sum=vector<E>(n+1);
vector<multiset<int>> pos(m+1);
for(int i=1; i<=n; i++) cin>>sum[i];
for(int i=2; i<=n; i++) sum[i]+=sum[i-1];
vector<int> c(n+1);
segment S(n);
for(int i=1; i<=n; i++){
cin>>c[i];
int T=0;
if(pos[c[i]].size()) T=*prev(pos[c[i]].end());
S.modify(1,1,n,i,T);
pos[c[i]].insert(i);
}
while(Q--){
int op;
E l,r;
cin>>op>>l>>r;
if(op==1){
cout<<S.query(1,1,n,l,r)<<'\n';
}
else{
auto pnt=pos[c[l]].find(l);
assert(pnt!=pos[c[l]].end());
if(!pos[r].size()){
S.modify(1,1,n,l,0);
}
else{
auto pre=pos[r].lower_bound(l);
if(pre==pos[r].begin()) S.modify(1,1,n,l,0);
else pre=prev(pre),S.modify(1,1,n,l,*pre),pre++;
if(pre!=pos[r].end()) S.modify(1,1,n,*pre,l);
}
pnt++;
if(pnt!=pos[c[l]].end()){
int T=0;
if(prev(pnt)!=pos[c[l]].begin()) T=*prev(prev(pnt));
S.modify(1,1,n,*pnt,T);
}
pos[c[l]].erase(l);
pos[r].insert(l);
c[l]=r;
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 4156kb
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:
1802092 432992 143033 1935376 2493673 628229 726388 1097802 2646132 210951 2384821 432992 2594334 760980 191740 1065662 277160 304232 83889 952599 1253911 2493673 662724 39374 648685 952599 437547 232685 244579 235297 501619 2088743 930351 277160 459079 423488 946455 466602 662724 34330 1770070 1146...
result:
wrong answer 1st lines differ - expected: '118571', found: '1802092'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 399ms
memory: 27544kb
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:
1690492 3095094 2055958 2055958 3568627 3568627 4612047 1838697 3461156 3600625 4145064 3428628 2055958 3772595 3224217 1311003 3568627 3568627 1640768 3259709 3592859 11855676 3313362 4562540 1214212 1494075 3151073 2506068 1690492 2862763 5370489 3568627 3568627 2378654 6011621 3534117 3095094 215...
result:
wrong answer 1st lines differ - expected: '1232419', found: '1690492'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 309ms
memory: 28312kb
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:
5462471951 1427989353 931158568 2492172111 750265809 9534839833 3002888614 2762055353 2269661720 947390860 125441385 519479345 3304436888 3827615780 2535393597 1880621346 2518215380 3532955410 3144714126 4641346300 2355976068 3578662240 1298170005 1694313410 1848528011 2552767418 3977254608 16594241...
result:
wrong answer 1st lines differ - expected: '46702944', found: '5462471951'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%