QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#867258 | #5173. 染色 | AMlhdSan | 0 | 336ms | 117344kb | C++14 | 1.7kb | 2025-01-23 12:25:23 | 2025-01-23 12:25:23 |
Judging History
answer
#include <bits/stdc++.h>
#define N 1000010
using namespace std;
int n, q;
int a[N];
int lst[N];
int fa[N];
vector<int> son[N];
int depth[N];
int ans[N];
struct node {
int l;
int index;
};
vector<node> qry[N];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
inline void write(int x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main() {
n = read();
q = read();
for(int i = 1; i <= n; ++i) {
a[i] = read();
}
for(int i = 1; i <= q; ++i) {
int l, r;
l = read();
r = read();
if(l > r)
swap(l, r);
qry[r].push_back({l, i});
}
int nxt;
for(int i = n; i >= 1; --i) {
nxt = n + 1;
if(lst[a[i]]) {
nxt = min(nxt, lst[a[i]]);
}
if(nxt <= n) {
son[nxt].push_back(i);
depth[i] = depth[nxt] + 1;
}
lst[a[i]] = i;
fa[i] = i;
}
for(int i = 1; i <= n; ++i) {
for(int j : son[i]) {
fa[find(j)] = i;
}
for(node tmp : qry[i]) {
ans[tmp.index] = depth[find(tmp.l)] - depth[tmp.l] + 2 * (i - tmp.l);
}
}
for(int i = 1; i <= q; ++i) {
write(ans[i]);
putchar('\n');
}
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: 6ms
memory: 60080kb
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:
3805 4755 6204 8694 756 7281 191 7591 514 1186 263 2335 13721 6498 473 7792 2237 10897 1861 2775 4985 302 6224 654 6912 6417 11836 2827 3285 8115 18445 531 5686 18495 9924 6386 5183 15116 695 481 16206 13147 9213 8119 11391 6857 6635 5208 9463 8854 2268 10673 2791 13021 5142 2231 9126 1973 6724 2946...
result:
wrong answer 1st words differ - expected: '3668', found: '3805'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 27ms
memory: 61828kb
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:
128621 150559 62382 7375 10446 88967 106364 32879 44215 126808 75352 8164 74820 48640 50850 55991 12614 122048 81344 12039 5351 98845 53005 85817 30654 12434 13810 67601 21040 62713 13237 8880 6283 43764 76565 66346 19304 79645 79512 61042 58857 636 21028 136171 4571 49224 71110 38687 11243 28370 37...
result:
wrong answer 1st words differ - expected: '113194', found: '128621'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 4ms
memory: 54508kb
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:
1351 2760 1779 2666 4863 5108 3019 1359 901 5179 7988 4963 953 942 823 7436 7836 5451 3893 3306 4578 1609 2591 40 924 309 4457 3971 3889 5858 4718 1693 446 1448 3702 5366 580 121 2085 7781 9316 2096 3190 3757 2948 432 740 4098 184 3298 1473 1636 7272 3069 6082 8262 1578 3881 370 4564 3371 1779 835 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1351'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 336ms
memory: 117344kb
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:
1270822 310323 764292 79891 161241 580065 993695 1725603 1352496 216381 619378 549268 1393588 322496 1100359 52577 277659 228822 2491 148568 145588 670796 25562 225016 185373 1453184 1675496 550692 147232 974690 1112571 238859 821809 113120 85282 1195280 318427 721951 170461 562935 772037 414507 736...
result:
wrong answer 1st words differ - expected: '1263815', found: '1270822'