QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#857893#2710. Bread First SearchHuTao#25 ✓99ms17460kbC++141.9kb2025-01-16 09:17:332025-01-16 09:17:39

Judging History

This is the latest submission verdict.

  • [2025-01-16 09:17:39]
  • Judged
  • Verdict: 25
  • Time: 99ms
  • Memory: 17460kb
  • [2025-01-16 09:17:33]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5, INF = 0x3f3f3f3f;

int n, m;
int g[N], mn[N];
int f[N], cnt[N];

struct Node{
    int a, b;
    int v, t;
}t[N * 4];

#define ls (u << 1)
#define rs (u << 1 | 1)
inline void PushUp(int u)
{
    t[u].v = min(t[ls].v, t[rs].v);
}
inline void Change(int u, int d)
{
    t[u].v += d, t[u].t += d;
}
inline void PushDown(int u)
{
    if(t[u].t)
    {
        Change(ls, t[u].t);
        Change(rs, t[u].t);
        t[u].t = 0;
    }
}
inline void Build(int u, int a, int b)
{
    t[u].a = a, t[u].b = b;
    if(a != b)
    {
        int mid = (a + b) >> 1;
        Build(ls, a, mid);
        Build(rs, mid + 1, b);
    }
}
inline void Modify(int u, int x, int y, int d)
{
    if(x <= t[u].a && t[u].b <= y) return Change(u, d);
    PushDown(u);
    if(t[ls].b >= x) Modify(ls, x, y, d);
    if(t[rs].a <= y) Modify(rs, x, y, d);
    PushUp(u);
}
inline int Query(int u, int x, int y)
{
    if(x <= t[u].a && t[u].b <= y) return t[u].v;
    PushDown(u);
    int res = INF;
    if(t[ls].b >= x) res = min(res, Query(ls, x, y));
    if(t[rs].a <= y) res = min(res, Query(rs, x, y));
    return res;
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i ++ ) g[i] = i;
    for(int i = 1; i <= m; i ++ )
    {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a] = min(g[a], b);
        g[b] = min(g[b], a);
    }
    mn[n + 1] = n + 1;
    for(int i = n; i >= 1; i -- ) mn[i] = min(mn[i + 1], g[i]);
    Build(1, 1, n);
    for(int i = 2; i <= n; i ++ )
    {
        if(g[i] > 1) Modify(1, 1, g[i] - 1, 1);
        if(mn[i + 1] == 1)
        {
            f[i] = INF;
            Modify(1, i, i, INF);
            continue;
        }
        f[i] = Query(1, 1, min(i - 1, mn[i + 1] - 1));
        Modify(1, i, i, f[i]);
    }
    printf("%d\n", f[n]);
    return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

2 0

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 1ms
memory: 5976kb

input:

6 3
1 3
2 6
4 5

output:

2

result:

ok single line: '2'

Test #3:

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

input:

200 0

output:

199

result:

ok single line: '199'

Test #4:

score: 5
Accepted
time: 1ms
memory: 5976kb

input:

200 10
109 114
7 2
44 50
153 146
38 41
4 14
156 168
15 25
165 177
198 193

output:

189

result:

ok single line: '189'

Test #5:

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

input:

200 435
148 140
128 127
115 117
78 80
37 39
191 182
132 131
84 80
23 19
34 35
153 155
183 184
152 165
49 48
132 126
30 41
122 121
16 11
117 110
26 27
132 139
197 191
62 64
118 120
193 196
41 42
157 165
40 41
105 94
84 86
83 82
104 111
8 10
6 13
118 126
93 94
92 85
197 116
27 40
190 188
129 138
99 95...

output:

121

result:

ok single line: '121'

Test #6:

score: 5
Accepted
time: 1ms
memory: 5972kb

input:

200 426
106 108
95 97
23 19
109 122
166 165
133 128
108 109
125 121
62 63
117 116
13 5
110 111
194 195
86 75
58 54
22 8
10 4
29 30
73 68
72 63
56 58
19 20
129 126
22 23
128 132
171 173
40 48
107 109
39 42
176 173
181 176
127 122
114 104
146 147
48 42
119 123
140 128
13 11
83 82
94 100
188 185
22 20
...

output:

107

result:

ok single line: '107'

Test #7:

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

input:

