Submission #561291

# Submission time Handle Problem Language Result Execution time Memory
561291 2022-05-12T15:20:12 Z messiuuuuu Joker (BOI20_joker) C++14
100 / 100
196 ms 12432 KB
#include<bits/stdc++.h>
#define task "F"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 2e5 + 5;
const ll INF = 1e18 + 5;

int n, m, q;
pair<int, int> es[MAXN];

void Input()
{
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++)
        cin >> es[i].fi >> es[i].se;
}

struct TRback
{
    int u, lu, v, lv;
};

stack<TRback> Q;

int lab[MAXN], f[MAXN];
bool pare[MAXN];

pair<int, int> FindSet(int u)
{
    bool w = 0;
    while (lab[u] > 0)
    {
        w ^= pare[u];
        u = lab[u];
    }
    return {u, w};
}

bool Unite(int u, int v)
{
    auto pu = FindSet(u);
    auto pv = FindSet(v);
    if (pu.fi == pv.fi)
    {
        return (pu.se != pv.se);
    }
    if (lab[pu.fi] > lab[pv.fi])
        swap(pu, pv);
    u = pu.fi;
    v = pv.fi;
    Q.push({u, lab[u], v, lab[v]});
    lab[u] += lab[v];
    lab[v] = u;
    pare[v] = pu.se ^ pv.se ^ 1;
    return 1;
}

void rollback(int sz)
{
    while (Q.size() > sz)
    {
        auto p = Q.top();
        Q.pop();
        lab[p.u] = p.lu;
        lab[p.v] = p.lv;
    }
}

void Dnc(int l, int r, int pl, int pr)
{
    if (l > r)
        return;
    int mid = (l + r) / 2;
    int s = Q.size();
    bool kt = 1;
    for (int i = l; i <= mid; i++)
    {
        if (!Unite(es[i].fi, es[i].se))
        {
            kt = 0;
            break;
        }
    }
    if (kt)
    {
        int s1 = Q.size();
        f[mid] = 0;
        for (int i = min(m, pr); i >= max(mid + 1, pl); i--)
        {
            if (!Unite(es[i].fi, es[i].se))
            {
                f[mid] = i;
                break;
            }
        }

        //if (mid == 1)
         //   cerr << f[mid] << '\n';

        rollback(s1);
        Dnc(mid + 1, r, f[mid], pr);
    }
    rollback(s);
    for (int i = f[mid] + 1; i <= pr; i++)
        Unite(es[i].fi, es[i].se);
    Dnc(l, mid - 1, pl, f[mid]);
    rollback(s);
}

