QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740610 | #5173. 染色 | jinqihao2023 | 0 | 424ms | 97532kb | C++14 | 1.4kb | 2024-11-13 10:43:25 | 2024-11-13 10:43:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,q,a[N],to[N][21],lst[N];
namespace IO {
const int SIZE=(1<<21)+1;
char ibuf[SIZE],*iS,*iT,obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1,c,qu[55];int f, qr;
#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
inline void putc(char x){*oS++=x;if(oS==oT)flush();}
template <class I>
inline void read(I &x){
for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
}
template <class I>
inline void print(I x){
if(!x)putc('0');if(x<0)putc('-'),x=-x;
while(x)qu[++qr]=x%10+'0',x/=10;
while(qr)putc(qu[qr --]);
}
struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using IO::read;
using IO::putc;
using IO::print;
int main()
{
read(n),read(q);
for(int i=1;i<=n;i++)read(a[i]);
for(int i=1;i<=n;i++)lst[i]=n+1;
to[n+1][0]=n+1;
for(int i=n;i>=1;i--)to[i][0]=min(to[i+1][0],lst[a[i]]),lst[a[i]]=i;
for(int i=1;i<=19;i++)for(int j=1;j<=n+1;j++)to[j][i]=to[to[j][i-1]][i-1];
while(q--)
{
int x,y;
read(x),read(y);
if(x>y)swap(x,y);
int num=0;
for(int i=19;i>=0;i--)if(to[x][i]<=y)x=to[x][i],num|=(1<<i);
num=(y-x)*2-num;
print(num),putc('\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: 2ms
memory: 9700kb
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:
-154 -157 -256 -342 -17 -291 -9 -308 -22 -34 -9 -93 -554 -270 8 -331 -86 -443 -69 -97 -195 9 -245 -9 -270 -251 -464 -102 -137 -332 -750 -21 -214 -747 -376 -263 -202 -623 -2 -13 -661 -507 -352 -299 -449 -279 -259 -201 -354 -341 -81 -423 -90 -539 -204 -76 -337 -49 -274 -128 -13 -277 -226 -301 -165 -52...
result:
wrong answer 1st words differ - expected: '3668', found: '-154'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 32ms
memory: 22756kb
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:
-40968 -48049 -19993 -2329 -3319 -28380 -33980 -10498 -14107 -40428 -24099 -2630 -23789 -15524 -16272 -17878 -4004 -39024 -25888 -3806 -1709 -31585 -16836 -27355 -9710 -3961 -4325 -21645 -6687 -20033 -4242 -2852 -1969 -13945 -24348 -21046 -6135 -25500 -25457 -19507 -18724 -201 -6719 -43357 -1436 -15...
result:
wrong answer 1st words differ - expected: '113194', found: '-40968'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 2ms
memory: 9776kb
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:
-26 -64 -23 -5 -65 -69 -76 27 60 -90 -169 -58 -17 -13 -16 -174 -155 -129 -61 -33 -58 -7 -46 40 21 -2 -91 -58 -37 -107 -78 -28 35 -4 -55 -93 -1 1 -20 -171 -212 13 3 -57 -5 6 -11 -98 -3 -67 -13 -8 -149 -50 -82 -167 -33 -47 11 -84 -30 -13 -12 -33 -69 -14 -104 -53 44 -93 -9 -32 -39 -125 -63 -56 -127 -58...
result:
wrong answer 1st words differ - expected: '1322', found: '-26'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 424ms
memory: 97532kb
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:
-7095 -1604 -3931 -200 -664 -3212 -5480 -9519 -7476 -1213 -3412 -2967 -7760 -1605 -6096 -253 -1472 -1229 14 -820 -624 -3696 -10 -1112 -1022 -8036 -9330 -2881 -802 -5434 -6094 -1142 -4521 -523 -360 -6641 -1444 -4033 -824 -2841 -4120 -2238 -336 -1493 -2980 -5729 -1393 -564 -3328 -2672 -2027 209 -1496 ...
result:
wrong answer 1st words differ - expected: '1263815', found: '-7095'