200 358
64 58
159 158
100 92
178 177
37 38
111 112
103 105
8 20
138 139
103 112
51 39
131 138
114 115
1 4
124 110
2 5
49 52
69 68
6 4
154 153
23 19
44 56
152 151
188 192
180 183
101 104
136 134
30 32
95 102
173 170
13 15
98 104
34 25
168 169
172 182
183 182
54 56
118 109
19 22
18 20
169 163
53 54
1 ...

output:

120

result:

ok single line: '120'

Test #8:

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

input:

200 347
89 86
125 127
148 149
91 92
178 175
179 171
103 104
59 61
67 66
115 114
200 199
90 89
71 69
10 11
6 5
14 15
163 157
27 24
31 38
16 18
68 66
198 194
144 146
158 159
19 18
163 176
7 5
48 43
57 60
172 171
7 8
3 8
125 128
171 174
146 145
133 131
194 199
19 21
59 58
110 113
100 95
62 75
147 151
9...

output:

102

result:

ok single line: '102'

Test #9:

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

input:

200 100
103 118
128 149
174 116
74 40
112 57
28 22
119 96
84 125
40 86
44 63
25 35
60 1
132 151
44 134
51 87
66 3
166 179
13 81
55 50
28 56
5 14
5 47
11 58
103 41
35 121
104 60
50 61
39 5
36 41
44 62
59 43
61 138
86 181
28 122
157 84
164 70
175 166
13 20
88 167
131 187
8 50
2 21
25 5
183 165
180 108...

output:

149

result:

ok single line: '149'

Test #10:

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

input:

200 895
106 43
195 198
31 32
38 35
87 54
28 9
125 147
138 106
38 127
196 184
199 168
107 25
149 143
32 21
188 189
85 88
90 103
79 78
126 125
103 89
92 2
192 193
150 153
95 93
62 22
60 53
186 175
133 143
123 124
45 42
9 14
199 198
12 22
128 142
62 61
22 23
6 10
156 153
140 172
82 103
93 94
151 125
12...

output:

97

result:

ok single line: '97'

Test #11:

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

input:

200 888
128 129
164 191
184 186
144 151
171 144
21 5
148 168
181 182
155 160
69 81
178 147
16 46
61 14
175 180
148 152
30 24
170 163
19 18
118 119
115 116
48 45
147 152
53 72
81 77
177 176
156 90
73 65
53 103
50 40
147 114
43 46
38 37
177 171
169 173
104 106
186 162
130 128
172 170
175 170
118 194
1...

output:

117

result:

ok single line: '117'

Subtask #2:

score: 6
Accepted

Dependency #1:

100%
Accepted

Test #12:

score: 6
Accepted
time: 1ms
memory: 8240kb

input:

5000 0

output:

4999

result:

ok single line: '4999'

Test #13:

score: 6
Accepted
time: 1ms
memory: 8272kb

input:

5000 100
3510 3521
4132 4109
4724 4662
3571 3521
4386 4356
2280 2310
2827 2836
3262 3309
2103 2105
3719 3731
3836 3820
3032 3101
1021 1001
259 299
2071 2031
106 153
792 723
3770 3715
2119 2168
1207 1218
1124 1148
2548 2584
722 710
1837 1770
680 637
1389 1418
1484 1432
3635 3596
3239 3206
1337 1330
3...

output:

4899

result:

ok single line: '4899'

Test #14:

score: 6
Accepted
time: 2ms
memory: 6096kb

input:

5000 16161
4949 4946
2876 2888
1633 1635
3721 3722
3483 3476
2647 2614
3242 3241
1495 1452
4010 4008
926 927
2503 2510
158 121
2417 2475
1720 1710
3999 4013
3129 3128
1972 1970
545 543
3681 3684
444 466
1097 1100
1309 1310
1119 1122
1668 1619
3569 3636
4808 4810
1382 1381
4418 4420
294 344
978 984
1...

output:

4032

result:

ok single line: '4032'

Test #15:

score: 6
Accepted
time: 3ms
memory: 8264kb

input:

5000 15410
1545 1543
4578 4577
4808 4815
4015 4018
3089 3109
985 995
260 263
3910 3914
2649 2653
3858 3891
1096 1121
3034 3007
3316 3296
3598 3597
974 978
1820 1877
1410 1411
4316 4259
3245 3247
4918 4917
2040 2058
1747 1718
441 447
1661 1672
1889 1824
4780 4719
892 891
4816 4817
1488 1489
2856 2857...

