QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418033#8672. 排队PYD110 42ms42536kbC++141.6kb2024-05-23 09:33:122024-05-23 09:33:16

Judging History

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

  • [2024-05-23 09:33:16]
  • 评测
  • 测评结果:10
  • 用时:42ms
  • 内存:42536kb
  • [2024-05-23 09:33:12]
  • 提交

answer

#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <time.h>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <stdio.h>
#include <iomanip>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mk make_pair
#define fi first
#define se second

inline int read(){
	int t = 0,f = 1;
	register char c = getchar();
	while (c < 48 || c > 57) f = (c == '-') ? (-1) : (f),c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return f * t;
}

const int N = 1e6 + 10;
int n,q,inl[N],inr[N],ans[N],val[N];

vector<pair<int,int> > qr[N];

void solve(){
	for (int l = n;l >= 1;l--){
		if (inl[l] == 0){
			int ad = 1;
			for (int i = l + 1;i <= n + 1;i++){
				val[i] += ad;
				if (val[i] > inr[i]){
					if (val[i] - ad <= inr[i] && val[i] - ad >= inl[i]) --ad;
				}else if (val[i] >= inl[i]){
					if (val[i] - ad < inl[i]) ++ad;
				}
				if (ad <= 0) break;
			}
		}
		for (auto q : qr[l]){
			ans[q.se] = val[q.fi + 1];
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	n = read(),q = read();
	for (int i = 1;i <= n;i++) inl[i] = read(),inr[i] = read();
	for (int i = 1;i <= q;i++){
		int l = read(),r = read();
		qr[l].emplace_back(mk(r,i));
	}
	solve();
	for (int i = 1;i <= q;i++) printf("%d\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 33688kb

input:

3 3
0 0
1 2
0 2
1 1
1 3
2 3

output:

1
3
1

result:

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

Test #2:

score: 0
Accepted
time: 6ms
memory: 35432kb

input:

5000 5000
5 10
3 9
3 8
2 7
2 5
3 6
1 5
0 2
7 8
2 10
0 3
3 6
4 6
1 6
4 8
7 8
2 7
3 4
4 9
7 8
2 9
2 5
3 6
0 5
6 7
1 2
2 4
2 10
1 5
7 9
6 9
2 3
9 10
5 5
2 9
3 3
2 7
2 4
0 6
0 3
1 7
7 7
4 8
2 9
4 8
0 10
1 8
1 1
2 7
5 9
1 7
1 7
1 4
2 4
1 4
2 9
1 7
4 7
3 8
1 3
4 6
1 5
1 6
0 0
3 9
4 7
2 8
1 8
1 2
7 8
2 7
2...

output:

11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
...

result:

ok 5000 numbers

Test #3:

score: 0
Accepted
time: 5ms
memory: 33860kb

input:

5000 5000
33 36
10 96
0 89
45 59
4 38
16 26
7 83
3 45
37 78
32 57
19 58
24 88
81 87
24 68
18 38
50 78
27 92
61 98
1 13
8 63
33 55
38 76
18 43
64 72
24 93
7 34
1 38
44 72
5 36
62 71
6 72
8 53
22 93
75 78
24 69
10 38
31 99
12 100
57 67
22 65
34 44
37 88
3 48
62 84
62 79
5 68
1 18
49 57
45 64
6 38
37 3...

output:

101
101
101
101
63
101
101
101
99
100
28
86
101
92
101
101
101
101
101
101
101
101
99
101
101
101
101
92
101
101
4
101
101
101
101
101
101
74
101
101
101
101
101
101
41
101
101
51
101
101
101
101
101
101
101
100
101
101
100
101
101
101
101
101
94
101
101
101
101
101
101
46
101
99
101
101
7
101
95
10...

result:

ok 5000 numbers

Test #4:

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

input:

5000 5000
332 468
241 278
90 259
397 412
212 317
55 238
173 296
176 184
67 260
51 95
117 184
37 276
122 441
226 401
43 244
127 186
34 493
38 221
3 4
67 122
45 486
5 91
64 158
74 394
134 188
229 265
155 422
221 403
176 252
28 98
94 250
133 133
107 281
13 347
154 209
203 271
12 325
33 318
181 220
27 2...

output:

500
11
490
491
501
2
7
490
468
140
501
494
215
1
499
186
494
483
495
483
0
85
31
1
345
492
24
0
443
24
1
500
484
466
501
498
500
496
0
89
396
1
84
324
500
491
436
471
436
430
484
185
358
367
484
488
38
332
13
0
411
28
498
501
498
307
55
258
101
376
139
455
299
501
119
20
501
14
500
501
273
291
1
107...

result:

ok 5000 numbers

Test #5:

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

input:

5000 5000
67 104
31 155
488 834
533 622
20 899
560 652
91 910
362 683
173 699
241 251
130 644
276 631
712 926
54 840
142 440
88 566
387 997
54 771
579 866
107 862
241 467
26 289
448 701
482 584
118 632
120 419
480 654
271 699
78 621
251 509
140 689
213 356
681 930
371 412
0 142
590 853
557 711
387 5...

output:

13
5
586
0
215
95
471
38
4
268
134
731
118
855
701
5
36
868
2
713
23
47
0
615
390
406
251
9
913
163
841
15
1
829
61
152
111
3
468
517
112
6
6
243
31
0
9
752
187
208
105
0
229
242
773
340
0
34
0
686
22
112
65
13
231
867
911
177
83
3
125
22
43
22
47
186
87
416
871
7
0
38
187
743
357
645
144
854
6
20
6...

result:

ok 5000 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 34516kb

input:

5000 5000
1484 3115
596 3914
2334 3936
2782 3399
176 1270
3695 4175
4185 4222
2165 2301
321 4460
33 35
679 1844
443 2424
292 520
796 995
1014 4510
1053 3456
589 4211
514 3195
449 4153
1314 4247
1388 1736
1301 2724
1555 1950
413 4176
3501 4606
396 1492
521 2047
125 3192
677 1709
317 1833
444 1562
120...

output:

0
1
2
0
1
0
0
0
0
0
0
1
2
1
0
1
0
0
0
2
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
3
0
0
0
0
0
0
0
0
0
1
0
0
0
3
1
2
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
1
0
2
0
0
0
0
0
0
0
0
0
0
3
0
0
1
0
0
0
0
0
2
0
2
2
0
2
2
3
0
0
0
0
0
2
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
2
0
0
0
0
0
2
0
0
0
0
0
0
0
0
1
...

result:

ok 5000 numbers

Test #7:

score: 0
Accepted
time: 3ms
memory: 34988kb

input:

5000 5000
0 33
0 96
0 89
0 59
0 4
0 16
0 83
0 3
0 78
0 57
0 58
0 88
0 81
0 68
0 38
0 50
0 92
0 98
0 1
0 63
0 55
0 76
0 43
0 64
0 93
0 34
0 1
0 72
0 5
0 71
0 72
0 8
0 93
0 78
0 69
0 10
0 99
0 100
0 57
0 65
0 44
0 88
0 48
0 84
0 79
0 68
0 1
0 49
0 45
0 6
0 37
0 27
0 50
0 57
0 94
0 89
0 78
0 83
0 74
0 ...

output:

101
101
101
101
91
101
101
101
99
100
90
97
101
98
101
101
101
101
101
101
101
101
101
101
101
101
101
97
101
101
74
101
101
101
101
101
101
98
101
101
101
101
101
101
86
101
101
82
101
101
101
101
101
101
101
100
101
101
101
101
101
101
101
101
96
101
101
101
101
101
101
96
101
101
101
101
69
101
1...

result:

ok 5000 numbers

Test #8:

score: 0
Accepted
time: 14ms
memory: 35228kb

input:

5000 5000
0 67
0 31
0 488
0 622
0 899
0 560
0 910
0 362
0 699
0 251
0 644
0 276
0 926
0 840
0 440
0 566
0 997
0 771
0 579
0 107
0 467
0 289
0 448
0 482
0 632
0 120
0 480
0 699
0 621
0 251
0 689
0 213
0 930
0 371
0 0
0 590
0 711
0 387
0 73
0 466
0 430
0 847
0 201
0 63
0 64
0 234
0 265
0 133
0 697
0 3...

output:

749
415
945
338
865
820
943
812
610
883
842
947
850
985
958
617
869
978
356
969
807
739
447
945
921
901
892
492
987
823
969
449
233
983
675
834
885
236
927
932
800
627
401
914
863
73
630
954
909
860
852
31
917
863
966
914
281
770
323
959
664
810
808
739
886
979
988
773
726
249
902
714
736
761
791
88...

result:

ok 5000 numbers

Test #9:

score: 0
Accepted
time: 19ms
memory: 33980kb

input:

5000 5000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 0
0 0
0 20
0 21
0 22
0 0
0 24
0 25
0 0
0 27
0 0
0 0
0 0
0 31
0 32
0 33
0 34
0 35
0 36
0 0
0 38
0 39
0 40
0 41
0 42
0 0
0 44
0 45
0 46
0 47
0 48
0 49
0 50
0 51
0 0
0 53
0 54
0 55
0 0
0 0
0 58
0 59
0 60
0 61
0 62
0...

output:

406
752
1297
49
190
3029
1175
1826
550
787
30
3676
1099
2402
929
2810
1655
931
172
3198
3561
2845
1688
1754
849
853
816
2603
2591
442
309
1545
211
434
368
1084
1355
1641
239
412
680
1830
421
1175
1950
3000
567
1912
2576
1674
223
2381
575
309
1763
1568
813
290
1187
1217
1381
448
910
1147
536
1058
833...

result:

ok 5000 numbers

Test #10:

score: 0
Accepted
time: 20ms
memory: 34020kb

input:

5000 5000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 0
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
0 31
0 32
0 33
0 34
0 35
0 36
0 37
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 47
0 0
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 58
0 59
0 60
...

output:

3044
1914
39
1760
154
2146
1494
2629
2354
494
1295
743
1203
1771
2288
755
1126
1008
2095
469
625
897
2206
2712
3357
3098
1488
364
1360
949
1680
2016
876
2110
1943
79
1796
2114
425
1082
2584
1384
2842
668
3879
510
1589
3110
3295
2984
1268
1399
1381
212
1626
1134
1029
4271
1227
1991
4006
873
1463
748
...

result:

ok 5000 numbers

Test #11:

score: 0
Accepted
time: 19ms
memory: 34960kb

input:

5000 5000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 0
0 0
0 20
0 21
0 22
0 0
0 24
0 25
0 0
0 27
0 0
0 0
0 0
0 31
0 32
0 33
0 34
0 35
0 36
0 0
0 38
0 39
0 40
0 41
0 42
0 0
0 44
0 45
0 46
0 47
0 48
0 49
0 50
0 51
0 0
0 53
0 54
0 55
0 0
0 0
0 58
0 59
0 60
0 61
0 62
0...

output:

2107
1855
3981
3461
1876
3487
2007
2882
3200
3851
2340
3687
3180
3603
2309
3727
4113
1187
196
3362
3819
3448
1765
2834
2470
2711
3443
4174
2923
1586
3779
4041
2075
1788
2375
1913
1991
2405
3176
3644
1457
1946
3752
3358
2150
3494
2273
2120
2999
3913
2110
3604
4062
1986
1877
2867
2910
3133
3677
2634
3...

result:

ok 5000 numbers

Subtask #2:

score: 0
Time Limit Exceeded

Test #12:

score: 15
Accepted
time: 32ms
memory: 35572kb

input:

200000 200000
3 6
3 3
6 10
1 7
2 7
6 9
4 6
3 4
0 8
0 6
3 5
3 4
1 8
7 8
4 5
0 3
1 5
2 9
1 2
1 2
3 4
5 7
6 10
3 9
4 7
1 6
2 6
1 7
2 5
1 7
6 8
1 1
0 7
7 8
0 9
1 7
3 8
3 7
1 2
4 8
5 6
0 6
5 6
2 7
2 6
0 6
0 6
1 7
2 5
0 3
0 3
7 10
3 8
0 2
3 4
3 7
4 9
0 6
4 7
2 6
8 10
2 10
4 10
3 3
2 6
4 5
3 9
1 8
1 2
2 9
...

output:

11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
...

result:

ok 200000 numbers

Test #13:

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

input:

200000 200000
5 45
27 99
7 23
51 88
16 62
10 24
16 80
43 70
12 45
35 55
6 99
77 91
40 82
66 99
30 47
18 80
9 36
4 12
26 51
37 64
39 52
2 11
2 69
57 81
15 98
8 36
19 27
32 34
35 97
22 23
15 89
53 77
2 89
25 55
25 90
4 91
13 77
37 65
67 89
8 52
20 58
10 18
31 81
35 59
41 56
71 74
18 61
56 77
51 74
40 ...

output:

101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
0
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
10...

result:

ok 200000 numbers

Test #14:

score: 0
Accepted
time: 26ms
memory: 42536kb

input:

200000 200000
193 894
142 229
346 553
197 496
389 718
370 600
650 853
476 695
764 767
220 571
238 714
516 700
137 692
1 293
835 962
34 536
208 482
148 225
377 804
75 864
277 925
278 864
296 647
390 757
179 283
338 602
571 746
447 852
315 365
7 390
634 689
76 239
16 60
244 388
385 822
451 836
301 373...

output:

1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
961
999
1001
1001
1001
1001
1001
1001
981
1001
1001
1001
1001
1001
1001
1001
966
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001
1001...

result:

ok 200000 numbers

Test #15:

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

input:

200000 200000
3145 7698
6037 6154
6483 6707
6834 7442
7373 9621
5166 8045
7346 8938
2235 5518
2240 4134
586 3188
3845 8054
1258 5380
2409 2631
3360 5706
19 2771
1925 9642
6687 8264
4305 8055
2844 5474
2282 7810
1738 4706
1462 7466
17 6282
2481 6022
2363 2987
3633 4157
1460 2634
4866 8159
3154 5079
2...

output:

9965
10001
0
10001
10001
10001
9991
10001
4831
9935
5274
10001
10001
2
10001
10001
10001
10001
9991
10001
10001
10001
10001
9935
9994
10001
9742
10001
10001
0
9982
10001
10001
10001
10001
10001
80
0
9991
9763
8
10001
9975
9939
10001
10001
9092
9983
9333
10001
10001
10001
10001
10001
10001
10001
9965...

result:

ok 200000 numbers

Test #16:

score: 0
Accepted
time: 40ms
memory: 40376kb

input:

200000 200000
15540 44932
12196 33126
776 23774
35673 42863
31231 44618
16521 19781
8467 9747
5319 42216
13940 21955
3389 6981
22 11576
15248 17307
5734 35942
12762 45217
30349 47977
8869 11242
11199 25942
3415 10196
20104 40771
8813 28517
29726 34188
13420 13731
17526 30474
1033 44930
3143 10541
46...

output:

8
31
33781
8
161
3
618
14580
3
25947
1415
455
2
147
16877
21598
539
56
7425
6686
4
393
4
4
4378
176
24
1407
837
19
14
7146
7
19626
21422
9
20472
0
200
3514
2
380
35942
35129
1
216
3
312
1200
2519
4046
9
1734
1318
21862
3361
27414
52
38201
2303
635
235
1
17
271
24468
29
1029
1071
38200
10968
95
4
125...

result:

ok 200000 numbers

Test #17:

score: -15
Time Limit Exceeded

input:

200000 200000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
0 31
0 32
0 33
0 34
0 35
0 36
0 37
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 47
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 58
0 59
...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

input:

200000 200000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 0
0 9
0 10
0 0
0 0
0 13
0 14
0 0
0 16
0 17
0 18
0 19
0 0
0 21
0 22
0 23
0 0
0 0
0 0
0 0
0 28
0 0
0 30
0 31
0 32
0 33
0 34
0 35
0 0
0 0
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 0
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 0
0 59
0 60
0 0
0 0
...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #32:

score: 0
Time Limit Exceeded

input:

200000 200000
0 200000
1 200000
1 200000
0 200000
0 200000
1 200000
1 200000
1 200000
0 200000
1 200000
0 200000
0 200000
1 200000
0 200000
0 200000
0 200000
0 200000
1 200000
0 200000
0 200000
1 200000
0 200000
1 200000
1 200000
1 200000
1 200000
0 200000
0 200000
1 200000
2 200000
1 200000
2 20000...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%