UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200303#3470. 寻找好点Planting1004272ms13312kbC++1.5kb2023-12-31 10:21:592023-12-31 12:25:44

answer

# include <bits/stdc++.h>

using namespace std;

int n, q;

int a[1000005], t[4000005], tg[4000005];

inline void build (int u, int l, int r) {
	
	if (l == r) {
		
		t[u] = a[l];
		
		return ;
		
	}
	
	int mid = (l + r) >> 1;
	
	build (u << 1, l, mid), build (u << 1 | 1, mid + 1, r);
	
	t[u] = max (t[u << 1], t[u << 1 | 1]);
	
}

inline int get (int u, int l, int r, int x) {
	
	if (l == r) return l;
	
	int mid = (l + r) >> 1;
	
	return t[u << 1] > x ? get (u << 1, l, mid, x) : get (u << 1 | 1, mid + 1, r, x);
	
}

inline int query (int u, int l, int r, int L, int R, int x) {
	
	if (r < L || l > R) return -1;
	
	if (L <= l && r <= R) return t[u] > x ? get (u, l, r, x) : -1;
	
	int mid = (l + r) >> 1, res = query (u << 1, l, mid, L, R, x);
	
	return res != -1 ? res : query (u << 1 | 1, mid + 1, r, L, R, x);
	
}

inline void change (int u, int l, int r, int k, int x) {
	
	if (l == r) {
		
		t[u] = x;
		
		return ;
		
	}
	
	int mid = (l + r) >> 1;
	
	if (k <= mid) change (u << 1, l, mid, k, x);
	
	else change (u << 1 | 1, mid + 1, r, k, x);
	
	t[u] = max (t[u << 1], t[u << 1 | 1]);
	
}

signed main () {
	
	scanf ("%d", &n);
	
	for (int i = 1; i <= n; ++ i) scanf ("%d", &a[i]);
	
	build (1, 1, n);
	
	scanf ("%d", &q);
	
	for (int i = 1; i <= q; ++ i) {
		
		int l, r, v;
		
		scanf ("%d %d %d", &l, &r, &v);
		
		int nw = query (1, 1, n, l, r, v);
		
		printf ("%d\n", nw);
		
		if (nw != -1) a[nw] = v, change (1, 1, n, nw, v);
		
	}
	
	return 0;
	
}

Details

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

Test #1:

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

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: 0ms
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: 4ms
memory: 1296kb

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

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: 4ms
memory: 1296kb

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: 4ms
memory: 1296kb

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: 1162ms
memory: 13308kb

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: 1293ms
memory: 13312kb

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: 1046ms
memory: 13308kb

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: 756ms
memory: 13308kb

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