output:

3811

result:

ok single line: '3811'

Test #16:

score: 6
Accepted
time: 3ms
memory: 6228kb

input:

5000 15922
2708 2714
2553 2555
3098 3091
3516 3542
3018 3009
558 521
3772 3717
3680 3671
391 422
4053 4058
3635 3643
1089 1081
245 256
1774 1830
3463 3471
1715 1691
3500 3499
1190 1176
3559 3567
1843 1840
487 489
4359 4393
4498 4501
4064 4080
4124 4123
453 456
3947 3952
1426 1429
1552 1557
4421 4365...

output:

3207

result:

ok single line: '3207'

Test #17:

score: 6
Accepted
time: 2ms
memory: 6248kb

input:

5000 15530
780 782
3347 3321
1349 1343
4236 4237
3282 3286
1992 1991
3063 3064
772 771
391 397
1613 1609
412 381
1245 1250
3886 3885
1353 1355
3091 3088
1389 1352
4061 4001
3218 3203
66 46
1808 1826
2779 2766
1233 1215
3890 3896
4649 4657
3832 3834
441 440
3817 3816
2121 2117
1301 1302
2501 2519
281...

output:

3371

result:

ok single line: '3371'

Test #18:

score: 6
Accepted
time: 2ms
memory: 8080kb

input:

5000 2500
2438 2122
2517 1218
266 715
3405 969
2154 1633
1645 1496
569 257
316 478
3929 3002
1356 485
2436 4339
1072 2445
4083 1924
2836 2397
3620 4802
2295 3680
1511 769
39 1466
1315 1506
2802 3280
2887 1170
1500 339
1669 1121
4635 2614
2285 758
944 3105
3834 2911
160 923
4023 3256
430 1549
2833 33...

output:

4192

result:

ok single line: '4192'

Test #19:

score: 6
Accepted
time: 6ms
memory: 6224kb

input:

5000 39482
1134 1135
3471 3477
2837 2633
2622 2316
3496 3491
1812 1714
1428 1453
3115 3117
827 1217
3891 3887
2734 2730
2841 2441
3328 3332
208 245
70 1666
911 783
590 586
4563 4551
1937 2862
2828 2829
2709 2686
2661 2667
3446 2716
449 448
887 344
2360 2750
4442 4440
322 1373
1187 1166
755 751
3211 ...

output:

2854

result:

ok single line: '2854'

Test #20:

score: 6
Accepted
time: 4ms
memory: 6068kb

input:

5000 39422
1548 1375
2264 2263
362 353
4649 4635
4419 4418
502 418
3875 3514
1664 1665
4619 4620
1265 1277
972 970
670 1101
823 884
4634 2974
846 845
4974 4964
4670 4674
3076 3197
1092 1089
532 853
2235 2491
4438 4434
1072 1071
3191 3197
3693 4112
910 867
2259 2070
318 304
1640 1639
4047 4048
929 93...

output:

2786

result:

ok single line: '2786'

Subtask #3:

score: 14
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #21:

score: 14
Accepted
time: 61ms
memory: 17428kb

input:

200000 0

output:

199999

result:

ok single line: '199999'

Test #22:

score: 14
Accepted
time: 56ms
memory: 17452kb

input:

200000 6000
180958 181024
38186 37963
77704 77927
54141 54065
134310 134062
44768 44732
96437 96183
71999 72208
160621 160484
162439 162715
163226 163186
32473 32219
35520 35565
110599 110156
109071 109079
147799 147982
75884 75576
178827 179181
64669 64616
150228 149879
20821 20565
175586 175582
17...

output:

195379

result:

ok single line: '195379'

Test #23:

score: 14
Accepted
time: 65ms
memory: 17092kb

input:

150000 200000
119473 119090
119356 119588
30011 29903
11820 11616
139365 139415
55150 54787
1127 899
113654 113834
60887 60842
36463 36253
104848 105026
19976 19669
88487 88784
18236 17945
32271 32291
47429 47611
96009 96033
112092 112191
123433 123361
118466 118407
115975 115990
133233 133261
13170...

output:

122427

result:

ok single line: '122427'

Test #24:

score: 14
Accepted
time: 84ms
memory: 17452kb

input:

