QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137620 | #5173. 染色 | rsg23 | 0 | 212ms | 20948kb | C++17 | 1.5kb | 2023-08-10 14:47:05 | 2023-08-10 14:47:07 |
Judging History
answer
// 评测机完蛋了
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int NR = 1e6 + 5;
int n, q, a[NR], b[NR], c[NR], lst[NR], f[NR][21];
vector < int > v;
char *p1, *p2, buf[100000];
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
inline int read() {
int x = 0; char c = gc();
while (c < 48 || c > 57) c = gc();
while (c >= 48 && c <= 57) x = (x << 1) + (x << 3) + c - 48, c = gc();
return x;
}
signed main() {
n = read(), q = read(); c[n + 1] = n + 1, b[n + 1] = n + 1;
for (int i = 1; i <= n; ++i) a[i] = read(), lst[a[i]] = -1, c[i] = n + 1;
for (int i = n; i >= 1; --i) b[i] = lst[a[i]], lst[a[i]] = i;
for (int i = n, p = n + 1; i >= 1; --i) {
if (b[i] == -1) continue;
if (b[i] >= p) continue;
v.push_back(i), p = b[i];
}
reverse(v.begin(), v.end());
for (int i = 0; i < v.size(); ++i) c[v[i]] = v[i];
for (int i = n; i >= 1; --i)
if (c[i] == n + 1) c[i] = c[i + 1];
for (int i = 0; i <= 20; ++i)
for (int j = 1; j <= n + 1; ++j) f[j][i] = n + 1;
for (int i = 0; i < v.size() - 1; ++i) f[v[i]][0] = c[b[v[i]]];
for (int i = 1; i <= 20; ++i)
for (int j = 1; j <= n; ++j) f[j][i] = f[f[j][i - 1]][i - 1];
while (q --) {
int l, r; cin >> l >> r;
if (l > r) swap(l, r);
int ans = 2 * r - 2 * l;
int x = c[l];
if (b[x] <= r) ans --;
for (int i = 20; i >= 0; --i)
if (b[f[x][i]] <= r) ans -= (1 << i), x = f[x][i];
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 12728kb
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:
-1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -1951744 -19...
result:
wrong answer 1st words differ - expected: '3668', found: '-1951744'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 212ms
memory: 20948kb
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:
84842 15178 46294 59256 34133 74414 43850 62833 2392 81264 41696 127332 7276 88421 70458 119137 36759 28229 99524 93357 17370 4483 16080 93077 26370 23626 51591 31451 129120 50386 16551 3528 30441 63801 25481 64965 70056 74809 102555 14290 41774 34349 136056 111394 40005 31616 45332 4700 15819 3110 ...
result:
wrong answer 1st words differ - expected: '113194', found: '84842'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 3ms
memory: 12236kb
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:
-2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -2097146 -20...
result:
wrong answer 1st words differ - expected: '1322', found: '-2097146'
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:
1412792 834520 1234379 462803 799125 998963 1169038 911793 972139 655067 771060 111642 102780 927437 243278 301228 532914 1188354 1123276 487175 412077 1012277 319650 496869 11144 1042156 350892 2074 277484 1004805 1117342 831631 1578997 1224247 400535 1469956 528504 560767 1703118 262291 522311 382...