QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350524#5173. 染色ANIG0 570ms183572kbC++232.5kb2024-03-10 19:48:312024-03-10 19:48:31

Judging History

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

  • [2024-03-10 19:48:31]
  • 评测
  • 测评结果:0
  • 用时:570ms
  • 内存:183572kb
  • [2024-03-10 19:48:31]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5,T=17;
int n,m,w[N],lst[N],nxt[N],wz[N],to[N],f1[N][20],f2[N][20],mk[N];
vector<int>q1,q2;
inline int read(){
    int res=0;char c;
    do{
        c=getchar();
    }while(!isdigit(c));
    while(isdigit(c)){
        res=res*10+c-'0';
        c=getchar();
    }
    return res;
}
int solve1(int l,int r){
    int L=0,R=q1.size()-1;
    while(L<R){
        int mid=L+R>>1;
        if(q1[mid]>=l)R=mid;
        else L=mid+1;
    }
    int w=L;
    if(q1[w]<l||nxt[q1[w]]>r)return 0;
    int res=0,x=nxt[q1[w]];
    for(int i=T;i>=0;i--){
        if(f1[x][i]<=r)x=f1[x][i],res|=1<<i;
    }
    return res+1;
}
int solve2(int l,int r){
    int L=0,R=q2.size()-1;
    while(L<R){
        int mid=L+R>>1;
        if(q2[mid]>r)R=mid;
        else L=mid+1;
    }
    int w=L-1;
    if(w<0)return 0;
    int res=0,x=q2[w];
    for(int i=T;i>=0;i--){
        if(f2[x][i]>=l)x=f2[x][i],res|=1<<i;
    }
    return res+(lst[x]>=l);
}
int solve(int l,int r){
    if(l<=r)return 2*(r-l)-solve1(l,r);
    return 2*(l-r)-solve2(r,l);
}
void print(int x){
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
signed main(){
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        w[i]=read();
        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<=T;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]){
            mk[i]=1;
            continue;
        }
        to[j]=i;
        while(to[nw]<=lst[i])nw=to[nw];
        f2[i][0]=nw;
        j=i;
        q1.push_back(lst[i]);
        q2.push_back(i);
    }
    nxt[n+1]=n+1;
    for(int i=n,j=n+1,nw=n+1;i>=1;i--){
        if(mk[nxt[i]]||nxt[i]>n)continue;
        to[j]=i;
        while(to[nw]>=nxt[i])nw=to[nw];
        f1[nxt[i]][0]=nxt[nw];
       // cout<<i<<" "<<nxt[i]<<" "<<nxt[nw]<<endl;
        j=i;
    }
    for(int i=1;i<=T;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=read(),r=read();
        print(solve(l,r));
        putchar('\n');
    }
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 15956kb

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
4575
5976
8382
729
7013
183
7320
492
1140
253
2249
13226
6254
456
7507
2162
10481
1791
2675
4801
293
5997
627
6654
6179
11414
2712
3157
7836
17782
511
5486
17835
9564
6147
4996
14577
670
463
15613
12669
8872
7833
10987
6603
6399
5023
9102
8529
2173
10299
2694
12537
4958
2144
8809
1907
6476
2828...

result:

wrong answer 63rd words differ - expected: '5594', found: '5595'

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 13
Accepted
time: 53ms
memory: 35248kb

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
133099
54921
6483
9199
78290
93920
29192
38941
111588
66619
7226
66019
42776
44640
49274
11102
107722
71676
10708
4735
87161
46860
75805
27270
10951
12237
59513
18641
55105
11626
7850
5521
38727
67276
58326
16941
70130
70341
53673
51864
551
18481
119885
4016
43296
62515
33972
9870
24982
33222...

result:

ok 100000 tokens

Test #8:

score: -13
Wrong Answer
time: 58ms
memory: 39020kb

input:

