QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369168#3101. Event Hopping 2Rikku_eq0 99ms27244kbC++143.9kb2024-03-27 21:14:532024-03-27 21:14:54

Judging History

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

  • [2024-03-27 21:14:54]
  • 评测
  • 测评结果:0
  • 用时:99ms
  • 内存:27244kb
  • [2024-03-27 21:14:53]
  • 提交

answer

#include <bits/stdc++.h>
#define N 100005
#define mxL 22
#define ls(u) tr[u].ls
#define rs(u) tr[u].rs
using namespace std;
typedef long long ll;

int n, L, K, idr[N], pos[N];
int tp, stk[N], nxt[N][mxL], res[N];
int num[N*2], totn;

int rt, tot;
struct Seg { int ls, rs, sum; bool tg; } tr[N*4];

struct Qry { int l, r, lx, rx; } q[N];
struct Pnt {
    int id;
    bool operator< (const Pnt &x) const { return q[id].r<q[x.id].r; }
};
set <Pnt> s;
set <Pnt>::iterator it;

vector <int> ans;

bool cmpr (const int &a, const int &b) { return q[a].r<q[b].r; }

void buildST (int &u, int l, int r)
{
    if (!u) { u=++tot; }
    if (l==r) { return; }
    int md=(l+r)/2;
    buildST(ls(u), l, md);
    buildST(rs(u), md+1, r);
}
void pushdown (int u, int l, int r)
{
    if (!tr[u].tg) { return; }
    int md=(l+r)/2;
    tr[ls(u)].tg=1; tr[ls(u)].sum=md-l+1;
    tr[rs(u)].tg=1; tr[rs(u)].sum=r-md;
    tr[u].tg=0;
}
int qry (int u, int l, int r, int ql, int qr)
{
    if (l>qr || r<ql) { return 0; }
    if (ql<=l && r<=qr) { return tr[u].sum; }
    pushdown(u, l, r);
    int md=(l+r)/2;
    return qry(ls(u), l, md, ql, qr)+qry(rs(u), md+1, r, ql, qr);
}
void add (int u, int l, int r, int ql, int qr)
{
    if (l>qr || r<ql) { return; }
    if (ql<=l && r<=qr) { tr[u].tg=1; tr[u].sum=r-l+1; return; }
    pushdown(u, l, r);
    int md=(l+r)/2;
    add(ls(u), l, md, ql, qr);
    add(rs(u), md+1, r, ql, qr);
    tr[u].sum=tr[ls(u)].sum+tr[rs(u)].sum;
}

