QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#80650 | #5173. 染色 | infinities | 0 | 245ms | 89948kb | C++14 | 3.5kb | 2023-02-24 15:37:49 | 2023-02-24 15:37:50 |
Judging History
answer
#include<bits/stdc++.h>
//#include <ext/pb_ds/hash_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
namespace infinities{
#define fint register int
#define ls(i) (i << 1)
#define rs(i) ((i << 1) | 1)
#define pii pair<int, int>
#define im int mid = (l + r) >> 1
#define INT __int128
#define ll long long
#define ui unsigned int
#define lc ch[now][0]
#define rc ch[now][1]
const int mod = 998244353, INF = 998244353, maxn = (1 << 20) - 1;
namespace FastIO{//10M
const int SS = 1e7; char num_[50]; int cnt_;
inline int xchar(){static char buf[SS]; static int len = 0, pos = 0; if(pos == len)pos = 0, len = fread(buf, 1, SS, stdin); if(pos == len)exit(0); return buf[pos++];}
inline int read(){fint x = 0, f = 1, ch = xchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = xchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = xchar();} return x * f;}
inline void write(int x){if(x == 0){putchar('0'); return;}if(x < 0)putchar('-'), x = -x; while(x)num_[++cnt_] = x % 10 ^ 48,x /= 10; while(cnt_)putchar(num_[cnt_--]);}
inline void write(int x, char c){write(x), putchar(c);}
}
char buf[1 << 26], *pp1 = buf, *pp2 = buf, obuf[1 << 26], *O = obuf;
void print(int x){
if(x > 9)print(x / 10);
*O++ = x % 10 + '0';
}
using namespace std;
using namespace FastIO;
namespace mystd{
inline int qmin(int a, int b){return (a > b) ? b : a;} inline int qmax(int a, int b){return (a > b) ? a : b;}
inline void chkmin(int &a, int b){a = min(a, b); return;} inline void chkmax(int &a, int b){a = max(a, b); return;}
inline void qk(int &a, int b){a = a + b; a = (a >= mod) ? a - mod : a;}
inline void sub(int &a, int b){a = a - b + mod; a = (a >= mod) ? a - mod : a;}
inline int mul(int a, int b){return (1ll * a * b % mod + mod) % mod;}
inline int qpow(int x, int k){fint res = 1; for(; k; k = (k >> 1), x = 1ll * x * x % mod)if(k & 1)res = 1ll * res * x % mod; return res;}
inline void looked(int a[], int n){for(fint i = 1; i < n; i++)write(a[i], ' '); write(a[n], '\n');} inline void debug(){puts("qwq");} inline void YES(){puts("YES");} inline void Yes(){puts("Yes");} inline void yes(){puts("yes");} inline void NO(){puts("NO");} inline void No(){puts("No");} inline void no(){puts("no");}
}
using namespace mystd;
//using namespace __gnu_pbds;
//gp_hash_table<int, int>hsh;
void file(){freopen("a.in", "r", stdin), freopen("a.out", "w", stdout);}
int n, q, a[maxn], las[maxn], p[maxn], jump[21][maxn];
signed main(){
n = read(), q = read();
p[0] = n + 1;
for(fint i = 1; i <= n; i++)a[i] = read(), p[i] = n + 1;
for(fint i = 1; i <= n; i++){
if(las[a[i]] > 0)chkmin(p[las[a[i]]], i);
las[a[i]] = i;
}
fint len = 0;
for(fint i = n - 1; i >= 0; i--)chkmin(p[i], p[i + 1]);
p[n + 1] = n + 1;
fint now = 1; while(now <= n)now = p[now], ++len;
fint lm = 0;
while(len){len >>= 1, ++lm;}
for(fint i = 0; i <= n + 1; i++)jump[0][i] = p[i];
for(fint i = 1; i < lm; i++)for(fint j = 0; j <= n + 1; j++)jump[i][j] = jump[i - 1][jump[i - 1][j]];
while(q--){
fint u = read(), v = read();
if(u > v)swap(u, v);
fint ans = (v - u) * 2;
for(fint i = lm; i >= 0; i--)if(jump[i][u] <= v)u = jump[i][u], ans -= (1 << i);
print(ans); *O++ = '\n';
}
fwrite(obuf, O - obuf, 1, stdout);
return 0;
}
}
signed main(){
return infinities::main();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 28128kb
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:
2362 3406 4809 7295 , 5796 ( 6237 * + ' 705 12143 5121 ' 6077 1085 9334 615 1548 3266 / 4542 - 5351 4862 10383 1282 1507 6518 16705 . 4016 16777 8356 4823 3719 13457 + ( 14529 11645 7737 6716 9929 5344 5222 3828 7969 7229 935 9030 1607 11325 3485 921 7752 272 5103 1370 - 5521 3984 5422 2677 10879 85...
result:
wrong answer 1st words differ - expected: '3668', found: '2362'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 22ms
memory: 81228kb
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:
44371 64849 / + . 0 15669 ' / 42864 - * 321 - ' ) 0 38832 ' 0 ' 9250 ' 0 - * + + - . * . ' , ( * / ) + - / ' , 51963 , ( / ) - ( + / / * . + * ) 55727 , 0 * ( 2149 / ) ) 53478 . 13624 / / / / * ' 37133 / ( + * 29859 / 42708 + - + 8554 + 60233 * - + 901 - 3429 ) - - . - . 27234 ) . . * . . + / / , , ...
result:
wrong answer 1st words differ - expected: '113194', found: '44371'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 5ms
memory: 23908kb
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:
873 2331 1412 2300 4427 4677 2556 946 452 4799 7515 4557 600 631 475 6972 7400 4988 3481 2821 4180 1250 2261 . 514 ' 3981 3533 3520 5462 4254 1311 68 1040 3332 4963 174 0 1695 7354 8847 1668 2823 3390 2514 19 359 3647 ( 2898 1138 1302 6859 2677 5656 7815 1157 3514 89 4183 3021 1305 499 2030 3932 644...
result:
wrong answer 1st words differ - expected: '1322', found: '873'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 245ms
memory: 89948kb
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:
1243523 284092 743465 57055 141391 558291 966715 1698914 1327148 191590 593378 527878 1366252 299797 1073778 25721 257734 210933 * 127857 126333 649875 4790 199418 159024 1427262 1648877 526590 120773 949436 1089336 217887 796660 93527 65534 1167922 299294 694971 151905 540904 747952 388233 56112 24...
result:
wrong answer 1st words differ - expected: '1263815', found: '1243523'