QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#872591#8612. The Best Wifeucup-team1134#TL 2001ms15716kbC++233.9kb2025-01-26 02:34:232025-01-26 02:34:29

Judging History

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

  • [2025-01-26 02:34:29]
  • 评测
  • 测评结果:TL
  • 用时:2001ms
  • 内存:15716kb
  • [2025-01-26 02:34:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=610005,INF=15<<26;

int BI[MAX],R[MAX],RR[MAX];
pii dp[MAX];
const int D=800;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    int M=610000;
    for(int i=0;i<=M;i++){
        BI[i]=INF;
        R[i]=INF;
        RR[i]=INF;
        dp[i]=mp(0,INF);
    }
    
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        /*
         a=rng()%600000;if(a<0) a+=600000;
         a++;
         b=rng()%600000;if(b<0) b+=600000;
         b++;
         if(a>b) swap(a,b);
         */
        //cout<<a<<" "<<b<<endl;
        int aa=a/D,bb=b/D;
        if(aa==bb){
            chmin(R[a],b);
            chmin(RR[a],b);
            int mi=INF;
            for(int s=aa*D;s<aa*D+D;s++) dp[s]=mp(0,INF);
            for(int s=(aa+1)*D-1;s>=aa*D;s--){
                chmin(mi,R[s]);
                if(s!=(aa+1)*D-1) chmin(RR[s],RR[s+1]);
                if(mi!=INF){
                    if(mi==(aa+1)*D-1){
                        dp[s]=mp(1,(aa+1)*D-1);
                    }else if(dp[mi+1].fi==0){
                        dp[s]=mp(1,mi);
                    }else{
                        dp[s]=mp(dp[mi+1].fi+1,dp[mi+1].se);
                    }
                }
                
            }
            chmin(BI[aa],b);
        }else{
            chmin(RR[a],b);
            chmin(BI[aa],b);
            for(int s=(aa+1)*D-1;s>=aa*D;s--){
                if(s!=(aa+1)*D-1) chmin(RR[s],RR[s+1]);
            }
        }
        
        int ans=0,now=0,turn=0;
        while(now<=600000){
            //if(i==9898) cout<<now<<" "<<ans<<endl;
            if(dp[now].fi){
                turn++;
                ans+=dp[now].fi;
                now=dp[now].se+1;
            }else{
                int aa=now/D,tomi=INF;
                chmin(tomi,RR[now]);
                //cout<<i<<" "<<tomi<<endl;
                int po=aa+1;
                while(1){
                    //if(i%1000==0) cout<<i<<" "<<now<<" "<<po<<" "<<tomi<<endl;
                    turn++;
                    if(po*D>600000){
                        now=INF;
                        break;
                    }
                    if(po<tomi/D){
                        if(BI[po]/D==po){
                            now=po*D;
                            break;
                        }else{
                            chmin(tomi,BI[po]);
                            po++;
                        }
                    }else if(po==tomi/D){
                        ans++;
                        now=min(BI[po],tomi)+1;
                        break;
                    }else{
                        if(po*D>600000){
                            now=INF;
                            break;
                        }
                    }
                }
            }
        }
        //if(i%1000==0) cout<<i<<" "<<turn<<endl;
        cout<<ans<<"\n";
    }
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15568kb

input:

5
1 3
3 5
1 2
5 6
4 4

output:

1
1
2
2
3

result:

ok 5 number(s): "1 1 2 2 3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 15476kb

input:

100
67 72
1 100
61 65
87 91
19 77
47 97
3 85
64 97
6 92
33 36
7 27
33 44
13 98
3 62
36 97
26 39
7 35
2 92
8 64
37 83
5 89
26 87
6 96
58 71
49 96
3 85
27 65
16 93
26 70
8 97
1 100
8 93
5 59
9 92
9 99
1 100
8 81
7 66
4 78
12 52
28 42
1 36
2 100
75 81
26 61
8 86
4 44
58 74
29 100
40 77
83 100
39 59
3 9...

output:

1
1
2
3
3
3
3
3
3
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
6
6
6
6
6
6
6
6
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
9
9
10
10

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 392ms
memory: 15516kb

input:

100000
51660 126127
210168 259244
375216 406446
266465 360594
440097 493801
308365 394954
80451 132385
438120 528296
98030 155521
363557 431900
378862 434460
418401 490611
281907 339676
16991 74102
342851 430326
365420 396713
205195 237050
335783 388217
282383 322210
424391 425245
50628 78734
262644...

output:

