UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199532#3464. Mex问题Williamtank1007927ms28544kbC++1.7kb2023-12-17 09:57:092023-12-17 12:15:18

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,q;
const int N = 1e6;
struct Segment_tree
{
	int a[N + 5];
	int cnt;
	struct node
	{
		int mn;
		int lson,rson;
	}tree[2 * N + 5];
	void push_up(int k1)
	{
		tree[k1].mn = min(tree[tree[k1].lson].mn,tree[tree[k1].rson].mn);
	}
	void build_tree(int &k1,int l,int r)
	{
		k1 = ++cnt;
		if(l == r)
		{
			tree[k1].mn = a[l];
			return;
		}
		int mid = (l + r) / 2;
		build_tree(tree[k1].lson,l,mid);
		build_tree(tree[k1].rson,mid + 1,r);
		push_up(k1);
	}
	void update(int k1,int l,int r,int x,int k)
	{
		if(l == r)
		{
			tree[k1].mn = k;
			return;
		}
		int mid = (l + r) >> 1;
		if(x <= mid) update(tree[k1].lson,l,mid,x,k);
		else update(tree[k1].rson,mid + 1,r,x,k);
		push_up(k1); 
	}
	int query(int k1,int l,int r,int x,int y)
	{
		if(x <= l && r <= y) return tree[k1].mn;
		int mid = (l + r) >> 1;
		int ans = 1 << 30;
		if(x <= mid) ans = min(ans,query(tree[k1].lson,l,mid,x,y));
		if(y > mid) ans = min(ans,query(tree[k1].rson,mid + 1,r,x,y));
		return ans;
	}
}t;
signed main()
{
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;i++) scanf("%d",&t.a[i]);
	t.build_tree(t.tree[0].lson,1,n); 
	for(int i = 1;i <= m;i++)
	{
		int opt;
		scanf("%d",&opt);
		if(opt == 1)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			t.update(1,1,n,x,t.a[y]);
			t.update(1,1,n,y,t.a[x]);
			swap(t.a[x],t.a[y]);
		}
		else
		{
			int x,y;
			scanf("%d%d",&x,&y);
			int ans = 1 << 30;
			if(x > 1) ans = min(ans,t.query(1,1,n,1,x - 1));
			if(y < n) ans = min(ans,t.query(1,1,n,y + 1,n));
			if(ans == (1 << 30)) printf("%d\n",n);
			else printf("%d\n",ans); 
		}
	}
	return 0;
} 

详细

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

Test #1:

score: 10
Accepted
time: 1ms
memory: 1236kb

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

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

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: 1313ms
memory: 28540kb

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: 1341ms
memory: 28540kb

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: 1393ms
memory: 28540kb

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: 936ms
memory: 28540kb

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: 983ms
memory: 28544kb

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: 982ms
memory: 28544kb

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: 978ms
memory: 28540kb

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