void Solve()
{
    memset(lab, -1, sizeof(lab));
    fill(f + 1, f + 1 + m, m + 1);

    es[0] = {n + 1, n + 2};
    Dnc(0, m, 1, m);

    //for (int i = 0; i <= m; i++)
     //   cerr << f[i] << ' ';
    //cerr << '\n';

    while (q-- > 0)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r++;
        cout << (r <= f[l] ? "YES\n" : "NO\n");
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(task".INP","r",stdin);
    //freopen(task".OUT","w",stdout);
    Input();
    Solve();
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::stack<TRback>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while (Q.size() > sz)
      |            ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1096 KB Output is correct
23 Correct 1 ms 1104 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1096 KB Output is correct
23 Correct 1 ms 1104 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1112 KB Output is correct
30 Correct 2 ms 1108 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 2 ms 1192 KB Output is correct
33 Correct 2 ms 1144 KB Output is correct
34 Correct 2 ms 1120 KB Output is correct
35 Correct 3 ms 1108 KB Output is correct
36 Correct 2 ms 1112 KB Output is correct
37 Correct 4 ms 1108 KB Output is correct
38 Correct 2 ms 1108 KB Output is correct
39 Correct 2 ms 1108 KB Output is correct
40 Correct 2 ms 1120 KB Output is correct
41 Correct 2 ms 1148 KB Output is correct
42 Correct 2 ms 1152 KB Output is correct
43 Correct 2 ms 1072 KB Output is correct
44 Correct 2 ms 1152 KB Output is correct
45 Correct 2 ms 1112 KB Output is correct
46 Correct 2 ms 1120 KB Output is correct
47 Correct 2 ms 1108 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 3 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 2 ms 1152 KB Output is correct
53 Correct 3 ms 1120 KB Output is correct
54 Correct 2 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 137 ms 6156 KB Output is correct
4 Correct 115 ms 9760 KB Output is correct
5 Correct 127 ms 10444 KB Output is correct
6 Correct 106 ms 9860 KB Output is correct
7 Correct 114 ms 9792 KB Output is correct
8 Correct 114 ms 8528 KB Output is correct
9 Correct 124 ms 8936 KB Output is correct
10 Correct 164 ms 9324 KB Output is correct
11 Correct 136 ms 9468 KB Output is correct
12 Correct 143 ms 9932 KB Output is correct
13 Correct 121 ms 8252 KB Output is correct
14 Correct 124 ms 9000 KB Output is correct
15 Correct 191 ms 9740 KB Output is correct
16 Correct 158 ms 9712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1096 KB Output is correct
23 Correct 1 ms 1104 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 137 ms 6156 KB Output is correct
30 Correct 115 ms 9760 KB Output is correct
31 Correct 127 ms 10444 KB Output is correct
32 Correct 106 ms 9860 KB Output is correct
33 Correct 114 ms 9792 KB Output is correct
34 Correct 114 ms 8528 KB Output is correct
35 Correct 124 ms 8936 KB Output is correct
36 Correct 164 ms 9324 KB Output is correct
37 Correct 136 ms 9468 KB Output is correct
38 Correct 143 ms 9932 KB Output is correct
39 Correct 121 ms 8252 KB Output is correct
40 Correct 124 ms 9000 KB Output is correct
41 Correct 191 ms 9740 KB Output is correct
42 Correct 158 ms 9712 KB Output is correct
43 Correct 127 ms 9888 KB Output is correct
44 Correct 135 ms 10264 KB Output is correct
45 Correct 196 ms 11692 KB Output is correct
46 Correct 106 ms 10144 KB Output is correct
47 Correct 115 ms 10084 KB Output is correct
48 Correct 140 ms 9484 KB Output is correct
49 Correct 159 ms 10160 KB Output is correct
50 Correct 134 ms 9592 KB Output is correct
51 Correct 144 ms 10112 KB Output is correct
52 Correct 152 ms 9672 KB Output is correct
53 Correct 124 ms 8532 KB Output is correct
54 Correct 143 ms 9544 KB Output is correct
55 Correct 157 ms 10176 KB Output is correct
56 Correct 172 ms 10316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1096 KB Output is correct
23 Correct 1 ms 1104 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1112 KB Output is correct
30 Correct 2 ms 1108 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 2 ms 1192 KB Output is correct
33 Correct 2 ms 1144 KB Output is correct
34 Correct 2 ms 1120 KB Output is correct
35 Correct 3 ms 1108 KB Output is correct
36 Correct 2 ms 1112 KB Output is correct
37 Correct 4 ms 1108 KB Output is correct
38 Correct 2 ms 1108 KB Output is correct
39 Correct 2 ms 1108 KB Output is correct
40 Correct 2 ms 1120 KB Output is correct
41 Correct 2 ms 1148 KB Output is correct
42 Correct 2 ms 1152 KB Output is correct
43 Correct 2 ms 1072 KB Output is correct
44 Correct 2 ms 1152 KB Output is correct
45 Correct 2 ms 1112 KB Output is correct
46 Correct 2 ms 1120 KB Output is correct
47 Correct 2 ms 1108 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 3 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 2 ms 1152 KB Output is correct
53 Correct 3 ms 1120 KB Output is correct
54 Correct 2 ms 1108 KB Output is correct
55 Correct 96 ms 7472 KB Output is correct
56 Correct 90 ms 9420 KB Output is correct
57 Correct 86 ms 9044 KB Output is correct
58 Correct 70 ms 7488 KB Output is correct
59 Correct 112 ms 7240 KB Output is correct
60 Correct 140 ms 7648 KB Output is correct
61 Correct 115 ms 7212 KB Output is correct
62 Correct 114 ms 7808 KB Output is correct
63 Correct 87 ms 6336 KB Output is correct
64 Correct 121 ms 7480 KB Output is correct
65 Correct 133 ms 7780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1096 KB Output is correct
23 Correct 1 ms 1104 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 1 ms 1104 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1112 KB Output is correct
30 Correct 2 ms 1108 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 2 ms 1192 KB Output is correct
33 Correct 2 ms 1144 KB Output is correct
34 Correct 2 ms 1120 KB Output is correct
35 Correct 3 ms 1108 KB Output is correct
36 Correct 2 ms 1112 KB Output is correct
37 Correct 4 ms 1108 KB Output is correct
38 Correct 2 ms 1108 KB Output is correct
39 Correct 2 ms 1108 KB Output is correct
40 Correct 2 ms 1120 KB Output is correct
41 Correct 2 ms 1148 KB Output is correct
42 Correct 2 ms 1152 KB Output is correct
43 Correct 2 ms 1072 KB Output is correct
44 Correct 2 ms 1152 KB Output is correct
45 Correct 2 ms 1112 KB Output is correct
46 Correct 2 ms 1120 KB Output is correct
47 Correct 2 ms 1108 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 3 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 2 ms 1152 KB Output is correct
53 Correct 3 ms 1120 KB Output is correct
54 Correct 2 ms 1108 KB Output is correct
55 Correct 137 ms 6156 KB Output is correct
56 Correct 115 ms 9760 KB Output is correct
57 Correct 127 ms 10444 KB Output is correct
58 Correct 106 ms 9860 KB Output is correct
59 Correct 114 ms 9792 KB Output is correct
60 Correct 114 ms 8528 KB Output is correct
61 Correct 124 ms 8936 KB Output is correct
62 Correct 164 ms 9324 KB Output is correct
63 Correct 136 ms 9468 KB Output is correct
64 Correct 143 ms 9932 KB Output is correct
65 Correct 121 ms 8252 KB Output is correct
66 Correct 124 ms 9000 KB Output is correct
67 Correct 191 ms 9740 KB Output is correct
68 Correct 158 ms 9712 KB Output is correct
69 Correct 127 ms 9888 KB Output is correct
70 Correct 135 ms 10264 KB Output is correct
71 Correct 196 ms 11692 KB Output is correct
72 Correct 106 ms 10144 KB Output is correct
73 Correct 115 ms 10084 KB Output is correct
74 Correct 140 ms 9484 KB Output is correct
75 Correct 159 ms 10160 KB Output is correct
76 Correct 134 ms 9592 KB Output is correct
77 Correct 144 ms 10112 KB Output is correct
78 Correct 152 ms 9672 KB Output is correct
79 Correct 124 ms 8532 KB Output is correct
80 Correct 143 ms 9544 KB Output is correct
81 Correct 157 ms 10176 KB Output is correct
82 Correct 172 ms 10316 KB Output is correct
83 Correct 96 ms 7472 KB Output is correct
84 Correct 90 ms 9420 KB Output is correct
85 Correct 86 ms 9044 KB Output is correct
86 Correct 70 ms 7488 KB Output is correct
87 Correct 112 ms 7240 KB Output is correct
88 Correct 140 ms 7648 KB Output is correct
89 Correct 115 ms 7212 KB Output is correct
90 Correct 114 ms 7808 KB Output is correct
91 Correct 87 ms 6336 KB Output is correct
92 Correct 121 ms 7480 KB Output is correct
93 Correct 133 ms 7780 KB Output is correct
94 Correct 136 ms 10580 KB Output is correct
95 Correct 174 ms 12432 KB Output is correct
96 Correct 116 ms 11316 KB Output is correct
97 Correct 116 ms 10800 KB Output is correct
98 Correct 121 ms 10820 KB Output is correct
99 Correct 136 ms 10060 KB Output is correct
100 Correct 144 ms 11120 KB Output is correct
101 Correct 138 ms 10332 KB Output is correct
102 Correct 154 ms 10828 KB Output is correct
103 Correct 158 ms 11324 KB Output is correct
104 Correct 135 ms 9816 KB Output is correct
105 Correct 164 ms 10744 KB Output is correct
106 Correct 175 ms 11040 KB Output is correct
107 Correct 111 ms 11548 KB Output is correct
108 Correct 140 ms 10372 KB Output is correct
109 Correct 140 ms 10340 KB Output is correct
110 Correct 132 ms 10376 KB Output is correct
111 Correct 134 ms 10376 KB Output is correct
112 Correct 138 ms 10456 KB Output is correct
113 Correct 137 ms 10428 KB Output is correct
114 Correct 127 ms 10368 KB Output is correct
115 Correct 138 ms 10328 KB Output is correct
116 Correct 164 ms 10380 KB Output is correct