Submission #255070

# Submission time Handle Problem Language Result Execution time Memory
255070 2020-07-31T07:49:31 Z davitmarg Joker (BOI20_joker) C++17
100 / 100
390 ms 9956 KB
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 200005;

int p[N],col[N],BI,sz[N];
vector<pair<pair<int, int>, int>>st;

void init(int n)
{
    st.clear();
    for (int i = 1; i <= n; i++)
    {
        p[i] = i;
        col[i] = 0;
        sz[i] = 1;
    }
}

void und()
{
    int b = st.back().first.first;
    int a = st.back().first.second;
    if (a == b)
    {
        BI -= st.back().second;
        st.pop_back();
        return;
    }
    sz[a] -= st.back().second;
    sz[b] += st.back().second;
    p[b] = b;
    st.pop_back();
}

pair<int, int> get(int v)
{
    int c=col[v];
    while (v != p[v])
    {
        v = p[v];
        c ^= col[v];
    }
    return MP(v, c);
}

void dsu(int a, int b)
{
    pair<int,int> A = get(a), B = get(b);
    if (A.first == B.first)
    {
        if (A.second == B.second)
            BI++;
        st.push_back(MP(MP(A.first, B.first), (A.second == B.second)));
        return;
    }
    if (sz[A.first] < sz[B.first])
        swap(A, B);
    st.push_back(MP(MP(B.first, A.first), sz[B.first]));
    if (A.second == B.second)
        col[B.first] ^= 1;

    sz[A.first] += sz[B.first];
    sz[B.first] = 0;
    p[B.first] = A.first;
    col[B.first] ^= col[A.first];
}


int n, m, q, L[N], R[N],X[N],Y[N], used[N], d[N], fnd, pos[N];

void solve(int l, int r, int optl, int optr)
{
    if (l > r)
        return;
    int m = (l + r) / 2;
    for (int i = l; i < m; i++)
        dsu(X[i], Y[i]);
    int optm = optr + 1;
    for (int i = optr; i >= m && i>=optl && BI==0; i--)
    {
        dsu(X[i], Y[i]);
        if (BI || i == m)
        {
            optm = i;
            und();
            break;
        }
    }
    pos[m] = optm;
    optm = min(optr, optm);
    
    for (int i = optr; i > optm; i--)
        und();
    for (int i = l; i < m; i++)
        und();

    for (int i = optr; i > optm; i--)
        dsu(X[i], Y[i]);

    solve(l, m - 1, optl, optm);

    for (int i = optr; i > optm; i--)
        und();

    for (int i = l; i <= m; i++)
        dsu(X[i], Y[i]);
    solve(m + 1, r, max(optm, m + 1), optr);
    for (int i = l; i <= m; i++)
        und();
}

