Submission #930540

# Submission time Handle Problem Language Result Execution time Memory
930540 2024-02-20T05:54:42 Z Ghulam_Junaid Joker (BOI20_joker) C++17
39 / 100
2000 ms 211884 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 3;
int n, m, q, vis_nq[N], par[N], col[N];
vector<pair<int, int>> g[N], atl[N];
pair<int, int> edge[N];
vector<int> S[N];
bool ans[N];

int root(int v){
    return (par[v] == -1 ? v : root(par[v]));
}

inline bool merge(int u, int v){
    int r1 = root(u);
    int r2 = root(v);

    if (r1 == r2)
        return (col[u] != col[v]);

    if (S[r2].size() > S[r1].size())
        swap(r1, r2);
    par[r2] = r1;

    int take = 0;
    if (col[u] == col[v])
        take = 3;

    for (int x : S[r2]){
        col[x] ^= take;
        S[r1].push_back(x);
    }
    S[r2].clear();
    return 1;
}

int main(){
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= m; i ++){
        int u, v;
        scanf("%d%d", &u, &v);

        g[u].push_back({i, v});
        g[v].push_back({i, u});
        edge[i] = {u, v};
    }

    int mx = 0;
    for (int i = 0; i < q; i ++){
        int l, r;
        scanf("%d%d", &l, &r);
        mx = max(mx, l);
        atl[l].push_back({r, i});
    }

    for (int i = 1; i <= m; i ++){
        sort(atl[i].begin(), atl[i].end());
        reverse(atl[i].begin(), atl[i].end());
    }

    for (int i = 1; i <= mx; i ++){
        if (atl[i].size() == 0) continue;

        for (int j = 1; j <= n; j ++){
            S[j] = {j};
            par[j] = -1;
            col[j] = 1;
        }

        bool even = 1;
        for (int j = 1; j < i; j ++)
            even &= merge(edge[j].first, edge[j].second);

        int x = m;
        for (auto [r, id] : atl[i]){
            for (int j = r + 1; j <= x; j ++)
                even &= merge(edge[j].first, edge[j].second);
            x = r;

            if (even)
                ans[id] = 0;
            else
                ans[id] = 1;
        }
    }

    for (int i = 0; i < q; i ++){
        if (ans[i])
            printf("YES\n");
        else
            printf("NO\n");
    }
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
Joker.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%d%d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16728 KB Output is correct
2 Correct 5 ms 16732 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 5 ms 16728 KB Output is correct
5 Correct 4 ms 16728 KB Output is correct
6 Correct 4 ms 16728 KB Output is correct
7 Correct 5 ms 16732 KB Output is correct
8 Correct 5 ms 16856 KB Output is correct
9 Correct 5 ms 16732 KB Output is correct
10 Correct 6 ms 16988 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16732 KB Output is correct
14 Correct 4 ms 16984 KB Output is correct
15 Correct 5 ms 16728 KB Output is correct
16 Correct 5 ms 16732 KB Output is correct
17 Correct 5 ms 16888 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 5 ms 16732 KB Output is correct
20 Correct 4 ms 16732 KB Output is correct
21 Correct 6 ms 16732 KB Output is correct
22 Correct 5 ms 16732 KB Output is correct
23 Correct 4 ms 16732 KB Output is correct
24 Correct 5 ms 16732 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16884 KB Output is correct
27 Correct 4 ms 16728 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16728 KB Output is correct
2 Correct 5 ms 16732 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 5 ms 16728 KB Output is correct
5 Correct 4 ms 16728 KB Output is correct
6 Correct 4 ms 16728 KB Output is correct
7 Correct 5 ms 16732 KB Output is correct
8 Correct 5 ms 16856 KB Output is correct
9 Correct 5 ms 16732 KB Output is correct
10 Correct 6 ms 16988 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16732 KB Output is correct
14 Correct 4 ms 16984 KB Output is correct
15 Correct 5 ms 16728 KB Output is correct
16 Correct 5 ms 16732 KB Output is correct
17 Correct 5 ms 16888 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 5 ms 16732 KB Output is correct
20 Correct 4 ms 16732 KB Output is correct
21 Correct 6 ms 16732 KB Output is correct
22 Correct 5 ms 16732 KB Output is correct
23 Correct 4 ms 16732 KB Output is correct
24 Correct 5 ms 16732 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16884 KB Output is correct
27 Correct 4 ms 16728 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 23 ms 17044 KB Output is correct
30 Correct 39 ms 17236 KB Output is correct
31 Correct 38 ms 17240 KB Output is correct
32 Correct 28 ms 17184 KB Output is correct
33 Correct 22 ms 16988 KB Output is correct
34 Correct 43 ms 17388 KB Output is correct
35 Correct 43 ms 17440 KB Output is correct
36 Correct 23 ms 17244 KB Output is correct
37 Correct 44 ms 19300 KB Output is correct
38 Correct 47 ms 18376 KB Output is correct
39 Correct 40 ms 17500 KB Output is correct
40 Correct 27 ms 16988 KB Output is correct
41 Correct 32 ms 17144 KB Output is correct
42 Correct 25 ms 16988 KB Output is correct
43 Correct 31 ms 16984 KB Output is correct
44 Correct 41 ms 17200 KB Output is correct
45 Correct 55 ms 17652 KB Output is correct
46 Correct 52 ms 17244 KB Output is correct
47 Correct 23 ms 16988 KB Output is correct
48 Correct 27 ms 16988 KB Output is correct
49 Correct 32 ms 17236 KB Output is correct
50 Correct 40 ms 17244 KB Output is correct
51 Correct 24 ms 16984 KB Output is correct
52 Correct 28 ms 16984 KB Output is correct
53 Correct 33 ms 17236 KB Output is correct
54 Correct 42 ms 17300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16728 KB Output is correct
2 Correct 5 ms 16732 KB Output is correct
3 Correct 108 ms 31464 KB Output is correct
4 Correct 160 ms 38772 KB Output is correct
5 Correct 153 ms 38324 KB Output is correct
6 Correct 126 ms 33564 KB Output is correct
7 Correct 137 ms 34540 KB Output is correct
8 Correct 119 ms 30720 KB Output is correct
9 Correct 136 ms 33016 KB Output is correct
10 Correct 183 ms 39104 KB Output is correct
11 Correct 129 ms 33500 KB Output is correct
12 Correct 150 ms 37948 KB Output is correct
13 Correct 104 ms 28860 KB Output is correct
14 Correct 116 ms 31168 KB Output is correct
15 Correct 137 ms 35772 KB Output is correct
16 Correct 171 ms 39452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16728 KB Output is correct
2 Correct 5 ms 16732 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 5 ms 16728 KB Output is correct
5 Correct 4 ms 16728 KB Output is correct
6 Correct 4 ms 16728 KB Output is correct
7 Correct 5 ms 16732 KB Output is correct
8 Correct 5 ms 16856 KB Output is correct
9 Correct 5 ms 16732 KB Output is correct
10 Correct 6 ms 16988 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16732 KB Output is correct
14 Correct 4 ms 16984 KB Output is correct
15 Correct 5 ms 16728 KB Output is correct
16 Correct 5 ms 16732 KB Output is correct
17 Correct 5 ms 16888 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 5 ms 16732 KB Output is correct
20 Correct 4 ms 16732 KB Output is correct
21 Correct 6 ms 16732 KB Output is correct
22 Correct 5 ms 16732 KB Output is correct
23 Correct 4 ms 16732 KB Output is correct
24 Correct 5 ms 16732 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16884 KB Output is correct
27 Correct 4 ms 16728 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 108 ms 31464 KB Output is correct
30 Correct 160 ms 38772 KB Output is correct
31 Correct 153 ms 38324 KB Output is correct
32 Correct 126 ms 33564 KB Output is correct
33 Correct 137 ms 34540 KB Output is correct
34 Correct 119 ms 30720 KB Output is correct
35 Correct 136 ms 33016 KB Output is correct
36 Correct 183 ms 39104 KB Output is correct
37 Correct 129 ms 33500 KB Output is correct
38 Correct 150 ms 37948 KB Output is correct
39 Correct 104 ms 28860 KB Output is correct
40 Correct 116 ms 31168 KB Output is correct
41 Correct 137 ms 35772 KB Output is correct
42 Correct 171 ms 39452 KB Output is correct
43 Correct 1956 ms 197028 KB Output is correct
44 Execution timed out 2017 ms 211884 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16728 KB Output is correct
2 Correct 5 ms 16732 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 5 ms 16728 KB Output is correct
5 Correct 4 ms 16728 KB Output is correct
6 Correct 4 ms 16728 KB Output is correct
7 Correct 5 ms 16732 KB Output is correct
8 Correct 5 ms 16856 KB Output is correct
9 Correct 5 ms 16732 KB Output is correct
10 Correct 6 ms 16988 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16732 KB Output is correct
14 Correct 4 ms 16984 KB Output is correct
15 Correct 5 ms 16728 KB Output is correct
16 Correct 5 ms 16732 KB Output is correct
17 Correct 5 ms 16888 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 5 ms 16732 KB Output is correct
20 Correct 4 ms 16732 KB Output is correct
21 Correct 6 ms 16732 KB Output is correct
22 Correct 5 ms 16732 KB Output is correct
23 Correct 4 ms 16732 KB Output is correct
24 Correct 5 ms 16732 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16884 KB Output is correct
27 Correct 4 ms 16728 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 23 ms 17044 KB Output is correct
30 Correct 39 ms 17236 KB Output is correct
31 Correct 38 ms 17240 KB Output is correct
32 Correct 28 ms 17184 KB Output is correct
33 Correct 22 ms 16988 KB Output is correct
34 Correct 43 ms 17388 KB Output is correct
35 Correct 43 ms 17440 KB Output is correct
36 Correct 23 ms 17244 KB Output is correct
37 Correct 44 ms 19300 KB Output is correct
38 Correct 47 ms 18376 KB Output is correct
39 Correct 40 ms 17500 KB Output is correct
40 Correct 27 ms 16988 KB Output is correct
41 Correct 32 ms 17144 KB Output is correct
42 Correct 25 ms 16988 KB Output is correct
43 Correct 31 ms 16984 KB Output is correct
44 Correct 41 ms 17200 KB Output is correct
45 Correct 55 ms 17652 KB Output is correct
46 Correct 52 ms 17244 KB Output is correct
47 Correct 23 ms 16988 KB Output is correct
48 Correct 27 ms 16988 KB Output is correct
49 Correct 32 ms 17236 KB Output is correct
50 Correct 40 ms 17244 KB Output is correct
51 Correct 24 ms 16984 KB Output is correct
52 Correct 28 ms 16984 KB Output is correct
53 Correct 33 ms 17236 KB Output is correct
54 Correct 42 ms 17300 KB Output is correct
55 Execution timed out 2094 ms 190696 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16728 KB Output is correct
2 Correct 5 ms 16732 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 5 ms 16728 KB Output is correct
5 Correct 4 ms 16728 KB Output is correct
6 Correct 4 ms 16728 KB Output is correct
7 Correct 5 ms 16732 KB Output is correct
8 Correct 5 ms 16856 KB Output is correct
9 Correct 5 ms 16732 KB Output is correct
10 Correct 6 ms 16988 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 5 ms 16732 KB Output is correct
13 Correct 5 ms 16732 KB Output is correct
14 Correct 4 ms 16984 KB Output is correct
15 Correct 5 ms 16728 KB Output is correct
16 Correct 5 ms 16732 KB Output is correct
17 Correct 5 ms 16888 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 5 ms 16732 KB Output is correct
20 Correct 4 ms 16732 KB Output is correct
21 Correct 6 ms 16732 KB Output is correct
22 Correct 5 ms 16732 KB Output is correct
23 Correct 4 ms 16732 KB Output is correct
24 Correct 5 ms 16732 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 4 ms 16884 KB Output is correct
27 Correct 4 ms 16728 KB Output is correct
28 Correct 4 ms 16728 KB Output is correct
29 Correct 23 ms 17044 KB Output is correct
30 Correct 39 ms 17236 KB Output is correct
31 Correct 38 ms 17240 KB Output is correct
32 Correct 28 ms 17184 KB Output is correct
33 Correct 22 ms 16988 KB Output is correct
34 Correct 43 ms 17388 KB Output is correct
35 Correct 43 ms 17440 KB Output is correct
36 Correct 23 ms 17244 KB Output is correct
37 Correct 44 ms 19300 KB Output is correct
38 Correct 47 ms 18376 KB Output is correct
39 Correct 40 ms 17500 KB Output is correct
40 Correct 27 ms 16988 KB Output is correct
41 Correct 32 ms 17144 KB Output is correct
42 Correct 25 ms 16988 KB Output is correct
43 Correct 31 ms 16984 KB Output is correct
44 Correct 41 ms 17200 KB Output is correct
45 Correct 55 ms 17652 KB Output is correct
46 Correct 52 ms 17244 KB Output is correct
47 Correct 23 ms 16988 KB Output is correct
48 Correct 27 ms 16988 KB Output is correct
49 Correct 32 ms 17236 KB Output is correct
50 Correct 40 ms 17244 KB Output is correct
51 Correct 24 ms 16984 KB Output is correct
52 Correct 28 ms 16984 KB Output is correct
53 Correct 33 ms 17236 KB Output is correct
54 Correct 42 ms 17300 KB Output is correct
55 Correct 108 ms 31464 KB Output is correct
56 Correct 160 ms 38772 KB Output is correct
57 Correct 153 ms 38324 KB Output is correct
58 Correct 126 ms 33564 KB Output is correct
59 Correct 137 ms 34540 KB Output is correct
60 Correct 119 ms 30720 KB Output is correct
61 Correct 136 ms 33016 KB Output is correct
62 Correct 183 ms 39104 KB Output is correct
63 Correct 129 ms 33500 KB Output is correct
64 Correct 150 ms 37948 KB Output is correct
65 Correct 104 ms 28860 KB Output is correct
66 Correct 116 ms 31168 KB Output is correct
67 Correct 137 ms 35772 KB Output is correct
68 Correct 171 ms 39452 KB Output is correct
69 Correct 1956 ms 197028 KB Output is correct
70 Execution timed out 2017 ms 211884 KB Time limit exceeded
71 Halted 0 ms 0 KB -