100000 100000
2 3 2 2 2 1 2 1 2 1 2 2 3 3 3 2 1 2 1 1 3 3 3 1 3 1 1 1 2 2 1 1 3 3 3 2 2 2 1 3 3 3 3 3 3 2 1 3 2 1 3 3 1 1 1 2 3 1 1 3 3 2 1 1 2 2 2 1 3 1 1 3 2 2 1 2 2 3 2 1 1 1 1 1 1 2 2 3 3 2 1 3 3 2 3 2 1 2 3 3 1 3 1 3 3 1 3 3 1 3 1 1 3 2 3 2 2 2 1 3 2 1 2 1 2 3 3 3 3 3 1 2 2 2 2 1 2 2 3 3 1 2 3 ...

output:

26713
92501
21509
49442
97641
78683
141125
77139
85866
63249
94772
69580
92232
51238
68375
24225
33431
945
69079
81415
89436
46535
15964
5588
93083
42072
99191
79445
79452
91055
38537
37616
422
72269
18476
82679
19235
10612
8002
12362
35849
66190
71653
93753
68380
17858
100447
115325
114262
29272
91...

result:

wrong answer 62573rd words differ - expected: '77138', found: '77139'

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 18
Accepted
time: 0ms
memory: 15960kb

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
1743
2611
4759
4995
2950
1327
880
5076
7811
4860
935
925
808
7270
7663
5325
3813
3225
4478
1577
2540
40
901
300
4351
3882
3813
5739
4610
1658
437
1416
3623
5257
565
119
2044
7615
9112
2047
3121
3683
2883
420
727
4006
179
3231
1443
1602
7127
3008
5954
8083
1539
3807
363
4476
3300
1741
818
2...

result:

ok 5000 tokens

Test #16:

score: 0
Accepted
time: 4ms
memory: 20056kb

input:

5000 5000
180 296 137 108 236 226 19 135 16 42 151 140 223 244 115 170 230 207 143 65 195 219 77 119 170 197 223 65 64 217 206 157 100 52 202 192 19 193 281 229 212 183 63 220 261 66 209 32 63 190 144 221 180 248 29 265 152 141 212 50 129 237 281 270 261 192 104 55 133 12 92 91 61 258 51 172 244 257...

output:

2352
1322
634
560
4251
760
1955
2722
5272
6615
1000
4720
1911
3371
4615
1164
7958
5006
2763
2322
6894
5026
4684
6645
607
5386
1264
7647
2221
651
98
1887
1722
248
954
4149
3969
1388
4170
2436
6737
377
6999
2049
2382
3586
3351
1107
6024
8005
535
1504
4057
438
4064
6837
4173
4865
1903
4334
2962
198
526...

result:

ok 5000 tokens

Test #17:

score: -18
Wrong Answer
time: 0ms
memory: 19984kb

input:

5000 5000
152 143 107 44 171 299 88 120 221 238 145 137 152 30 196 218 31 216 16 39 206 111 212 195 91 45 107 165 132 260 264 57 217 9 223 194 137 59 132 194 286 248 28 95 219 236 144 145 76 69 53 127 91 226 15 277 60 180 114 122 112 96 108 283 55 50 204 123 69 29 136 134 42 283 240 164 33 17 143 10...

output:

4076
2789
375
2375
2365
290
5779
1429
5357
1975
1146
4711
2438
4576
1984
173
4275
1748
1757
3292
538
495
3471
2870
1874
5565
2936
4736
1561
4658
6347
5936
1610
8726
518
3856
1264
2567
91
5371
4139
1415
6416
6198
4353
407
2055
7098
2759
1443
4707
4578
5778
6439
1210
353
2224
6103
4571
2885
4011
2550
...

result:

wrong answer 46th words differ - expected: '406', found: '407'

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 570ms
memory: 183572kb

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:

1263815
308608
760115
79452
160350
576908
988222
1716103
1345118
215185
615960
546263
1385912
320711
1094276
52291
276158
227555
2476
147750
144806
667128
25418
223778
184324
1445226
1666310
547639
146406
969316
1106498
237554
817297
112491
84810
1188701
316694
717959
169528
559867
767792
412202
732...

result:

wrong answer 19562nd words differ - expected: '1464740', found: '1464741'