200000 200000
161362 161660
4222 4007
188462 188889
80569 80376
54994 54574
179796 180145
169225 168833
32930 32624
9598 9676
45091 45179
73653 73982
18885 19296
127571 127585
45386 44953
127922 128034
127062 127078
178228 178096
113601 113764
98858 99070
129784 129690
198365 198341
102400 102410
11...

output:

172796

result:

ok single line: '172796'

Test #25:

score: 14
Accepted
time: 83ms
memory: 17180kb

input:

200000 200000
133428 133699
176677 176362
12772 12840
54900 54901
185644 186004
55132 55339
37635 37264
131614 131258
125674 125793
170674 170676
21894 21592
120156 120303
20995 21280
135328 135390
156874 156780
15444 15276
88955 88818
177777 177901
153772 153371
93681 93474
157125 156893
153836 153...

output:

162595

result:

ok single line: '162595'

Test #26:

score: 14
Accepted
time: 84ms
memory: 15400kb

input:

200000 200000
70573 70941
129825 129781
125504 125797
116328 116358
65001 64991
86971 87172
50566 50549
82121 81715
197100 197075
27040 26883
85548 85567
49264 49287
20854 21082
41164 41163
180506 180642
77393 77078
8775 9186
66659 66828
54656 54336
39372 39012
107748 107789
42414 42694
3843 3481
18...

output:

151360

result:

ok single line: '151360'

Test #27:

score: 14
Accepted
time: 56ms
memory: 17460kb

input:

200000 100
105306 14333
157291 119839
115315 189213
79257 47583
6040 69441
130802 110050
47914 19516
60802 104978
195741 125477
190603 189750
174615 84442
94393 22504
152122 122563
105008 150843
89733 2660
118419 160122
185177 194578
9385 21874
71215 130030
145690 96013
113795 138331
39703 58
15134 ...

output:

199940

result:

ok single line: '199940'

Test #28:

score: 14
Accepted
time: 60ms
memory: 17404kb

input:

200000 6000
8569 21852
151872 114718
124881 180094
2698 1552
1231 30131
31786 50614
57613 32318
32328 60653
117167 105512
1272 719
115516 188508
2277 292
136534 65931
75434 7261
51185 24345
1690 29177
165077 196847
1192 42332
141105 157520
68762 126208
95447 124676
139247 194887
4020 74852
92014 121...

output:

197330

result:

ok single line: '197330'

Test #29:

score: 14
Accepted
time: 42ms
memory: 12364kb

input:

100000 100000
67727 82149
20500 54795
65206 47464
76780 99582
39237 39951
8708 7144
57016 72518
37417 964
5590 8427
29406 22770
75560 69058
89087 98466
88996 79253
45726 56875
93810 66539
80947 38004
27460 25184
29297 54474
68780 99870
16924 21430
4846 7969
94578 85978
61480 28057
3302 31105
18258 6...

output:

70427

result:

ok single line: '70427'

Test #30:

score: 14
Accepted
time: 77ms
memory: 16804kb

input:

150000 200000
83428 104490
20603 39678
67626 20849
12673 29723
30926 2619
831 1015
149374 137521
141708 140615
4499 50053
49544 32971
10956 46803
1335 4979
52207 94382
83651 25220
748 3355
21351 21688
58614 53520
34953 100269
119551 105422
23486 16310
28739 28912
19187 93625
12774 4037
1 8454
24440 ...

output:

85777

result:

ok single line: '85777'

Test #31:

score: 14
Accepted
time: 99ms
memory: 17416kb

input:

200000 200000
115239 152869
113905 105000
84651 9210
127216 132284
977 206
104982 179068
12217 7594
8562 77586
134323 81307
82568 84186
90 6401
169074 115105
94340 102058
5128 57021
32825 27565
152093 176641
71594 53498
813 31955
157233 101109
164733 87473
16019 20006
6246 6958
3081 26662
60678 5548...

output:

112959

result:

ok single line: '112959'

Test #32:

score: 14
Accepted
time: 98ms
memory: 17396kb

input:

200000 200000
152983 156971
18421 28013
39441 46225
15908 83517
58866 63317
89031 127201
125508 199088
29742 44453
28047 46364
27214 747
99080 173404
147186 74813
41361 56767
7054 67206
184982 138854
190734 176443
190904 152279
3497 1141
39304 83525
24964 78831
12091 10529
105225 43687
97136 22734
1...

output:

113161

result:

ok single line: '113161'

Extra Test:

score: 0
Extra Test Passed