QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350473#5173. 染色ANIG0 120ms60464kbC++141.7kb2024-03-10 19:11:382024-03-10 19:11:38

Judging History

你现在查看的是最新测评结果

  • [2024-03-10 19:11:38]
  • 评测
  • 测评结果:0
  • 用时:120ms
  • 内存:60464kb
  • [2024-03-10 19:11:38]
  • 提交

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],to[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,nw=0;i<=n;i++){
        if(lst[i]<lst[j])continue;
        to[j]=i;
        while(to[nw]<=lst[i])nw=to[nw];
        f1[nw][0]=i;
        f2[i][0]=nw;
        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: 0ms
memory: 18384kb

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:

3668
4576
6218
8739
729
7313
183
7631
509
1140
254
2332
13227
6254
473
7507
2162
10482
1867
2675
4989
294
6250
654
6655
6445
11414
2829
3285
8162
17783
531
5719
18595
9564
6413
5196
15206
694
479
16285
12669
9252
8161
10988
6891
6668
5238
9102
8888
2264
10300
2694
13074
4958
2233
9176
1983
6743
2950...

result:

wrong answer 2nd words differ - expected: '4575', found: '4576'

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 120ms
memory: 60464kb

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:

113194
181116
54921
8807
12516
78290
93921
39683
53027
111588
90714
9824
66019
58296
44641
67099
15092
146746
71677
10709
6432
118744
63695
75805
27270
10951
16537
81157
25307
75125
15861
10701
7488
38727
67277
58327
23068
70130
70342
73146
51864
750
18482
119886
4016
58913
85053
33973
9870
34085
33...

result:

wrong answer 2nd words differ - expected: '133099', found: '181116'

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 2ms
memory: 20712kb

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:

1322
2696
1779
2612
4759
4996
3022
1328
891
5183
7811
4970
936
943
808
7270
7663
5326
3900
3225
4573
1577
2593
40
924
300
4351
3975
3813
5866
4722
1658
438
1416
3623
5257
576
119
2045
7793
9112
2047
3185
3764
2953
420
730
4085
179
3232
1443
1633
7287
3064
5954
8267
1573
3807
368
4576
3301
1781
819
2...

result:

wrong answer 3rd words differ - expected: '1743', found: '1779'

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:

1270943
308609
764371
79452
160351
580119
993789
1725755
1352634
215185
615960
546264
1393701
322510
1094277
52568
277679
228858
2486
147751
144806
670853
25567
223779
184325
1453312
1675687
547640
147241
974761
1112705
237554
817298
112491
85287
1195393
318456
721995
170481
562972
767792
414543
732...

result: