QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111229#5173. 染色Retrieve_720 0ms0kbC++141.0kb2023-06-06 12:22:032023-06-06 12:22:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-06 12:22:06]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-06-06 12:22:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second 
#define deb(var) cerr << #var << '=' << var << "; "
int n, q, a[1000010], p[1000010], lst[1000010], f[1000010][21]; 
void read(int &x) {
	char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
}
signed main() {
	cin >> n >> q;
	for (int i = 1; i <= 1e6; i++) p[i] = 2;
	for (int i = 3; i <= n + 2; i++) {
		read(a[i]);
		lst[i] = p[a[i]]; p[a[i]] = i;
	}
	for (int i = 3; i <= n + 2; i++) lst[i] = max(lst[i - 1], lst[i]);
	lst[2] = 1;
	for (int i = 2; i <= n + 2; i++) {
		f[i][0] = lst[i];
		for (int j = 1; j < 20; j++) f[i][j] = f[f[i][j - 1]][j - 1];
	} 
	while (q--) {
		int l, r;
		cin >> l >> r; 
		l = 0, r = 0; read(l), read(r); l += 2, r += 2; 
		if (l > r) swap(l, r);
		int ans = 2 * (r - l);
		for (int i = 20; i >= 0; i--)
			if (f[r][i] >= l) r = f[r][i], ans -= 1ll << i;
		printf("%d\n", ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

10000 100
84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...

output:

4575
8382
7013
7320
1140
2249
6254
7507
10481
2675
293
627
6179
2712
7836
511
17835
6147
14577
463
12669
7833
6603
5023
8529
10299
12537
2144
1907
2828
6673
6873
12133
5066
11017
9841
12806
5483
11057
2487
5123
5812
5672
1784
10875
11994
715
2462
11085
13323

result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #7:

score: 0
Time Limit Exceeded

input:

100000 100000
3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...

output:

133099
6483
78290
29192
111588
7226
42776
49274
107722
10708
87161
75805
10951
59513
55105
7850
38727
58326
70130
53673
551
119885
43296
33972
24982
72215
78188
56527
47512
41921
25805
78785
31990
125045
80257
21516
14574
80449
56959
17203
104682
108361
41234
91130
129838
53730
81726
87438
30619
183...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

5000 5000
256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...

output:

2696
2611
4995
1327
5076
4860
925
7270
5325
3225
1577
40
300
3882
5739
1658
1416
5257
119
7615
2047
3683
420
4006
3231
1602
3008
8083
3807
4476
1741
2433
964
4783
3753
1998
5509
3236
3366
441
7121
2901
2399
2494
1198
1382
2479
3402
2132
1393
1071
3389
4555
1377
1725
4826
67
2478
4203
5730
4812
24
67...

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #23:

score: 0
Time Limit Exceeded

input:

1000000 1000000
1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...

output:

308608
79452
576908
1716103
215185
546263
320711
52291
227555
147750
667128
223778
1445226
547639
969316
237554
112491
1188701
717959
559867
412202
266835
1042723
114224
513178
15121
659166
1033704
119191
292879
124818
406346
1455742
1177226
653660
183439
71003
341418
46229
321668
120957
492243
1302...

result: