UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199559#3464. Mex问题jane1006529ms13292kbC++111.1kb2023-12-17 10:17:122023-12-17 12:24:40

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
#define ls(p) p<<1
#define rs(p) (p<<1)+1
int n,q,a[N];
int t[N<<2];
void build(int l,int r,int p){
	if(l==r){
		t[p]=a[l];
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,ls(p));
	build(mid+1,r,rs(p));
	t[p]=min(t[ls(p)],t[rs(p)]);
}
void mo(int l,int r,int p,int x,int num){
	if(l==r){
		t[p]=num;
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid)
		mo(l,mid,ls(p),x,num);
	else
		mo(mid+1,r,rs(p),x,num);
	t[p]=min(t[ls(p)],t[rs(p)]);
}
int gn(int l,int r,int p,int x,int y){
	if(x>y)
		return n;
	if(x<=l&&r<=y)
		return t[p];
	int mid=(l+r)>>1,res=n+1;
	if(x<=mid)
		res=min(res,gn(l,mid,ls(p),x,y));
	if(y>mid)
		res=min(res,gn(mid+1,r,rs(p),x,y));
	return res;
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	build(1,n,1);
	while(q--){
		int op,x,y;
		scanf("%d%d%d",&op,&x,&y);
		if(op==1){
			swap(a[x],a[y]);
			mo(1,n,1,x,a[x]);
			mo(1,n,1,y,a[y]);
		}
		else
			printf("%d\n",min(gn(1,n,1,1,x-1),gn(1,n,1,y+1,n)));
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1212kb

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: 2ms
memory: 1208kb

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: 1208kb

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: 967ms
memory: 13288kb

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: 1361ms
memory: 13288kb

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: 953ms
memory: 13288kb

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: 731ms
memory: 13288kb

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: 737ms
memory: 13292kb

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: 760ms
memory: 13288kb

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: 1018ms
memory: 13292kb

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