ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199601 | #3464. Mex问题 | baiencheng | 100 | 6567ms | 20788kb | C++ | 1.7kb | 2023-12-17 10:42:36 | 2023-12-17 12:33:09 |
answer
#include<bits/stdc++.h>
//#define int long long
#define endl "\n"
#define ull unsigned long long
#define ts cout<<1<<"\n";
using namespace std;
int n,q;
int a[1000005];
int mi[1000000*4+5];
void build(int k,int x,int y){
if(x==y){
mi[k]=a[x];
return ;
} else {
int mid=(x+y)>>1;
build(k*2,x,mid);
build(k*2+1,mid+1,y);
mi[k]=min(mi[k*2],mi[k*2+1]);
return ;
}
}
void modify(int k,int x,int y,int qx,int qy,int z){
if(x==qx&&qy==y){
a[x]+=z;
mi[k]=a[x];
} else {
int mid=(x+y)>>1;
if(qy<=mid) modify(k*2,x,mid,qx,qy,z);
if(qx>mid) modify(k*2+1,mid+1,y,qx,qy,z);
// else modify(k*2,x,mid,qx,mid,z),modify(k*2+1,mid+1,y,mid+1,qy,z);
mi[k]=min(mi[k*2],mi[k*2+1]);
}
}
int query(int k,int x,int y,int qx,int qy){
if(x>=qx&&y<=qy){
return mi[k];
} else {
int ans=n;
int mid=(x+y)>>1;
if(qx<=mid) ans=min(ans,query(k*2,x,mid,qx,qy));
if(qy>mid) ans=min(ans,query(k*2+1,mid+1,y,qx,qy));
return ans;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(mi,0x3f,sizeof(mi));
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
while(q--){
int pd,x,y;
cin>>pd>>x>>y;
if(pd==1){
int cntx=a[x],cnty=a[y];
modify(1,1,n,x,x,cnty-cntx);
modify(1,1,n,y,y,cntx-cnty);
} else {
int ans=n;
if(x>1) ans=min(ans,query(1,1,n,1,x-1));
if(y<n) ans=min(ans,query(1,1,n,y+1,n));
cout<<ans<<"\n";
}
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 5ms
memory: 16888kb
input:
1000 1000 766 551 229 619 16 792 855 602 918 959 379 858 777 503 252 449 473 238 359 703 930 874 444...
output:
211 382 766 211 1000 551 16 47 766 551 1000 551 382 766 229 211 551 551 1000 551 766 766 211 1000 55...
result:
ok 473 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 16888kb
input:
1000 1000 979 835 871 109 874 446 706 581 33 808 267 662 295 702 793 375 127 938 338 340 352 431 539...
output:
835 835 109 482 482 547 547 9 517 835 517 109 547 547 517 835 547 517 4 547 547 547 4 547 4 547 547 ...
result:
ok 500 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 16884kb
input:
1000 1000 152 958 925 477 38 77 289 947 154 490 267 914 814 993 374 858 450 692 792 899 316 115 341 ...
output:
502 1000 152 1000 502 1000 1000 38 152 1000 502 672 1000 1000 502 502 1000 1000 1000 672 672 672 100...
result:
ok 516 lines
Test #4:
score: 10
Accepted
time: 1024ms
memory: 20788kb
input:
1000000 1000000 416632 951954 346607 668902 615191 265616 312582 30395 835755 866377 515388 538995 6...
output:
0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 ...
result:
ok 499975 lines
Test #5:
score: 10
Accepted
time: 1337ms
memory: 20784kb
input:
1000000 1000000 108748 877565 196157 720468 129802 600075 317321 799786 665963 638373 510469 901108 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 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 1 0 0 0 0 0 1 1 6 ...
result:
ok 499969 lines
Test #6:
score: 10
Accepted
time: 1037ms
memory: 20784kb
input:
1000000 1000000 812407 150933 396889 408364 72596 793626 731766 831633 169527 521479 50208 950746 47...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 7 0 1 0 2 0 7 0 0 3 ...
result:
ok 499952 lines
Test #7:
score: 10
Accepted
time: 789ms
memory: 20788kb
input:
999998 1000000 496742 1903 386521 847417 168428 380343 791167 240576 271414 613096 192711 723079 497...
output:
496742 496742 846822 846822 496742 846822 496742 846822 496742 846822 496742 846822 496742 999998 99...
result:
ok 499556 lines
Test #8:
score: 10
Accepted
time: 793ms
memory: 20788kb
input:
1000000 1000000 137393 664239 178477 745998 955585 221661 631802 12887 408835 943141 907351 214221 3...
output:
1000000 1000000 137393 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...
result:
ok 500201 lines
Test #9:
score: 10
Accepted
time: 794ms
memory: 20788kb
input:
999998 1000000 487858 189435 425747 744974 571986 20129 489577 661897 906159 864589 145564 153617 27...
output:
999998 189435 999998 487858 999998 189435 487858 999998 999998 189435 189435 999998 999998 999998 99...
result:
ok 499608 lines
Test #10:
score: 10
Accepted
time: 788ms
memory: 20788kb
input:
999999 1000000 178622 257725 504698 723327 640246 10648 929245 508226 572943 464286 88720 809444 889...
output:
999999 759507 178622 178622 178622 759507 759507 178622 999999 759507 759507 759507 759507 759507 75...
result:
ok 499620 lines
Extra Test:
score: 0
Extra Test Passed