QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#818998 | #5173. 染色 | zzafanti | 0 | 314ms | 93348kb | C++23 | 1.3kb | 2024-12-18 11:35:35 | 2024-12-18 11:35:35 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6+5, inf = 0x3f3f3f3f;
int n, q, a[N], ls[N], nx[N];
int ps[N][20];
inline int read () {
int x = 0; char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x*10+(ch^48), ch = getchar();
return x;
}
inline void write (int x) {
if (x > 9) write(x/10);
putchar(x%10+'0');
}
signed main () {
n = read(); q = read();
for (int i = 1;i <= n;i++) a[i] = read();
for (int i = 1;i <= n;i++) ls[i] = n+1;
for (int i = n;i >= 1;i--) {
nx[i] = ls[a[i]]; ls[a[i]] = i;
}
int k = n+1;
ps[0][n+1] = n+1;
for (int i = n;i >= 1;i--) {
k = min(k, nx[i]); ps[i][0] = k;
}
for (int i = 1;i < 20;i++) {
for (int j = 1;j <= n+1;j++) ps[j][i] = ps[ps[j][i-1]][i-1]; //fa[i][j] = {fa[i-1][fa[i-1][j].fi].fi, fa[i-1][j].se+fa[i-1][fa[i-1][j].fi].se};
}
while (q--) {
int l = read(), r = read();
if (l > r) swap(l, r);
int p = l, ans = 0;
for (int i = __lg(r-l+1); ~i; i--) {
if (ps[p][i] <= r) ans += 1<<i, p = ps[p][i];
}
write(2*(r-l)-ans); 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: 0ms
memory: 14056kb
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 729 3221 183 3537 3 1140 253 297 5601 2429 219 3745 201 2747 1791 737 915 49 2159 627 2851 2351 3709 789 1251 4075 2159 21 1627 2215 1789 2319 1113 7017 185 463 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 ...
result:
wrong answer 1st words differ - expected: '3668', found: '1777'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 25ms
memory: 18688kb
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 9199 78290 62365 29192 38941 20945 66619 7226 66019 42776 44640 49274 11102 15677 32029 10708 4735 87161 30929 37627 4213 10951 12237 59513 18641 9605 11626 7850 5521 38727 67276 58326 16941 70130 70341 7645 51864 551 18481 32175 4016 43296 62515 33972 9870 24982 33222 72215 209...
result:
wrong answer 1st words differ - expected: '113194', found: '23093'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 0ms
memory: 10036kb
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 40 415 55 365 1929 1851 1773 629 671 191 427 1659 1283 69 119 43 3699 1139 51 1145 1719 907 177 231 11 179 1261 451 615 3197 1029 2001 81 557 1845 363 483 1327 761 325 451 291 475 741 795 21 1799 399 ...
result:
wrong answer 1st words differ - expected: '1322', found: '331'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 314ms
memory: 93348kb
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'