UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200247#3470. 寻找好点Williamtank1004217ms28540kbC++1.5kb2023-12-31 09:35:372023-12-31 12:14:38

answer

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

详细

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

Test #1:

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

input:

300
246 733 1322 2465 2613 3452 4124 4346 4368 4871 5995 6637 7297 7634 7507 8383 8979 9620 10757 11...

output:

148
178
225
190
138
179
69
147
83
200
99
192
19
79
200
100
120
148
-1
282
57
134
141
142
198
151
190...

result:

ok 300 lines

Test #2:

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

input:

300
493 1451 2459 2622 3230 3690 3979 4574 5081 5631 6458 6215 7727 6712 7752 7904 10559 10395 9721 ...

output:

147
233
156
89
194
233
11
245
222
120
188
71
109
169
137
82
122
134
105
160
155
50
187
240
-1
94
134...

result:

ok 300 lines

Test #3:

score: 10
Accepted
time: 3ms
memory: 1340kb

input:

5000
9 20 45 52 49 57 58 87 110 114 104 119 130 126 176 144 198 211 229 234 199 251 215 260 240 293 ...

output:

-1
4025
-1
2859
799
3670
2568
1368
2950
1598
2548
956
3217
3063
-1
-1
2744
3604
1392
515
1040
-1
210...

result:

ok 5000 lines

Test #4:

score: 10
Accepted
time: 3ms
memory: 1344kb

input:

5000
9 11 22 36 56 62 67 80 96 98 117 118 134 139 144 158 174 182 190 203 227 232 247 244 259 268 29...

output:

-1
-1
1724
-1
2593
-1
939
-1
-1
-1
1503
-1
2163
2578
1527
2112
-1
2115
3271
3945
-1
3149
3651
1324
3...

result:

ok 5000 lines

Test #5:

score: 10
Accepted
time: 3ms
memory: 1344kb

input:

5000
10 12 39 37 58 58 82 116 119 95 138 117 144 183 174 217 197 205 209 243 211 271 286 257 236 298...

output:

-1
-1
1574
1937
1691
-1
4216
-1
1708
955
-1
3433
-1
2531
3493
1962
2115
3046
-1
799
-1
-1
3216
2821
...

result:

ok 5000 lines

Test #6:

score: 10
Accepted
time: 3ms
memory: 1340kb

input:

5000
17 24 41 50 66 71 80 86 102 106 123 133 150 157 167 180 182 191 204 218 228 243 251 268 279 293...

output:

2066
-1
2658
2886
916
958
-1
4190
-1
-1
2858
-1
3611
2990
1167
4519
1151
-1
3881
4966
943
3101
-1
-1...

result:

ok 5000 lines

Test #7:

score: 10
Accepted
time: 1616ms
memory: 28540kb

input:

1000000
5 7 9 15 24 28 36 38 45 48 51 56 54 61 70 71 78 79 85 91 98 107 112 117 126 132 133 142 154 ...

output:

523080
585083
682099
488339
477822
330809
337824
574145
627108
434148
372632
532279
774997
474340
51...

result:

ok 1000000 lines

Test #8:

score: 10
Accepted
time: 1259ms
memory: 28540kb

input:

1000000
4 7 12 23 28 36 47 48 65 70 73 82 86 87 97 101 111 118 122 120 124 126 137 149 151 148 158 1...

output:

436413
406778
507867
967432
462532
574431
725838
409960
532986
556972
615602
229720
269321
154974
26...

result:

ok 1000000 lines

Test #9:

score: 10
Accepted
time: 652ms
memory: 28540kb

input:

1000000
8 8 17 27 28 36 53 51 60 69 72 76 83 81 91 87 97 103 115 118 118 132 140 143 152 154 160 156...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
3...

result:

ok 1000000 lines

Test #10:

score: 10
Accepted
time: 677ms
memory: 28540kb

input:

1000000
8 9 16 19 23 34 38 39 47 54 58 64 71 83 85 94 98 109 109 112 118 120 132 144 146 145 139 153...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
3...

result:

ok 1000000 lines

Extra Test:

score: 0
Extra Test Passed