QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534219#121. Bitaro's Partyisirazeev7 620ms14148kbC++202.4kb2024-08-26 22:02:502024-08-26 22:02:50

Judging History

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

  • [2024-08-26 22:02:50]
  • 评测
  • 测评结果:7
  • 用时:620ms
  • 内存:14148kb
  • [2024-08-26 22:02:50]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = (int) 1e5 + 10;
const int C = 100;

const int INF = (int) 1e9;

set<pair<int, int>> biggest[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> rev_g[n];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        rev_g[v - 1].emplace_back(u - 1);
    }
    set<int> was;
    int dist[n];
    for (int i = 0; i < n; i++) dist[i] = 0;
    for (int i = 0; i < n; i++) {
        biggest[i].insert({0, i});
        was.clear();
        dist[i] = 0;
        was.insert(i);
        for (int j: rev_g[i]) {
            for (auto [c, ind]: biggest[j]) {
                if (was.find(ind) != was.end()) {
                    if (dist[ind] < c + 1) {
                        biggest[i].erase({dist[ind], ind});
                        dist[ind] = c + 1;
                        biggest[i].insert({c + 1, ind});
                    }
                } else {
                    biggest[i].insert({c + 1, ind});
                    was.insert(ind), dist[ind] = c + 1;
                }
                if ((int) biggest[i].size() > C) {
                    dist[biggest[i].begin()->second] = 0;
                    biggest[i].erase(biggest[i].begin());
                }
            }
        }
        for (auto [c, ind]: biggest[i]) dist[ind] = 0;
    }
    for (int _ = 0; _ < q; _++) {
        int T, Y;
        cin >> T >> Y;
        T--;
        set<int> block;
        for (int i = 0; i < Y; i++) {
            int A;
            cin >> A;
            block.insert(A - 1);
        }
        if (Y >= C) {
            int dp[n];
            for (int i = 0; i < n; i++) dp[i] = -INF;
            dp[T] = 0;
            for (int i = T; i >= 0; i--) {
                for (int j: rev_g[i])
                    dp[j] = max(dp[j], dp[i] + 1);
            }
            int res = -1;
            for (int i = 0; i < n; i++) if (block.find(i) == block.end()) res = max(res, dp[i]);
            cout << res << "\n";
            continue;
        } else {
            int res = -1;
            for (auto [val, ind]: biggest[T]) {
                if (block.find(ind) == block.end())
                    res = max(res, val);
            }
            cout << res << "\n";
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 0ms
memory: 8252kb

input:

1 0 1
1 0

output:

0

result:

ok single line: '0'

Test #2:

score: 7
Accepted
time: 2ms
memory: 8316kb

input:

1 0 1
1 1 1

output:

-1

result:

ok single line: '-1'

Test #3:

score: 7
Accepted
time: 2ms
memory: 8204kb

input:

2 1 1
1 2
1 2 1 2

output:

-1

result:

ok single line: '-1'

Test #4:

score: 7
Accepted
time: 0ms
memory: 8312kb

input:

2 1 1
1 2
1 1 1

output:

-1

result:

ok single line: '-1'

Test #5:

score: 7
Accepted
time: 7ms
memory: 10068kb

input:

1000 2000 1
66 427
211 505
213 674
56 131
180 883
127 167
228 262
42 50
386 688
346 943
170 396
127 150
169 192
253 706
96 497
141 277
317 711
792 802
244 469
24 702
135 252
31 764
52 95
701 900
473 832
510 691
14 474
158 488
422 491
228 897
318 622
195 548
479 626
525 728
53 109
133 854
392 416
34 ...

output:

12

result:

ok single line: '12'

Test #6:

score: 7
Accepted
time: 11ms
memory: 10128kb

input:

1000 2000 1
762 826
799 904
17 20
56 733
46 416
261 768
196 392
121 144
14 69
244 625
331 485
331 383
502 635
107 914
131 274
288 495
70 103
417 934
318 535
775 930
9 113
250 677
82 200
2 4
36 77
367 553
8 31
633 712
21 179
484 963
117 146
207 413
685 787
561 903
508 710
834 912
4 76
196 977
355 394...

output:

14

result:

ok single line: '14'

Test #7:

score: 7
Accepted
time: 11ms
memory: 9976kb

input:

1000 2000 1
86 222
107 710
207 983
80 929
4 5
685 963
758 769
228 274
34 35
14 26
614 786
383 679
41 62
125 522
619 851
175 359
253 492
127 182
27 367
111 221
170 453
519 612
137 191
254 301
53 148
214 824
31 374
402 795
25 26
177 461
301 614
574 798
82 104
137 625
86 575
32 364
37 183
131 270
113 6...

output:

2

result:

ok single line: '2'

Test #8:

score: 7
Accepted
time: 13ms
memory: 12796kb

input:

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

output:

181

result:

ok single line: '181'

Test #9:

score: 7
Accepted
time: 13ms
memory: 13060kb

input:

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

output:

627

result:

ok single line: '627'

Test #10:

score: 7
Accepted
time: 9ms
memory: 12808kb

input:

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

output:

72

result:

ok single line: '72'

Test #11:

score: 7
Accepted
time: 15ms
memory: 12620kb

input:

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

output:

9

result:

ok single line: '9'

Test #12:

score: 7
Accepted
time: 19ms
memory: 11576kb

input:

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

output:

11

result:

ok single line: '11'

Test #13:

score: 7
Accepted
time: 11ms
memory: 12852kb

input:

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

output:

-1

result:

ok single line: '-1'

Test #14:

score: 7
Accepted
time: 10ms
memory: 10972kb

input:

1000 2000 1
999 1000
998 1000
997 1000
996 1000
995 1000
994 1000
993 996
992 1000
991 994
990 992
989 996
988 998
987 995
986 990
985 991
984 985
983 987
982 988
981 984
980 988
979 987
978 980
977 981
976 986
975 976
974 983
973 975
972 981
971 972
970 974
969 970
968 972
967 969
966 972
965 968
9...

output:

-1

result:

ok single line: '-1'

Test #15:

score: 7
Accepted
time: 14ms
memory: 10172kb

input:

1000 2000 1
999 1000
998 1000
997 1000
996 1000
995 1000
994 1000
993 1000
992 1000
991 1000
990 1000
989 1000
988 1000
987 1000
986 998
985 1000
984 993
983 1000
982 1000
981 1000
980 988
979 1000
978 1000
977 1000
976 984
975 1000
974 1000
973 1000
972 1000
971 980
970 1000
969 989
968 1000
967 10...

output:

0

result:

ok single line: '0'

Test #16:

score: 7
Accepted
time: 15ms
memory: 10984kb

input:

1000 2000 1
999 1000
998 1000
997 1000
996 997
995 1000
994 998
993 1000
992 1000
991 992
990 992
989 994
988 996
987 993
986 990
985 995
984 991
983 991
982 992
981 982
980 986
979 981
978 984
977 981
976 986
975 979
974 981
973 981
972 982
971 980
970 979
969 972
968 970
967 970
966 975
965 969
96...

output:

165

result:

ok single line: '165'

Test #17:

score: 7
Accepted
time: 18ms
memory: 11824kb

input:

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

output:

74

result:

ok single line: '74'

Test #18:

score: 7
Accepted
time: 16ms
memory: 10704kb

input:

1000 2000 1
1 74
2 21
3 90
4 63
5 100
6 70
7 50
8 108
9 82
10 26
11 74
12 39
13 34
14 25
15 72
16 56
17 50
18 21
19 93
20 85
21 73
22 55
23 85
24 108
25 73
26 67
27 71
28 77
29 126
30 42
31 59
32 75
33 126
34 46
35 101
36 75
37 124
38 94
39 110
40 86
41 132
42 138
43 68
44 53
45 59
46 58
47 93
48 70...

output:

8

result:

ok single line: '8'

Test #19:

score: 7
Accepted
time: 18ms
memory: 11692kb

input:

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

output:

0

result:

ok single line: '0'

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #20:

score: 7
Accepted
time: 575ms
memory: 14148kb

input:

1000 200000 1
180 799
43 141
111 439
23 207
84 833
346 930
693 731
3 15
231 879
75 118
63 286
82 988
14 149
786 929
296 474
113 462
771 797
407 497
413 624
12 15
137 249
65 115
208 228
117 141
324 437
246 574
329 410
350 800
444 580
418 964
237 544
173 475
19 39
197 352
480 686
42 884
339 557
370 47...

output:

395

result:

ok single line: '395'

Test #21:

score: 7
Accepted
time: 278ms
memory: 13836kb

input:

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

output:

286

result:

ok single line: '286'

Test #22:

score: 7
Accepted
time: 596ms
memory: 14108kb

input:

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

output:

196

result:

ok single line: '196'

Test #23:

score: 7
Accepted
time: 620ms
memory: 13976kb

input:

1000 200000 1
999 1000
998 1000
997 1000
996 1000
995 1000
994 1000
993 1000
992 1000
991 1000
990 1000
989 1000
988 1000
987 1000
986 1000
985 1000
984 1000
983 1000
982 1000
981 1000
980 1000
979 1000
978 1000
977 1000
976 1000
975 1000
974 1000
973 1000
972 1000
971 1000
970 1000
969 1000
968 100...

output:

140

result:

ok single line: '140'

Test #24:

score: 0
Time Limit Exceeded

input:

100000 200000 1
33743 95024
2194 8454
5183 61615
1325 12578
20276 40081
41257 89273
3021 31316
13816 15631
6304 71909
35427 68479
1880 5185
14215 14875
11370 19817
67215 75366
6711 22104
57106 63907
14771 52069
37895 83415
25190 39472
2775 40247
9190 65004
50644 65994
3659 85855
31776 43448
6475 989...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%