ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199576 | #3464. Mex问题 | BYR_KKK | 100 | 11318ms | 102784kb | C++ | 1.8kb | 2023-12-17 10:28:58 | 2023-12-17 12:29:44 |
answer
#include<bits/stdc++.h>
#define int long long
#define pii std::pair<int,int>
#define fi first
#define se second
#define us unsigned short
int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') x=x*10+(int)(c-'0'),c=getchar();
return x*f;
}
const int maxn=1e6+10,inf=1e18;
int a[maxn];
struct tree{
int l,r,lz,ls,rs,mi;
}s[maxn*2];
int tot=0;
void push_up(int p){
s[p].mi=std::min(s[s[p].ls].mi,s[s[p].rs].mi);
return ;
}
int build(int l,int r){
int p=++tot;
s[p].l=l,s[p].r=r;
if(l==r){
s[p].mi=a[l];
return p;
}
int mid=(l+r)>>1;
s[p].ls=build(l,mid);
s[p].rs=build(mid+1,r);
push_up(p);
return p;
}
void update(int p,int k,int x){
int l=s[p].l,r=s[p].r;
if(l==r){
s[p].mi-=x;
return ;
}
int mid=(l+r)>>1;
if(k<=mid) update(s[p].ls,k,x);
else update(s[p].rs,k,x);
push_up(p);
return ;
}
int query(int p,int L,int R){
int l=s[p].l,r=s[p].r;
if(l>=L&&r<=R) return s[p].mi;
int mid=(l+r)>>1,ans=inf;
if(mid>=L) ans=std::min(ans,query(s[p].ls,L,R));
if(R>mid) ans=std::min(ans,query(s[p].rs,L,R));
return ans;
}
signed main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n=read(),q=read();
for(int i=1;i<=n;i++) a[i]=read();
build(1,n);
while(q--){
int opt=read();
if(opt==1){
int x=read(),y=read();
update(1,x,a[x]-a[y]);
update(1,y,a[y]-a[x]);
std::swap(a[x],a[y]);
}else {
int l=read(),r=read(),m=inf;
if(l==1){
if(r==n) std::printf("%lld\n",n);
else std::printf("%lld\n",query(1,r+1,n));
}else if(r==n){
std::printf("%lld\n",query(1,1,l-1));
}else std::printf("%lld\n",std::min(query(1,1,l-1),query(1,r+1,n)));
}
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 1328kb
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: 1328kb
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: 1328kb
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: 2032ms
memory: 102780kb
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: 1977ms
memory: 102784kb
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: 2200ms
memory: 102784kb
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: 1245ms
memory: 102780kb
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: 1270ms
memory: 102780kb
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: 1308ms
memory: 102780kb
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: 1285ms
memory: 102784kb
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