QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#159857 | #5173. 染色 | skip2004 | 0 | 453ms | 89744kb | C++23 | 974b | 2023-09-02 18:56:36 | 2023-09-02 18:56:38 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 1000005;
int n, q;
int a[N];
int ri[N];
int jump[N][20];
int pre[N];
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
#ifdef zqj
freopen("$.in", "r", stdin);
#endif
cin >> n >> q;
for(int i = 1;i <= n + 1;++i) {
ri[i] = n + 1;
}
for(int i = 1;i <= n;++i) {
cin >> a[i];
int p = pre[a[i]];
ri[p] = std::min(ri[p], i);
pre[a[i]] = i;
}
for(int i = n - 1;i >= 1;--i) {
ri[i] = std::min(ri[i], ri[i + 1]);
}
for(int i = 1;i <= n + 1;++i) jump[0][i] = ri[i];
for(int i = 1;i < 20;++i) {
for(int j = 1;j <= n + 1;++j) {
jump[j][i] = jump[jump[j][i - 1]][i - 1];
}
}
for(int i = 1, l, r;i <= q;++i) {
cin >> l >> r;
if(l > r) std::swap(l, r);
int ans = (r - l) * 2;
for(int i = std::__lg(r - l + 1);i >= 0;--i) {
if(jump[l][i] <= r) {
ans -= 1 << i;
l = jump[l][i];
}
}
cout << ans << '\n';
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 9916kb
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:
1777 681 2139 549 249 3221 65 3537 3 167 9 297 5601 2429 219 3745 201 2747 845 737 915 49 2159 145 2851 2351 3709 789 1251 4075 2159 21 1627 2215 1789 2319 1113 7017 185 229 8095 5025 1065 4071 3265 2797 2579 1145 1305 703 227 2549 759 4891 1075 193 989 963 2655 909 485 2863 1733 3079 395 4473 2169 ...
result:
wrong answer 1st words differ - expected: '3668', found: '1777'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 27ms
memory: 16632kb
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:
23093 50077 9379 621 4327 41137 62365 6923 20281 20945 25187 1665 24273 25535 28145 1621 6915 15677 32029 6325 2349 53211 30929 37627 4213 6725 179 15623 8945 9605 7679 2511 3395 19907 26091 13839 6693 30095 30265 7645 5053 243 8819 32175 1361 26189 19577 13519 5257 1321 12517 32941 12029 40935 2350...
result:
wrong answer 1st words differ - expected: '113194', found: '23093'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 3ms
memory: 9756kb
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:
331 715 759 625 779 1021 981 337 391 1093 3905 877 447 433 315 3351 3749 1363 1855 1263 485 589 549 9 415 55 365 1929 1851 1773 629 671 191 427 1659 1283 69 59 43 3699 1139 51 1145 1719 907 177 231 11 57 1261 451 615 3197 1029 2001 81 557 1845 115 483 1327 761 325 451 291 475 741 795 21 1799 153 102...
result:
wrong answer 1st words differ - expected: '1322', found: '331'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 453ms
memory: 89744kb
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:
222369 48209 240087 14371 30181 55835 469503 677181 304071 85333 95155 25023 345137 60373 51895 19813 15537 97789 445 17513 14525 146575 9185 93965 54315 404755 627115 26443 16173 450479 64135 107807 297611 47597 19755 146821 56315 197729 39411 38707 247829 152403 8105 6215 23587 7 79493 49329 76859...
result:
wrong answer 1st words differ - expected: '1263815', found: '222369'