int main ()
{
    // freopen("0test.in", "r", stdin);
    // freopen("0test.out", "w", stdout);

    scanf("%d %d", &n, &K);
    L=ceil(log(n)/log(2));
    for (int i=1; i<=n; i++) {
        scanf("%d %d", &q[i].l, &q[i].r);
        idr[i]=i; num[++totn]=q[i].l; num[++totn]=q[i].r-1;
    }
    q[n+1].l=1000000001;
    q[n+1].r=1000000002;

    sort(idr+1, idr+n+1, cmpr);
    for (int i=1; i<=n; i++) { pos[idr[i]]=i; }

    idr[n+1]=n+1;
    for (int i=n; i>=1; i--) {
        while (tp>0 && q[idr[stk[tp]]].l<=q[idr[i]].l) { tp--; }

        int l=1, r=tp; nxt[i][0]=n+1;
        while (l<=r) {
            int md=(l+r)/2;
            if (q[idr[stk[md]]].l>=q[idr[i]].r) { l=md+1; nxt[i][0]=stk[md]; }
            else { r=md-1; }
        }
        stk[++tp]=i;
    }

    for (int j=0; j<=L; j++) { nxt[n+1][j]=n+1; }
    nxt[0][0]=1;
    for (int i=n; i>=0; i--) {
        for (int j=1; j<=L; j++) { nxt[i][j]=nxt[nxt[i][j-1]][j-1]; }
    }

    sort(num+1, num+totn+1);
    totn=unique(num+1, num+totn+1)-(num+1);
    for (int i=1; i<=n; i++) {
        q[i].lx=lower_bound(num+1, num+totn+1, q[i].l)-num;
        q[i].rx=lower_bound(num+1, num+totn+1, q[i].r-1)-num;
    }

    int curr=0;
    for (int i=1; i<=n; i++) {
        int id=idr[i];
        if (q[id].l>=curr) { res[0]++; curr=q[id].r; }
    }

    if (res[0]<K) { printf("-1"); return 0; }

    buildST(rt, 1, totn);

    int sum=res[0];
    for (int i=1; i<=n; i++) {
        if (qry(rt, 1, totn, q[i].lx, q[i].rx)) { continue; }
        
        int pcur=pos[i];
        it=s.lower_bound((Pnt){ i });

        int nx=(it==s.end() ? n+1 : (*it).id);
        int cnt=0;
        for (int j=L; j>=0; j--) {
            if (q[idr[nxt[pcur][j]]].r<=q[nx].l) { cnt+=(1<<j); pcur=nxt[pcur][j]; }
        }
        res[i]=cnt;

        int pr, tmppr;
        if (it==s.begin()) { pr=0; }
        else { it--; pr=(*it).id; }
        tmppr=pr;
        cnt=0;
        for (int j=L; j>=0; j--) {
            if (q[idr[nxt[pr][j]]].r<=q[i].l) { cnt+=(1<<j); pr=nxt[pr][j]; }
        }

        if (sum+res[i]+cnt-res[tmppr]+1>=K) {
            ans.push_back(i);
            sum+=res[i]-res[tmppr]+cnt+1; res[tmppr]=cnt;
            s.insert((Pnt){ i });
            add(rt, 1, totn, q[i].lx, q[i].rx);
        }

        if (ans.size()>=K) { break; }
    }
    
    for (int i=0; i<K; i++) { printf("%d\n", ans[i]); }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 8124kb

input:

1 1
1 3

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2 1
2 4
3 7

output:

1

result:

ok single line: '1'

Test #3:

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

input:

3 1
2 5
3 5
4 7

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 87ms
memory: 27244kb

input:

99999 93097
40044 40749
44538 45365
46530 47401
52845 53481
59519 60065
86226 87059
88353 88992
95665 96502
95669 96575
100446 100968
121870 122544
130836 131540
146294 147230
151177 151970
160381 161376
164174 165119
166582 167438
169062 169687
173200 173849
177329 178217
189213 189811
249372 25029...

output:

1
2
3
4
5
6
7
8
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
48
49
50
51
52
53
54
55
56
57
59
60
61
62
64
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
103
104
105
106
1...

result:

ok 93097 lines

Test #5:

score: 0
Accepted
time: 95ms
memory: 26792kb

input:

99999 88403
2150 2736
19195 20022
27727 28620
35862 36457
60973 61718
80791 81690
86082 86984
106677 107346
108139 108915
110531 111303
115660 116605
122015 122980
123932 124908
134353 135199
134501 135222
155517 156054
159779 160302
160367 161281
160417 161149
164477 165443
176902 177695
188399 189...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
17
18
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
62
63
64
65
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
101
102
103
105
106
107
108...

result:

ok 88403 lines

Test #6:

score: 0
Accepted
time: 81ms
memory: 26808kb

input:

99999 83610
13054 13952
35115 35859
40425 41389
47089 47725
59574 60420
70210 71056
73047 73747
78599 79251
84786 85465
96167 97165
118120 118862
122717 123442
139557 140446
140442 140948
167280 168099
172791 173512
175238 175890
179283 180010
188674 189600
192740 193434
197040 197739
206126 206742
...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
23
24
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
51
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
102
103
104
105
106
...

result:

ok 83610 lines

Test #7:

score: 0
Accepted
time: 77ms
memory: 26308kb

input:

99999 74350
13130 13773
26195 26982
41474 42296
50556 51176
52028 52952
61800 62451
64260 64787
77433 78243
79862 80477
104820 105424
119745 120717
124071 124902
137929 138510
155031 155946
156225 156935
156558 157403
186203 186953
190155 190856
202887 203601
219505 220031
224776 225447
225343 22601...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
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
54
55
56
57
58
59
60
61
62
63
64
65
66
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
103
104
105
106...

result:

ok 74350 lines

Test #8:

score: 0
Accepted
time: 96ms
memory: 27180kb

input:

100000 93001
8963 9929
13535 14469
13715 14543
62424 63376
64988 65554
66126 66943
80525 81309
81865 82540
82113 82814
83753 84473
91289 91956
93976 94815
123004 123792
137032 137701
145506 146047
154391 155306
163907 164811
173352 174335
207897 208525
216768 217487
224290 225235
247075 247627
25288...

output:

1
2
4
5
6
7
8
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
38
39
41
43
44
45
46
47
48
49
50
51
52
54
55
57
58
59
60
61
62
63
64
65
66
68
69
70
71
72
73
74
75
76
77
78
79
80
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
98
99
100
101
102
103
104
105
107
108
109
110
111...

result:

ok 93001 lines

Test #9:

score: 0
Accepted
time: 97ms
memory: 26772kb

input:

100000 88358
548 1465
4599 5115
17400 18217
20126 21091
24033 24624
31908 32485
35051 36014
36278 36911
52827 53811
58821 59329
64125 64906
96889 97505
112354 113069
123259 124017
134029 134704
144556 145471
170781 171364
186208 186898
187848 188781
188857 189400
207006 207911
221835 222742
229559 2...

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
66
67
68
69
70
71
72
73
74
75
77
78
79
80
81
82
83
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
105
1...

result:

ok 88358 lines

Test #10:

score: 0
Accepted
time: 89ms
memory: 26772kb

input:

100000 83736
6162 6948
47528 48088
51581 52406
54252 55179
59136 60123
74088 74789
85966 86478
97745 98486
105645 106507
109178 110065
119123 119948
131090 132059
134054 135027
158930 159457
161639 162627
162886 163459
171585 172115
173959 174537
189725 190461
192362 193084
206375 207310
215518 2162...

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
27
28
29
30
31
32
33
34
36
37
38
39
40
41
42
43
44
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
79
81
82
83
84
85
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
106
107
10...

result:

ok 83736 lines

Test #11:

score: 0
Accepted
time: 94ms
memory: 26064kb

input:

100000 74537
1240 2045
45619 46191
47541 48308
60964 61831
66245 67022
97465 98412
100671 101637
101356 101891
106041 106847
107695 108471
130232 130957
142492 143049
144495 145192
152230 152795
176811 177714
178845 179825
181023 181667
186532 187200
213378 214004
223268 224065
237222 238060
252278 ...

output:

1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
25
27
28
30
31
32
33
34
35
36
37
38
39
40
41
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
100
101
102
104
106
107
108
109
...

result:

ok 74537 lines

Test #12:

score: 0
Accepted
time: 72ms
memory: 25492kb

input:

100000 57378
288 9909
3927 11152
20084 28964
30571 39126
38628 45300
41935 47457
48699 55269
55106 61254
77890 83130
85054 93921
88571 96480
91031 99813
93263 100777
101052 107389
123891 133202
136899 144986
166399 172157
172062 180451
175185 181470
178642 185679
186035 191294
193000 202232
210529 2...

output:

1
3
4
6
7
9
10
14
15
16
17
19
21
22
23
24
28
31
33
35
38
41
42
43
45
47
49
51
52
54
55
56
57
59
61
62
63
64
65
66
67
68
69
70
71
73
74
75
76
77
78
80
81
82
84
86
88
89
91
93
94
96
97
98
101
103
104
106
107
109
111
112
114
117
119
121
123
124
125
126
128
129
131
133
135
137
139
141
142
144
146
148
15...

result:

ok 57378 lines

Test #13:

score: 0
Accepted
time: 73ms
memory: 25368kb

input:

100000 54689
635 6242
13982 22182
22661 30718
24154 30227
30660 36548
33924 42990
44017 50030
60973 66351
64489 72778
102975 110314
109192 117764
115739 121380
118596 126708
132734 139073
137862 143602
140007 147771
145000 151039
153742 162901
154064 161969
155008 162999
161339 166755
164906 173628
...

output:

1
2
3
6
7
8
10
12
14
16
18
22
23
24
25
27
31
32
34
35
36
38
39
41
43
46
47
48
49
52
56
57
58
59
60
63
65
67
70
72
73
75
76
79
80
82
83
84
86
87
89
90
91
93
94
95
96
100
101
104
105
107
110
113
114
119
121
126
127
128
130
131
133
134
135
137
138
141
143
144
148
149
151
152
156
158
160
161
163
164
165...

result:

ok 54689 lines

Test #14:

score: 0
Accepted
time: 80ms
memory: 25112kb

input:

100000 51899
12721 22028
16145 23647
28093 34105
31291 36638
44047 52326
55488 64995
56157 62217
66418 71755
68687 74835
69342 74935
70374 78347
71160 78293
98866 104712
106829 115593
123303 132506
127977 136686
131387 140227
143951 153377
151420 158533
153814 159285
159241 169053
167504 175345
2280...

output:

1
3
5
6
8
13
14
15
18
20
22
23
24
25
28
29
31
32
35
38
40
41
44
46
48
50
51
54
56
59
62
64
66
68
70
73
75
76
78
80
81
82
84
87
88
90
91
92
95
97
100
103
104
105
107
109
110
111
113
114
116
117
118
120
121
122
123
124
125
128
130
131
132
135
138
140
141
143
146
148
149
151
155
157
159
160
161
162
164...

result:

ok 51899 lines

Test #15:

score: 0
Accepted
time: 58ms
memory: 24780kb

input:

100000 45970
2875 10006
6962 14904
8232 13847
39406 45823
40169 48870
65197 71238
65771 73553
70120 79190
93112 101501
120131 129654
138254 143706
140305 147707
152704 161454
157287 166457
165588 173813
176164 184901
179803 186708
186911 196877
203774 212710
208535 217456
227845 234554
229061 236126...

output:

1
4
6
9
10
11
13
15
16
18
19
21
23
27
28
29
30
31
32
34
37
39
41
42
43
44
45
47
49
50
52
53
54
56
57
59
61
64
65
68
69
71
74
75
76
78
79
80
82
84
85
86
87
88
90
93
94
96
98
101
103
106
108
111
113
114
116
118
119
120
122
123
124
126
127
128
131
133
137
139
141
144
147
149
150
151
152
155
157
159
160...

result:

ok 45970 lines

Test #16:

score: 0
Accepted
time: 51ms
memory: 23368kb

input:

100000 12813
1033 81070
12954 81500
13156 68815
35338 111064
35506 119065
45225 124391
59060 117337
82625 160515
87693 157948
93135 171962
98548 149280
98885 184397
119996 172867
121551 204333
130795 181820
151221 223534
163612 238764
191948 268094
192810 249321
201147 280094
209164 272596
217258 28...

output:

1
8
17
27
34
43
51
57
62
70
77
86
91
98
104
110
119
128
136
142
150
157
169
177
182
189
201
206
215
222
228
234
244
251
258
266
275
285
296
306
315
321
327
332
340
351
358
370
376
387
395
404
408
415
421
427
431
441
450
455
462
466
474
476
482
487
493
500
507
515
520
528
537
545
551
557
566
577
585
...

result:

ok 12813 lines

Test #17:

score: 0
Accepted
time: 54ms
memory: 23152kb

input:

100000 11486
9958 109537
10290 105884
11646 98237
13442 105194
15629 88293
20778 93420
21509 86475
34164 89416
42240 109910
57255 128711
57391 155451
64212 135574
75341 158468
89926 183847
109410 200713
115234 179765
122402 209776
128743 205641
141578 222667
147296 215047
150895 216677
152208 248228...

output:

1
16
24
29
39
46
57
69
76
89
96
106
114
122
127
133
142
149
159
174
182
187
195
204
214
223
236
242
253
257
267
276
283
289
292
296
306
312
321
332
334
344
352
364
371
386
395
404
409
421
433
443
447
456
462
467
471
479
496
505
511
513
519
534
540
547
559
565
568
573
586
593
595
606
613
617
620
630
...

result:

ok 11486 lines

Test #18:

score: 0
Accepted
time: 54ms
memory: 23104kb

input:

100000 10243
20686 118188
28362 109019
29665 112454
42086 128002
47854 100516
69351 143086
80462 141232
82765 148621
85924 148841
85970 159110
109511 188316
112760 167213
126746 181139
126751 189646
139340 226463
141613 229658
142113 236962
142337 217316
192209 270843
201105 257365
240041 328724
244...

output:

1
13
19
27
34
40
48
60
69
73
82
95
98
104
114
123
131
135
140
147
159
170
178
188
200
211
220
230
233
241
247
259
266
275
281
285
294
301
312
316
335
341
351
356
366
376
388
397
405
415
422
430
441
451
455
460
474
480
488
498
504
513
523
531
541
546
557
566
575
584
592
596
607
612
620
636
642
650
66...

result:

ok 10243 lines

Test #19:

score: 0
Accepted
time: 56ms
memory: 22736kb

input:

100000 1692
1761 562188
8018 654677
12329 961589
21217 810688
21850 726916
26301 994382
28685 582608
32421 747755
39099 581374
47897 912559
54394 659595
56476 675836
60014 1008714
72795 994742
75196 843153
88489 828045
90004 1024886
100124 781515
106686 734628
107999 959025
110160 1066569
122777 730...

output:

1
74
151
213
267
332
383
442
509
574
624
693
759
817
874
936
992
1048
1101
1158
1230
1267
1317
1380
1451
1502
1567
1631
1694
1743
1812
1881
1931
1988
2034
2109
2159
2202
2258
2312
2367
2418
2485
2538
2610
2670
2724
2776
2830
2889
2949
3005
3045
3086
3159
3214
3278
3338
3394
3433
3497
3554
3618
3676
...

result:

ok 1692 lines

Test #20:

score: 0
Accepted
time: 58ms
memory: 22428kb

input:

100000 1532
11110 578739
15827 900884
20209 693425
20787 1005821
30145 907459
30992 780446
34235 729985
79035 651546
85599 832995
113134 652298
121940 1100169
135680 828786
141312 898191
143767 931673
177769 805753
181414 924082
191854 795021
201070 701360
211465 826185
217164 1154581
223164 1222889...

output:

1
59
141
198
298
373
433
509
588
657
726
787
853
914
997
1097
1186
1250
1338
1405
1484
1568
1648
1725
1785
1858
1941
2022
2074
2169
2239
2316
2367
2422
2493
2547
2629
2726
2814
2870
2928
2990
3081
3184
3250
3323
3412
3471
3526
3583
3648
3743
3820
3885
3975
4067
4166
4235
4300
4397
4446
4508
4573
463...

result:

ok 1532 lines

Test #21:

score: 0
Accepted
time: 50ms
memory: 22444kb

input:

100000 1359
6234 861238
9126 603680
11750 603711
24871 794005
43119 653921
44111 990217
50268 968692
68132 986854
68579 797843
72248 721632
91367 827206
98456 693310
116298 822182
124847 960194
126999 1008775
131415 872868
135286 662199
150820 781868
183837 915832
184357 1161197
185711 1042124
18840...

output:

1
100
175
228
303
383
436
546
659
729
784
857
927
966
1059
1156
1267
1331
1403
1452
1519
1610
1698
1764
1843
1914
1992
2086
2168
2244
2315
2381
2480
2550
2646
2716
2802
2900
2951
3023
3115
3195
3277
3358
3431
3522
3608
3697
3774
3847
3955
4024
4113
4195
4269
4368
4424
4538
4584
4637
4705
4808
4884
4...

result:

ok 1359 lines

Test #22:

score: 0
Accepted
time: 61ms
memory: 22480kb

input:

100000 189
11871 5366857
12597 9358750
14009 5205039
18514 9736021
20792 7819695
23493 6457961
25878 9701971
30227 9271987
37129 6458756
43408 9430450
45981 5848267
50021 6061887
57665 6870713
60542 9297323
64683 8507199
67331 6852620
69935 6350577
73053 9746131
112740 7267403
116273 9213900
137641 ...

output:

1
572
1043
1541
2077
2591
3133
3715
4226
4768
5321
5909
6431
6993
7524
8000
8521
9038
9591
10111
10656
11186
11721
12267
12750
13309
13841
14438
15054
15576
16105
16697
17307
17855
18411
18942
19467
19991
20485
21025
21572
22101
22621
23131
23638
24197
24754
25237
25768
26307
26801
27319
27835
28421...

result:

ok 189 lines

Test #23:

score: 0
Accepted
time: 52ms
memory: 22524kb

input:

100000 170
15020 9542401
19499 9392647
19904 7646218
22983 6941656
32667 6484681
46653 6933539
56208 5473471
60717 6361757
81926 5641147
91980 8928336
94894 5631653
120394 6671365
130890 7917964
132476 5985347
137771 7575277
148174 6984429
177899 9467333
180823 8727173
181899 7786849
206091 6801597
...

output:

1
986
1611
2322
3025
3902
4717
5286
6049
6896
7642
8175
8859
9822
10414
11247
11759
12574
13439
14178
15164
15737
16360
17016
17831
18383
19410
19995
20645
21598
22138
22804
23458
24118
24749
25491
26304
26897
27614
28482
29458
30044
30564
31404
32199
32801
33679
34575
35103
36012
36490
37092
37619
...

result:

ok 170 lines

Test #24:

score: 0
Accepted
time: 61ms
memory: 22888kb

input:

100000 151
3579 9118430
9447 9032933
14340 7691467
22723 5499192
34606 9834536
47116 6238057
50317 8013445
61242 5447275
69720 7351131
71026 5525709
99210 8453046
99742 5998151
126894 7899026
137262 5299483
147751 7757492
158431 9076647
196594 8459875
208689 8979881
217587 6422716
219034 6165744
228...

output:

1
892
1416
2260
3051
3627
4384
4969
5918
6702
7693
8359
8962
9766
10319
10963
11875
12671
13555
14324
15214
15851
16476
17083
18059
19031
19657
20336
21334
22133
22699
23417
24281
25024
25984
26940
27587
28388
29396
30246
31009
31969
32500
33250
34152
34913
35611
36580
37230
37880
38504
39134
39749
...

result:

ok 151 lines

Test #25:

score: 0
Accepted
time: 70ms
memory: 22736kb

input:

100000 18
8109 56775703
11232 74757212
15872 74507021
30195 57394492
45875 70393643
47551 74279114
49350 98896516
51429 80228938
53821 74959851
81875 67009083
93968 90825457
98446 68959198
125292 76509949
126753 73919168
150175 91319742
151324 97878794
157896 52805171
162328 81425517
162635 61803343...

output:

1
6137
13176
20323
26077
31648
37228
42943
48628
54162
59974
65670
71447
77199
82887
88502
94300
99914

result:

ok 18 lines

Test #26:

score: 0
Accepted
time: 70ms
memory: 22736kb

input:

100000 17
5751 56778827
15135 63974156
15673 63824206
22694 78041150
43956 56138887
53848 75522379
79685 88688017
82640 58184217
88386 82120905
98588 63275168
98929 72529330
100002 52940837
126875 50480059
130623 81125021
145677 83657256
152240 69367414
168620 93644452
175295 69686460
180229 9877236...

output:

1
6418
17109
25909
31937
37723
43378
49116
54774
60467
66115
71675
77321
83212
88901
94442
99985

result:

ok 17 lines

Test #27:

score: 0
Accepted
time: 67ms
memory: 22112kb

input:

100000 15
3561 66111120
9802 93321355
10933 78907631
20110 70956938
34371 94948134
77905 57173394
83776 91987357
90064 93855771
90222 84732759
91345 64200241
94774 94219049
100059 96434167
105668 93971823
107556 69555569
112624 59052396
114267 81539543
119384 55088679
120482 63806436
153401 78359176...

output:

1
7272
16593
25490
35385
44485
50708
59374
65768
71282
76945
82646
88442
94040
99963

result:

ok 15 lines

Test #28:

score: 0
Accepted
time: 23ms
memory: 17864kb

input:

100000 92832
3904 4676
17152 18031
45308 45968
52035 53028
65993 66781
70630 71224
93527 94490
103809 104329
110889 111438
121174 122156
136806 137731
151126 151674
155381 155886
174217 175136
179951 180923
186771 187721
196450 197416
233337 233891
235748 236671
239022 240011
250329 251110
274824 27...

output:

-1

result:

ok single line: '-1'

Test #29:

score: 0
Accepted
time: 35ms
memory: 16964kb

input:

100000 57559
9811 19660
39039 45034
51646 58360
77780 86559
88545 94426
92332 99376
95958 102734
98170 107323
99186 108855
115004 123561
118333 125003
131494 139616
150582 156372
160367 168741
169108 176437
169730 178826
188042 195536
198497 207252
205598 212689
209988 215705
215270 222264
248660 25...

output:

-1

result:

ok single line: '-1'

Test #30:

score: 0
Accepted
time: 35ms
memory: 18020kb

input:

100000 12816
10705 81228
24794 112425
26012 94365
33798 115157
50355 120380
65359 161028
65530 132290
76244 158981
86155 166344
91749 145380
107269 170103
108577 191966
121561 177732
139959 220843
140635 222426
163553 241075
173063 232632
173144 271194
177165 239814
178297 233885
207355 285290
21101...

output:

-1

result:

ok single line: '-1'

Test #31:

score: 0
Accepted
time: 42ms
memory: 17808kb

input:

100000 1697
4905 859654
6037 963822
18599 881164
19144 720042
24799 889785
39319 770870
40326 1013932
40964 680543
41319 734642
52952 1046566
73626 746287
74034 697292
82999 830672
88378 594384
97312 600480
117186 1045625
117665 838820
131440 725034
133455 938219
143307 691741
160872 839582
172998 9...

output:

-1

result:

ok single line: '-1'

Test #32:

score: 0
Accepted
time: 38ms
memory: 17092kb

input:

100000 188
6538 5750489
35295 8856905
36949 9632685
56936 5192568
57114 9654737
61953 7613350
63339 7586928
85730 8146324
87048 5432388
92541 5822993
114576 8399838
120763 8890670
139789 6933072
143129 6489022
152417 9469113
153109 7432894
167187 5629094
167690 9087360
170065 5959807
177657 8158375
...

output:

-1

result:

ok single line: '-1'

Test #33:

score: 0
Accepted
time: 41ms
memory: 17384kb

input:

100000 19
11696 86394771
15030 83193673
21618 98424422
22595 77878508
22735 86392647
57110 94832421
60929 80830109
75471 89004994
79095 85788873
96996 87641109
114341 94738620
124516 54384823
135830 69674965
137162 52868775
149489 90413528
154708 59929605
158576 58522310
165944 55363464
199794 60460...

output:

-1

result:

ok single line: '-1'

Test #34:

score: 0
Accepted
time: 61ms
memory: 24456kb

input:

100000 34512
4001 10178
16727 26432
19853 28114
23766 32478
30904 38359
44152 52631
45308 50981
65993 72726
70035 76387
70630 80277
93527 101277
119889 125005
130174 135535
130809 140777
145806 153240
151126 157221
155381 162706
179951 187096
183217 192764
186771 195896
223450 230464
235748 242621
2...

output:

1
2
5
6
8
11
12
13
15
17
18
21
22
23
25
26
28
30
31
32
34
36
39
43
44
45
48
50
52
53
54
55
57
59
61
63
65
66
67
70
73
75
76
78
80
82
84
85
87
88
90
92
93
95
97
102
105
106
107
108
109
110
111
113
114
115
116
119
123
127
128
130
132
134
135
137
140
141
142
143
145
147
148
149
150
152
153
155
159
161
...

result:

ok 34512 lines

Test #35:

score: 0
Accepted
time: 49ms
memory: 23616kb

input:

100000 23024
9811 19660
39039 45034
51646 58360
77780 86559
88545 94426
92332 99376
95958 102734
98170 107323
99186 108855
115004 123561
118333 125003
131494 139616
150582 156372
160367 168741
169108 176437
169730 178826
188042 195536
198497 207252
205598 212689
209988 215705
215270 222264
248660 25...

output:

1
2
3
4
5
7
10
12
13
14
15
17
18
20
22
27
29
30
31
32
34
36
38
41
44
45
47
48
49
51
54
56
57
58
60
63
65
66
69
71
73
74
77
79
80
81
84
87
89
90
91
93
96
97
98
100
101
104
105
106
107
109
110
111
112
115
116
117
118
123
125
127
129
130
131
132
133
135
139
140
142
145
146
147
149
152
155
158
160
162
1...

result:

ok 23024 lines

Test #36:

score: 0
Accepted
time: 48ms
memory: 23140kb

input:

100000 11469
1749 9673
24794 33141
31015 39543
31561 39131
73553 80366
100042 107436
100746 107380
103683 109419
121616 129753
146270 153353
168277 174235
172338 179442
173056 178254
180700 190697
180878 186178
204655 214273
225196 234024
229485 238120
231513 239770
241919 250375
260338 265971
27329...

output:

1
2
5
6
9
10
11
14
16
17
20
21
22
23
24
25
26
27
29
30
34
36
38
40
41
42
43
44
45
47
48
52
54
57
60
61
64
65
68
70
72
74
75
78
79
80
81
82
84
85
86
87
91
92
94
96
97
98
101
103
105
106
107
112
114
116
119
121
123
124
125
127
129
132
133
134
135
137
139
143
144
145
147
148
149
151
152
153
154
155
156...

result:

ok 11469 lines

Test #37:

score: 0
Accepted
time: 69ms
memory: 25176kb

input:

100000 50000
3385 22602
15118 17374
25918 36726
25983 30341
38262 60763
50908 54723
71193 90454
77723 84223
96157 121101
97502 113730
124067 136828
131197 132858
144072 152682
149026 150819
153227 170907
158212 169128
175048 182925
180847 180992
189127 200462
192369 194079
207707 216404
207976 21429...

output:

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

ok 50000 lines

Test #38:

score: 0
Accepted
time: 68ms
memory: 24848kb

input:

100000 48000
3919 19928
6894 19295
26011 37935
30149 32523
46359 60844
48369 53998
62841 82568
70617 76333
86782 99607
93507 96845
109927 118141
111357 111996
118198 124460
120365 122508
135217 147445
136431 138035
148529 177957
148704 152131
196706 205108
198880 203741
208372 229413
211287 216823
2...

output:

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

ok 48000 lines

Test #39:

score: 0
Accepted
time: 59ms
memory: 24844kb

input:

100000 46000
7861 32751
22760 26494
39684 45851
40904 42267
51634 54991
51964 52209
56358 76070
67961 70798
77254 94033
78951 94032
98974 105914
99051 99360
110232 130179
120381 127849
132057 156356
133077 149316
160834 186236
161096 170777
198236 202006
201494 201958
204118 211402
207491 209514
214...

output:

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

ok 46000 lines

Test #40:

score: 0
Accepted
time: 62ms
memory: 24652kb

input:

100000 44000
354 15072
5536 14710
19678 32180
24230 27035
35679 49748
39329 41843
55851 66113
57846 62517
70107 82556
78170 81316
93880 106334
94742 101602
111770 140322
116978 123594
148941 157393
151851 154147
162583 191208
175952 186995
193692 209083
197078 207122
216756 226820
220611 221173
2355...

output:

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

ok 44000 lines

Test #41:

score: 0
Accepted
time: 68ms
memory: 24572kb

input:

100000 42000
134 25412
10249 13603
30598 45694
31946 40951
48198 63861
54201 57603
65107 91885
67263 75648
94096 106664
100707 102011
108972 123744
111181 123208
124630 135088
130963 133544
140847 153932
151528 153069
154469 165953
160640 160969
166427 183054
166990 173221
187899 206409
193568 19497...

output:

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

ok 42000 lines

Test #42:

score: 0
Accepted
time: 45ms
memory: 16572kb

input:

100000 50000
1009 11588
3172 7775
19428 37428
22241 27726
51939 57615
53942 56298
58145 60885
58411 60432
61299 76501
63967 71739
85978 91923
87118 88018
94158 118616
97458 98978
118969 145953
134410 143683
156177 175586
158124 168302
177242 200968
184735 195759
201230 229057
204144 209556
231440 23...

output:

-1

result:

ok single line: '-1'

Test #43:

score: -7
Wrong Answer
time: 82ms
memory: 24596kb

input:

100000 48000
8719 22716
12838 18758
25031 34662
27255 29644
36275 45579
37805 44405
46705 65627
48769 55749
67561 94228
69548 92389
96929 126085
102443 123805
141386 149872
142704 147965
152130 158469
155481 157837
163047 172760
164879 169722
175291 191106
176879 189992
191715 193629
193209 193221
1...

output:

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
64
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

wrong answer 20717th lines differ - expected: '44446', found: '44445'

Subtask #2:

score: 0
Wrong Answer

Test #47:

score: 1
Accepted
time: 1ms
memory: 3920kb

input:

1 1
134842099 137944073

output:

1

result:

ok single line: '1'

Test #48:

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

input:

2 2
4015595 884953730
519508315 726912949

output:

-1

result:

ok single line: '-1'

Test #49:

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

input:

3 2
551691302 800582045
14063803 52897269
153641504 567834643

output:

1
2

result:

ok 2 lines

Test #50:

score: 0
Accepted
time: 0ms
memory: 5992kb

input:

18 3
157893686 958635898
790021767 976682032
534783017 706987897
216566011 510148270
288661613 856715472
81126924 420966670
9734253 823219818
77427078 241270378
182953794 928971032
65710916 937359407
159217847 343023570
266169092 635952191
94867522 407392584
298640819 490028599
281580042 514089998
6...

output:

2
3
4

result:

ok 3 lines

Test #51:

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

input:

19 3
345121760 363569961
369142474 697961114
204455374 777512357
278051598 780834857
119744682 610142516
112692534 284271720
530820418 613805256
666599238 970772442
684066330 747151742
52464000 153949333
361766230 921325388
34600363 168745634
119418778 738281466
828841976 976561834
257913352 2579536...

output:

1
2
6

result:

ok 3 lines

Test #52:

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

input:

20 3
226617517 417144410
401110226 504506272
204308913 972565478
100780114 930332684
473716139 730386187
327436800 871728821
662616072 881801440
469971234 769277127
437331467 913865677
641546412 700063729
82089639 830256714
384651823 502387376
558881974 905373190
468189379 998408858
9103683 60217281...

output:

1
7
18

result:

ok 3 lines

Test #53:

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

input:

20 5
715591101 817706977
777008847 930020190
379125190 717746290
308826535 651449374
799848635 899870053
173402733 393191194
565584335 789226348
291163241 758381981
249473019 374801668
294956234 880404922
451362750 913870571
98855617 246302398
339866606 382702111
293058132 409201146
478015003 708631...

output:

1
9
12
15
19

result:

ok 5 lines

Test #54:

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

input:

20 4
95564966 475651640
544140915 921414489
36636943 545028649
269212181 518161723
368415853 600482753
416749483 825099524
704848425 946709199
145082659 465308089
751497619 765279722
452763328 557958381
643817392 876292284
353226095 933184330
466610247 590597228
29324927 65589713
155598093 306733984...

output:

5
7
14
15

result:

ok 4 lines

Test #55:

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

input:

20 2
341059917 968468550
619575412 657744605
362725213 784431788
79002877 857963719
636336680 943339572
282572479 300370019
213849085 706084423
315706132 851874320
740367416 998763448
113510482 521411850
198080835 487564765
29193064 86493364
488295690 701227663
351650597 899167999
437802529 73566590...

output:

1
6

result:

ok 2 lines

Test #56:

score: 0
Accepted
time: 0ms
memory: 8052kb

input:

20 1
827468447 879951302
735432164 759558988
269959865 944012171
67243577 84278317
805433568 936534843
171608293 591686301
112362102 822334845
410116008 619648090
306041507 327894522
360193096 488922828
417005225 834550228
872712520 873151446
472785468 800113380
39268216 894210474
600856133 91169444...

output:

1

result:

ok single line: '1'

Test #57:

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

input:

20 9
18246520 289037312
223590378 904221984
158468076 685664873
661343077 978347160
435186112 640627800
559466880 559927584
45242916 566596015
130290765 300200349
175183463 434730463
75064355 595211002
333621902 449961207
28044312 78011568
267319532 981800089
579543582 623250773
501315035 549454467
...

output:

-1

result:

ok single line: '-1'

Test #58:

score: -1
Wrong Answer
time: 1ms
memory: 6132kb

input:

20 4
282915225 425599000
46844071 877724908
331562754 774194013
454952275 729482745
26829711 957331160
627282472 841455868
100114358 781547255
150014807 274089000
534690006 980470663
541821180 599376720
84150518 232318480
4457533 168338098
28542916 343576455
94961278 964757965
1021672 802156769
1412...

output:

1
4
8
0

result:

wrong answer 2nd lines differ - expected: '6', found: '4'

Subtask #3:

score: 0
Wrong Answer

Test #74:

score: 0
Wrong Answer
time: 0ms
memory: 8500kb

input:

3000 57
226083340 261990234
392684356 462929590
468018811 841719892
495096853 606046097
196983814 256423598
331199122 967656486
802593662 931108452
74501453 679054962
294344294 752837262
295708332 547261648
265421699 652708933
272959087 727136240
165667761 846917534
61770748 157663302
608516043 8492...

output:

50
54
56
57
59
65
85
100
224
228
237
327
347
683
766
811
906
1416
1676
1774
2608
0
0
0
0
0
0
0
0
0
0
0
0
0
49
0
0
0
1880417312
22007
0
0
0
0
906
0
49
0
0
0
1880417312
22007
0
0
0
0
1416

result:

wrong answer 2nd lines differ - expected: '85', found: '54'

Subtask #4:

score: 0
Wrong Answer

Test #111:

score: 0
Wrong Answer
time: 99ms
memory: 22060kb

input:

100000 361
136798318 785362988
255943758 535488232
175203444 266819907
766993466 893575347
67274251 589651108
662289594 883406317
830803801 849703610
729398668 798198453
202605534 677648797
66407931 925909114
174421361 601553812
522629146 701284080
136544340 295925673
299796891 499869765
736583725 8...

output:

42
48
51
52
67
141
215
243
244
279
422
444
499
505
693
728
797
954
1281
1705
2088
4536
6365
6708
7064
7833
8092
10265
13019
13838
16475
18225
19119
21126
21320
24929
28849
32026
33446
37422
51281
54071
73408
77416
95210
98060
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
49
0
0
0
-648751152
21976
0
0
0
0
...

result:

wrong answer 2nd lines differ - expected: '102', found: '48'