QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350456#5173. 染色ANIG0 466ms125152kbC++141.6kb2024-03-10 18:48:312024-03-10 18:48:31

Judging History

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

  • [2024-03-10 18:48:31]
  • 评测
  • 测评结果:0
  • 用时:466ms
  • 内存:125152kb
  • [2024-03-10 18:48:31]
  • 提交

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],rs[N],c[N];
vector<pair<int,int> >g1[N],g2[N];
void add(int x,int k){
    while(x<=n){
        c[x]+=k;
        x+=x&-x;
    }
}
void add(int l,int r,int k){
    add(l,k);add(r+1,-k);
}
int gets(int x){
    int res=0;
    while(x){
        res+=c[x];
        x-=x&-x;
    }
    return res;
}
signed main(){
    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=1;i<=m;i++){
        int l,r;
        cin>>l>>r;
        if(l<=r)g1[r].push_back({l,i});
        else g2[r].push_back({l,i});
    }
    for(int i=1,j=0;i<=n;i++){
        if(j<=lst[i]){
            if(nxt[j]<=lst[i]){
                add(1,lst[i],1);
            }else{
                add(j+1,lst[i],1);
            }
            j=lst[i];
        }
        for(auto j:g1[i])rs[j.second]=2*(i-j.first)-gets(j.first);
    }
    for(int i=1;i<=n;i++)c[i]=0;
    lst[n+1]=n+1;
    for(int i=n,j=n+1;i>=1;i--){
        if(j>=nxt[i]){
            if(lst[j]>=nxt[i]){
                add(nxt[i],n,1);
            }else{
                add(nxt[i],j-1,1);
            }
            j=nxt[i];
        }
        for(auto j:g2[i])rs[j.second]=2*(j.first-i)-gets(j.first);
    }
    for(int i=1;i<=m;i++)cout<<rs[i]<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 59272kb

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:

3704
4611
6028
8462
735
7080
184
7389
496
1150
254
2271
13351
6316
460
7574
2185
10580
1804
2699
4843
296
6056
632
6720
6241
11519
2737
3179
7913
17944
516
5540
18000
9654
6208
5043
14714
675
470
15757
12786
8956
7908
11092
6665
6458
5071
9189
8610
2192
10398
2719
12653
5005
2163
8892
1928
6541
2857...

result:

wrong answer 1st words differ - expected: '3668', found: '3704'

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 48ms
memory: 69032kb

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:

116887
137432
56651
6680
9510
80810
96975
30191
40178
115221
68814
7434
68217
44151
46056
50878
11452
111209
74006
11037
4867
89973
48369
78242
28157
11305
12663
61391
19254
56881
11991
8086
5690
39997
69514
60242
17488
72347
72662
55369
53568
575
19066
123802
4144
44707
64576
35074
10190
25794
3424...

result:

wrong answer 1st words differ - expected: '113194', found: '116887'

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 4ms
memory: 60812kb

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:

1331
2708
1754
2623
4783
5018
2965
1334
882
5104
7850
4883
942
932
812
7304
7705
5352
3834
3241
4498
1588
2554
40
906
300
4373
3902
3833
5772
4631
1668
438
1423
3644
5284
569
119
2054
7656
9163
2058
3135
3703
2896
421
730
4022
179
3248
1447
1607
7167
3024
5981
8125
1547
3827
366
4499
3318
1751
820
2...

result:

wrong answer 1st words differ - expected: '1322', found: '1331'

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 466ms
memory: 125152kb

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:

1265299
308978
761032
79548
160566
577590
989384
1718126
1346696
215439
616702
546906
1387541
321075
1095557
52346
276497
227849
2479
147919
144975
667920
25446
224049
184536
1446926
1668263
548272
146582
970449
1107802
237833
818257
112646
84920
1190104
317053
718818
169720
560535
768669
412705
733...

result:

wrong answer 1st words differ - expected: '1263815', found: '1265299'