int main()
{
    fastIO;
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++)
        cin >> X[i] >> Y[i];

    init(n);

    solve(1, m, 1, m);

    for (int i = 1; i <= q; i++)
    {
        cin >> L[i] >> R[i];
        if (R[i] >= pos[L[i]])
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

/*




*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 223 ms 8672 KB Output is correct
4 Correct 334 ms 9832 KB Output is correct
5 Correct 197 ms 9568 KB Output is correct
6 Correct 272 ms 8516 KB Output is correct
7 Correct 262 ms 8676 KB Output is correct
8 Correct 283 ms 8288 KB Output is correct
9 Correct 296 ms 8804 KB Output is correct
10 Correct 360 ms 9948 KB Output is correct
11 Correct 264 ms 8672 KB Output is correct
12 Correct 292 ms 9444 KB Output is correct
13 Correct 262 ms 7652 KB Output is correct
14 Correct 273 ms 8032 KB Output is correct
15 Correct 358 ms 9184 KB Output is correct
16 Correct 366 ms 9688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 223 ms 8672 KB Output is correct
30 Correct 334 ms 9832 KB Output is correct
31 Correct 197 ms 9568 KB Output is correct
32 Correct 272 ms 8516 KB Output is correct
33 Correct 262 ms 8676 KB Output is correct
34 Correct 283 ms 8288 KB Output is correct
35 Correct 296 ms 8804 KB Output is correct
36 Correct 360 ms 9948 KB Output is correct
37 Correct 264 ms 8672 KB Output is correct
38 Correct 292 ms 9444 KB Output is correct
39 Correct 262 ms 7652 KB Output is correct
40 Correct 273 ms 8032 KB Output is correct
41 Correct 358 ms 9184 KB Output is correct
42 Correct 366 ms 9688 KB Output is correct
43 Correct 222 ms 8572 KB Output is correct
44 Correct 331 ms 9648 KB Output is correct
45 Correct 297 ms 9684 KB Output is correct
46 Correct 250 ms 8676 KB Output is correct
47 Correct 278 ms 8676 KB Output is correct
48 Correct 331 ms 8672 KB Output is correct
49 Correct 384 ms 9888 KB Output is correct
50 Correct 270 ms 8288 KB Output is correct
51 Correct 287 ms 9060 KB Output is correct
52 Correct 303 ms 9700 KB Output is correct
53 Correct 266 ms 7648 KB Output is correct
54 Correct 316 ms 8504 KB Output is correct
55 Correct 357 ms 9172 KB Output is correct
56 Correct 374 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 174 ms 6660 KB Output is correct
56 Correct 276 ms 7532 KB Output is correct
57 Correct 161 ms 7660 KB Output is correct
58 Correct 203 ms 6760 KB Output is correct
59 Correct 271 ms 6760 KB Output is correct
60 Correct 334 ms 7404 KB Output is correct
61 Correct 246 ms 6760 KB Output is correct
62 Correct 279 ms 7644 KB Output is correct
63 Correct 228 ms 5996 KB Output is correct
64 Correct 305 ms 6924 KB Output is correct
65 Correct 338 ms 7628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 223 ms 8672 KB Output is correct
56 Correct 334 ms 9832 KB Output is correct
57 Correct 197 ms 9568 KB Output is correct
58 Correct 272 ms 8516 KB Output is correct
59 Correct 262 ms 8676 KB Output is correct
60 Correct 283 ms 8288 KB Output is correct
61 Correct 296 ms 8804 KB Output is correct
62 Correct 360 ms 9948 KB Output is correct
63 Correct 264 ms 8672 KB Output is correct
64 Correct 292 ms 9444 KB Output is correct
65 Correct 262 ms 7652 KB Output is correct
66 Correct 273 ms 8032 KB Output is correct
67 Correct 358 ms 9184 KB Output is correct
68 Correct 366 ms 9688 KB Output is correct
69 Correct 222 ms 8572 KB Output is correct
70 Correct 331 ms 9648 KB Output is correct
71 Correct 297 ms 9684 KB Output is correct
72 Correct 250 ms 8676 KB Output is correct
73 Correct 278 ms 8676 KB Output is correct
74 Correct 331 ms 8672 KB Output is correct
75 Correct 384 ms 9888 KB Output is correct
76 Correct 270 ms 8288 KB Output is correct
77 Correct 287 ms 9060 KB Output is correct
78 Correct 303 ms 9700 KB Output is correct
79 Correct 266 ms 7648 KB Output is correct
80 Correct 316 ms 8504 KB Output is correct
81 Correct 357 ms 9172 KB Output is correct
82 Correct 374 ms 9728 KB Output is correct
83 Correct 174 ms 6660 KB Output is correct
84 Correct 276 ms 7532 KB Output is correct
85 Correct 161 ms 7660 KB Output is correct
86 Correct 203 ms 6760 KB Output is correct
87 Correct 271 ms 6760 KB Output is correct
88 Correct 334 ms 7404 KB Output is correct
89 Correct 246 ms 6760 KB Output is correct
90 Correct 279 ms 7644 KB Output is correct
91 Correct 228 ms 5996 KB Output is correct
92 Correct 305 ms 6924 KB Output is correct
93 Correct 338 ms 7628 KB Output is correct
94 Correct 249 ms 8636 KB Output is correct
95 Correct 307 ms 9832 KB Output is correct
96 Correct 232 ms 9584 KB Output is correct
97 Correct 259 ms 8672 KB Output is correct
98 Correct 274 ms 8712 KB Output is correct
99 Correct 319 ms 8292 KB Output is correct
100 Correct 366 ms 9956 KB Output is correct
101 Correct 348 ms 8488 KB Output is correct
102 Correct 333 ms 9192 KB Output is correct
103 Correct 344 ms 9828 KB Output is correct
104 Correct 313 ms 7928 KB Output is correct
105 Correct 359 ms 8856 KB Output is correct
106 Correct 390 ms 9568 KB Output is correct
107 Correct 193 ms 9700 KB Output is correct
108 Correct 254 ms 8748 KB Output is correct
109 Correct 247 ms 8592 KB Output is correct
110 Correct 230 ms 8548 KB Output is correct
111 Correct 233 ms 8516 KB Output is correct
112 Correct 242 ms 8548 KB Output is correct
113 Correct 230 ms 8548 KB Output is correct
114 Correct 238 ms 8656 KB Output is correct
115 Correct 225 ms 8544 KB Output is correct
116 Correct 238 ms 8544 KB Output is correct