QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350468 | #5173. 染色 | ANIG | 0 | 168ms | 58860kb | C++14 | 1.6kb | 2024-03-10 19:08:52 | 2024-03-10 19:08:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
int n,m,w[N],lst[N],nxt[N],wz[N],f1[N][22],f2[N][22];
set<int>q1,q2;
int solve1(int l,int r){
auto w=q1.lower_bound(l);
if(w==q1.end()||nxt[(*w)]>r)return 0;
int res=0,x=nxt[*w];
for(int i=20;i>=0;i--){
if(f1[x][i]<=r)x=f1[x][i],res+=1<<i;
}
return res+1;
}
int solve2(int l,int r){
auto w=q2.upper_bound(r);
if(w==q2.begin())return 0;
w--;
int res=0,x=*w;
for(int i=20;i>=0;i--){
if(f2[x][i]>=l)x=f2[x][i],res+=1<<i;
}
return res;
}
int solve(int l,int r){
if(l<=r)return 2*(r-l)-solve1(l,r);
return 2*(l-r)-solve2(r,l);
}
signed main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>w[i];
lst[i]=wz[w[i]];
wz[w[i]]=i;
}
for(int i=1;i<=n;i++)wz[i]=n+1;
for(int i=n;i>=1;i--){
nxt[i]=wz[w[i]];
wz[w[i]]=i;
}
for(int i=0;i<=20;i++)for(int j=0;j<=n+1;j++)f1[j][i]=n+1;
for(int i=1,j=0;i<=n;i++){
if(lst[i]<lst[j])continue;
f1[j][0]=i;
f2[i][0]=j;
j=i;
q1.insert(lst[i]);
q2.insert(i);
}
for(int i=1;i<=20;i++){
for(int j=1;j<=n;j++){
f1[j][i]=f1[f1[j][i-1]][i-1];
f2[j][i]=f2[f2[j][i-1]][i-1];
}
}
for(int i=1;i<=m;i++){
int l,r;
cin>>l>>r;
cout<<solve(l,r)<<"\n";
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 16580kb
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:
3587 4488 5853 8198 716 6861 182 7162 482 1120 251 2197 12937 6115 446 7343 2111 10257 1755 2607 4697 288 5860 613 6510 6043 11163 2655 3090 7663 17395 499 5362 17442 9357 6013 4891 14254 654 448 15272 12388 8677 7655 10746 6464 6265 4919 8901 8344 2133 10074 2633 12263 4849 2101 8614 1859 6329 2766...
result:
wrong answer 1st words differ - expected: '3668', found: '3587'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 168ms
memory: 58860kb
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:
105540 124068 51233 6053 8570 73004 87575 27183 36329 104050 62113 6769 61533 39908 41629 45940 10375 100459 66780 9993 4409 81301 43661 70641 25382 10229 11374 55540 17367 51374 10872 7351 5140 36123 62714 54393 15783 65460 65578 50082 48387 515 17246 111753 3735 40395 58293 31709 9200 23273 31001 ...
result:
wrong answer 1st words differ - expected: '113194', found: '105540'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 0ms
memory: 16416kb
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:
1304 2667 1716 2578 4700 4935 2919 1313 870 5004 7713 4799 921 912 795 7181 7562 5263 3762 3190 4418 1553 2506 40 891 297 4298 3835 3759 5656 4557 1634 432 1398 3574 5188 558 116 2015 7515 8992 2025 3082 3632 2852 419 717 3962 179 3187 1426 1583 7033 2964 5883 7978 1523 3753 356 4415 3255 1717 809 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1304'
Subtask #4:
score: 0
Time Limit Exceeded
Test #23:
score: 0
Time Limit Exceeded
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:
1259884 307624 757658 79203 159785 575036 985153 1710696 1340836 214498 614035 544493 1381570 319716 1090892 52143 275246 226817 2471 147267 144348 664984 25350 223047 183772 1440645 1661077 545957 145963 966258 1102984 236789 814741 112087 84502 1184996 315718 715726 169002 558033 765412 410888 729...