QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743345 | #5173. 染色 | 2024tangjiaqi | 0 | 0ms | 0kb | C++14 | 1.4kb | 2024-11-13 18:58:48 | 2024-11-13 18:58:48 |
answer
//created by fqr & cyx in 2024
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define ll long long
#define pb emplace_back
int ff,Ch;
template <typename T> inline void rd(T &x) {
x=0,ff=1,Ch=getchar();
while((Ch<'0'||Ch>'9') && Ch!='-') Ch=getchar();
if(Ch=='-')Ch=getchar(),ff=-1;
while(Ch>='0' && Ch<='9') {
x=(x<<1)+(x<<3)+Ch-'0';
Ch=getchar();
}
x*=ff;
}
template <typename T,typename ...Args> inline void rd(T &x,Args &...args) {
rd(x), rd(args...);
}
using namespace std;
const int N=1e6+5,inf=0x3f3f3f3f;
int n,Q;
int mp[N];
int a[N];
int f[20][N],suf[N];
signed main() {
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
memset(f,0x3f,sizeof(f));
rd(n),rd(Q);
for(int i=1; i<=n; i++) {
rd(a[i]);
if(mp[a[i]])
f[0][mp[a[i]]]=i;
mp[a[i]]=i;
}
for(int i=n; i; i--)
f[0][i]=min(f[0][i],f[0][i+1]);
for(int j=1; j<=__lg(n); j++) {
for(int i=n; i; i--) {
f[j][i]=f[j][i+1];
if(f[j-1][i]!=inf)
f[j][i]=min(f[j][i],f[j-1][f[j-1][i]]);
}
}
// for(int i=1; i<=n; i++)
// cout<<f[i][0]<<' '<<f[i][1]<<'\n';
// cout<<'\n';
int l,r;
while(Q--) {
rd(l),rd(r);
if(l>r) swap(l,r);
int ans=2*(r-l);
for(int k=__lg(n); ~k; k--)
if(f[k][l]<=r)
l=f[k][l],ans-=(1<<k);
printf("%d\n",ans);
}
return 0;
}
/*
15 1
1 2 3 2 1 1 2 2 2 3 1 1 2 3 1
1 15
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
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:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #7:
score: 0
Dangerous Syscalls
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:
result:
Subtask #3:
score: 0
Dangerous Syscalls
Test #15:
score: 0
Dangerous Syscalls
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:
result:
Subtask #4:
score: 0
Dangerous Syscalls
Test #23:
score: 0
Dangerous Syscalls
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...