QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67663 | #5098. 第一代图灵机 | skicean | 0 | 416ms | 31456kb | C++14 | 2.4kb | 2022-12-10 23:15:37 | 2022-12-10 23:15:38 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <set>
#define macro_expand(x) #x
#define print_macro(x) printf("%s\n",macro_expand(x))
#define FOR(i,l,r) for(int i=(l),i##ADJK=(r);i<=i##ADJK;++i)
#define ROF(i,r,l) for(int i=(r),i##ADJK=(l);i>=i##ADJK;--i)
using namespace std;
typedef long long LL;
const int MN=2e5+5;
LL N,M,Q,sum[MN];
int col[MN];
set<int> pos[MN];
int get_nxt(int c,set<int>::iterator it){
++it;
if(pos[c].end()==it)return N+1;
else return *it;
}
int get_pre(int c,set<int>::iterator it){
if(it==pos[c].begin())return -1;
else return *(--it);
}
int nxt[MN],mn[MN*4];
LL res[MN*4];
LL calc(int o,int l,int r,int z){
if(z<mn[o])return -1;
if(l==r)return sum[z]-sum[l];
int mid=(l+r)>>1;
LL tmp=calc(o<<1|1,mid+1,r,z);
if(tmp!=-1)return max(tmp,res[o]);
else return calc(o<<1,l,mid,z);
}
LL query(int o,int l,int r,int ql,int qr,int &z){
if(l>qr||r<ql)return -1;
if(z<mn[o])return -1;
if(ql<=l&&r<=qr){
LL ret=calc(o,l,r,z);
z=min(z,mn[o]-1);
return ret;
}
int mid=(l+r)>>1;
LL ret=query(o<<1|1,mid+1,r,ql,qr,z);
return max(ret,query(o<<1,l,mid,ql,qr,z));
}
void modify(int o,int l,int r,int p,int v){
if(l==r){
mn[o]=v;
return;
}
int mid=(l+r)>>1;
if(p<=mid)modify(o<<1,l,mid,p,v);
else modify(o<<1|1,mid+1,r,p,v);
res[o]=calc(o<<1,l,mid,mn[o]-1);
mn[o]=min(mn[o<<1],mn[o<<1|1]);
}
void build(int o,int l,int r){
if(l==r){
mn[o]=nxt[l];
return;
}
int mid=(l+r)>>1;
build(o<<1,l,mid),build(o<<1|1,mid+1,r);
res[o]=calc(o<<1,l,mid,mn[o<<1|1]-1);
mn[o]=min(mn[o<<1],mn[o<<1|1]);
}
int main(){
scanf("%lld%lld%lld",&N,&M,&Q);
FOR(i,1,N)scanf("%lld",&sum[i]);
FOR(i,1,N)sum[i]+=sum[i-1],scanf("%d",&col[i]);
FOR(i,1,N)pos[col[i]].insert(i);
FOR(i,1,N)nxt[i]=get_nxt(col[i],pos[col[i]].find(i));
build(1,1,N);
FOR(i,1,Q){
int op=0,a=0,b=0;
scanf("%d%d%d",&op,&a,&b);
if(op==1){
int z=b;
printf("%lld\n",query(1,1,N,a,b,z));
}else{
if(col[a]==b)continue;
auto tmp=pos[col[a]].find(a);
int x=get_pre(col[a],tmp),y=get_nxt(col[a],tmp);
if(x!=-1)nxt[x]=y,modify(1,1,N,x,y);
col[a]=b;
pos[b].insert(a);
tmp=pos[b].find(a);
x=get_pre(col[a],tmp),y=get_nxt(col[a],tmp);
if(x!=-1)nxt[x]=a,modify(1,1,N,x,a);
nxt[a]=y,modify(1,1,N,a,y);
}
// cerr<<"col:";
// FOR(j,1,N)cerr<<col[j]<<" ";
// cerr<<endl;
// cerr<<"nxt:";
// FOR(j,1,N)cerr<<nxt[j]<<" ";
// cerr<<endl<<endl;
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 13412kb
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 85822 73997 95154 95154 48725 68356 100567 100567 100567 100567 85822 85822 100567 90725 118571 81248 95154 58191 118571 100567 95154 87252 -1 89208 118571 99923 100567 100567 95724 87252 100567 118571 85822 100567 100567 85822 100567 85822 26617 85822 72864 85822 118571 86780 100567 89208 10...
result:
wrong answer 2nd lines differ - expected: '90725', found: '85822'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 416ms
memory: 31456kb
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 1189403 1167757 1206368 1214212 1222519 1184783 1189403 1222519 1160928 1011843 1206368 1206368 1189403 1165447 1214212 1222519 1148...
result:
wrong answer 22nd lines differ - expected: '1222519', found: '1189403'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 358ms
memory: 29568kb
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:
wrong answer 100th lines differ - expected: '35893677', found: '12196610'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%