QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359735 | #5173. 染色 | zyc070419 | 0 | 447ms | 187260kb | C++14 | 1.3kb | 2024-03-20 20:23:12 | 2024-03-20 20:23:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
inline int read() {
char ch = getchar(); int x = 0;
while (!isdigit(ch)) {ch = getchar();}
while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();}
return x;
}
void write(int x) {
if (!x) return;
write(x / 10); putchar(x % 10 + '0');
}
inline void print(int x, char ch = '\n') {
if (!x) putchar('0');
else write(x);
putchar(ch);
}
int n, T, a[N], lst[N], nxt[N], fa[N][22], va[N][22], top;
int main() {
n = read(); T = read(); nxt[n + 1] = n + 1;
for (int i = 1; i <= n; ++i) a[i] = read();
for (int i = 1; i <= n; ++i) lst[i] = n + 1;
for (int i = n; i >= 1; --i) {
nxt[i] = lst[a[i]];
lst[a[i]] = i;
}
for (int i = n, x = n + 1; i >= 1; --i) {
if (nxt[i] < x) fa[i][0] = nxt[i], va[i][0] = 1;
else fa[i][0] = x, va[i][0] = 0;
if (nxt[i] < nxt[x]) x = i;
}
for (int j = 1; j < 20; ++j)
for (int i = 1; i <= n + 1; ++i)
fa[i][j] = fa[fa[i][j - 1]][j - 1], va[i][j] = va[i][j - 1] + va[fa[i][j - 1]][j - 1];
while (T--) {
int l = read(), r = read(), ans;
if (l > r) swap(l, r);
ans = ((r - l) << 1);
int x = l;
for (int i = 19; i >= 0; --i) {
if (fa[x][i] > r) continue;
ans -= va[x][i];
x = fa[x][i];
}
print(ans);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 16404kb
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:
3467 4326 5783 8244 494 6898 69 7134 376 817 /)* 2146 13294 6059 440 7567 1746 10477 1424 2314 4803 289 5998 246 6587 6096 11366 2563 3167 7821 18040 497 5476 18085 9555 6070 4828 14736 529 17 15788 12678 8792 7693 10943 6501 6231 4808 9031 8532 1868 10355 2310 12660 4926 1825 8666 1847 6442 2703 94...
result:
wrong answer 1st words differ - expected: '3668', found: '3467'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 28ms
memory: 34624kb
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:
140380 167191 66506 7888 1687 96922 116727 26495 46865 138198 77703 1172 75144 47858 52436 56258 5751 132978 89467 13158 1509 107473 58472 95541 34206 5785 13752 70974 21209 67037 9727 740 *),( 40470 77969 65431 16087 85363 82575 64167 57246 -+00 16172 149198 ((,/ 46944 71222 35234 7051 25771 38437 ...
result:
wrong answer 1st words differ - expected: '113194', found: '140380'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 0ms
memory: 12292kb
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:
1325 2669 1669 2541 4761 4991 2958 1279 856 5037 7859 4836 847 803 713 7305 7682 5349 3789 3246 4439 1495 2445 .* 850 265 4370 3875 3757 5717 4627 1592 356 1365 3565 5237 507 47 1989 7630 9170 2016 3051 3625 2864 366 651 4009 75 3195 1338 1499 7135 2963 5955 8115 1499 3751 217 4437 3223 1744 712 243...
result:
wrong answer 1st words differ - expected: '1322', found: '1325'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 447ms
memory: 187260kb
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:
1265289 307996 755932 75896 154588 573181 989087 1717717 1345198 213323 615578 542191 1387569 317348 1094971 51805 270592 220397 1797 142616 138546 662865 20171 222554 183621 1445879 1667827 545666 145743 968788 1104649 232742 816506 106471 78859 1190121 310568 718471 162761 556332 766102 411765 655...
result:
wrong answer 1st words differ - expected: '1263815', found: '1265289'