1
2
3
4
5
5
5
5
5
5
5
5
5
6
6
6
6
6
6
7
7
8
8
8
8
9
9
10
10
10
10
10
10
11
12
12
12
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
14
14
14
15
15
15
15
15
15
15
15
15
15
16
16
16
16
16
16
16
16
16
16
17
17
18
18
18
18
18
18
18
18
18
18
18
18
18
18
19
19
19
20
20
20
20
20
...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 963ms
memory: 15400kb

input:

100000
279654 279683
114560 114598
146309 146322
73410 73447
525334 525360
85390 85428
58307 58326
19051 19099
483056 483066
501793 501794
582376 582417
224769 224785
25988 26034
466488 466490
584615 584650
143754 143801
519232 519269
177648 177668
569289 569316
251514 251556
549450 549450
425416 42...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
96
97
97
98
99
100
10...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 686ms
memory: 15392kb

input:

100000
189531 189531
318904 318905
356703 356704
382461 382462
336886 336886
517948 517948
233087 233088
169086 169087
406440 406441
328975 328975
69232 69233
90576 90576
318793 318793
147047 147047
223016 223016
433644 433644
22071 22072
537114 537115
301926 301926
422619 422619
477755 477756
542 5...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 720ms
memory: 15512kb

input:

100000
57237 57240
176325 176327
42205 42205
17763 17765
49433 49433
572987 572987
25495 25497
149662 149666
24618 24620
446574 446578
432952 432953
229463 229464
578271 578274
592617 592620
257219 257219
315129 315131
407620 407624
366835 366837
216343 216343
136055 136055
166363 166366
595382 5953...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 761ms
memory: 15592kb

input:

200000
358725 449443
325405 346981
192962 383958
400184 526956
28856 105815
22984 194669
58947 146182
179264 244600
449474 589402
325708 511019
64211 189979
355940 468867
434498 534039
321560 324011
145633 326833
263226 422177
186549 354712
201549 385706
199742 384903
439242 526870
115891 201539
315...

output:

1
2
2
2
3
3
3
4
5
5
5
5
5
6
6
6
6
6
6
6
6
6
6
6
6
7
7
7
7
7
7
7
7
7
7
7
7
8
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
9
9
10
10
10
10
10
10
10
11
11
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
13
13
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
1...

result:

ok 200000 numbers

Test #8:

score: 0
Accepted
time: 2001ms
memory: 15716kb

input:

200000
529330 529372
537446 537476
246687 246711
587726 587762
406392 406423
83710 83738
513588 513604
91688 91735
308498 308528
423908 423932
433106 433128
308815 308827
253944 253975
468078 468079
430544 430576
188303 188340
370064 370106
241744 241775
444273 444292
222233 222266
265063 265067
239...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 200000 numbers

Test #9:

score: 0
Accepted
time: 1404ms
memory: 15692kb

input:

200000
137139 137140
198106 198107
141426 141426
443475 443476
468159 468160
554206 554207
467938 467939
457368 457369
30269 30270
301420 301421
208779 208779
390446 390446
229064 229064
572313 572314
557841 557842
212844 212845
26105 26106
389247 389248
286652 286653
172502 172503
120144 120145
569...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 200000 numbers

Test #10:

score: 0
Accepted
time: 1558ms
memory: 15640kb

input:

200000
563156 563156
233699 233702
120196 120200
449380 449382
182598 182601
28933 28937
93163 93167
368881 368882
17883 17884
265396 265399
191398 191401
368420 368424
500484 500488
104338 104339
427627 427627
281927 281930
25359 25360
42751 42754
348205 348206
438051 438055
383579 383583
135350 13...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 200000 numbers

Test #11:

score: 0
Accepted
time: 1221ms
memory: 15460kb

input:

300000
298763 514245
247214 298186
184668 202726
317944 534255
318185 394207
311564 501049
354209 400937
32503 216103
135318 316466
48360 50639
437529 524956
362292 440128
399063 483479
190703 481597
413090 455312
232203 353403
287812 435387
581173 586653
420314 450808
100485 309478
426077 510484
25...

output:

1
2
3
3
3
3
3
3
3
4
5
5
5
5
5
5
5
6
6
6
6
6
6
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
8
8
8
8
9
9
9
9
9
9
9
10
10
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
13
13
1...

result:

ok 300000 numbers

Test #12:

score: -100
Time Limit Exceeded

input:

300000
272266 272275
235393 235414
187800 187827
497909 497952
206778 206803
325631 325665
243233 243250
41726 41761
441945 441987
184268 184274
225521 225565
238037 238054
64834 64851
170013 170025
155087 155117
3404 3418
483408 483446
505313 505317
555937 555943
47862 47878
424183 424196
251140 25...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result: