Submission #667477

# Submission time Handle Problem Language Result Execution time Memory
667477 2022-12-01T14:17:08 Z fatemetmhr Joker (BOI20_joker) C++17
100 / 100
290 ms 14832 KB
// ~ Be Name Khoda ~

// author: Fatemeh :/


#include<bits/stdc++.h>
//#pragma GCC optimize("O3")

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second

const int maxn  =  1e6   + 10;
const int maxn5 =  5e5   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  1e18;

struct posit{
    bool oddcy;
    int v, u, paru, parv;
    posit(bool od, int vv, int uu, int pv, int pu){
        oddcy = od;
        v = vv;
        u = uu;
        parv = pv;
        paru = pu;
    }
};

vector <posit> av;
bool ty[maxn5], oddcy = false;
int par[maxn5], a[maxn5], b[maxn5], ans[maxn5];

pair<int, int> get_par(int v){
    int x = 0;
    while(par[v] >= 0){
        x ^= ty[v];
        v = par[v];
    }
    return {v, x};
}

inline void add(int i){
    pair<int, int> ver1 = get_par(a[i]), ver2 = get_par(b[i]);
    int v = ver1.fi, u = ver2.fi;
    if(u == v){
        posit cur(oddcy, -1, -1, -1, -1);
        av.pb(cur);
        oddcy |= (ver1.se == ver2.se);
        return;
    }
    if(par[v] < par[u])
        swap(u, v);
    posit cur(oddcy, v, u, par[v], par[u]);
    av.pb(cur);
    if(par[v] == par[u])
        par[u]--;
    par[v] = u;
    ty[v] = (ver1.se ^ ver2.se ^ 1);
    return;
}

inline void undo(){
    posit cur = av.back(); av.pop_back();
    oddcy = cur.oddcy;
    if(cur.u == -1)
        return;
    par[cur.u] = cur.paru;
    par[cur.v] = cur.parv;
    return;
}

void solve(int l, int r, int optl, int optr){
    if(r <= l || optr <= optl || optr <= l)
        return;
    int keepsize = av.size();
    int mid = (l + r) >> 1;
    for(int i = l; i < mid; i++)
        add(i);
    int opt = mid - 1;
    if(oddcy){
        opt = optr - 1;
    }
    else{
        for(int i = optr - 1; i > max(mid, optl); i--){
            add(i);
            if(oddcy){
                opt = i - 1;
                break;
            }
        }
    }
    ans[mid] = opt;
    while(av.size() > keepsize)
        undo();
    for(int i = optr - 1; i > opt; i--)
        add(i);
    solve(l, mid, optl, opt + 1);
    while(av.size() > keepsize)
        undo();
    for(int i = l; i <= mid; i++)
        add(i);
    solve(mid + 1, r, opt, optr);
    while(av.size() > keepsize)
        undo();
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);

    int n, m, q; cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        ans[i] = i - 1;
    }
    memset(par, -1, sizeof par);
    solve(0, m, 0, m);
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        l--; r--;
        cout << (ans[l] >= r ? "YES\n" : "NO\n");
    }
}

/*
Why so fast...? 
Hold on...
Hold your breath...
Need anything else?

Nein, Kein Problem...
Das Leben war schon immer so grausam :)
*/

Compilation message

Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:102:21: warning: comparison of integer expressions of different signedness: 'std::vector<posit>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |     while(av.size() > keepsize)
      |           ~~~~~~~~~~^~~~~~~~~~
Joker.cpp:107:21: warning: comparison of integer expressions of different signedness: 'std::vector<posit>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |     while(av.size() > keepsize)
      |           ~~~~~~~~~~^~~~~~~~~~
Joker.cpp:112:21: warning: comparison of integer expressions of different signedness: 'std::vector<posit>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  112 |     while(av.size() > keepsize)
      |           ~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2256 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 2 ms 2248 KB Output is correct
9 Correct 2 ms 2244 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2244 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 1 ms 2260 KB Output is correct
23 Correct 1 ms 2260 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 2 ms 2260 KB Output is correct
26 Correct 1 ms 2260 KB Output is correct
27 Correct 1 ms 2260 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2256 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 2 ms 2248 KB Output is correct
9 Correct 2 ms 2244 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2244 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 1 ms 2260 KB Output is correct
23 Correct 1 ms 2260 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 2 ms 2260 KB Output is correct
26 Correct 1 ms 2260 KB Output is correct
27 Correct 1 ms 2260 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
29 Correct 3 ms 2392 KB Output is correct
30 Correct 3 ms 2388 KB Output is correct
31 Correct 3 ms 2388 KB Output is correct
32 Correct 2 ms 2388 KB Output is correct
33 Correct 2 ms 2388 KB Output is correct
34 Correct 3 ms 2388 KB Output is correct
35 Correct 3 ms 2384 KB Output is correct
36 Correct 2 ms 2444 KB Output is correct
37 Correct 3 ms 2388 KB Output is correct
38 Correct 3 ms 2388 KB Output is correct
39 Correct 2 ms 2388 KB Output is correct
40 Correct 3 ms 2388 KB Output is correct
41 Correct 3 ms 2388 KB Output is correct
42 Correct 2 ms 2436 KB Output is correct
43 Correct 3 ms 2388 KB Output is correct
44 Correct 3 ms 2388 KB Output is correct
45 Correct 4 ms 2388 KB Output is correct
46 Correct 3 ms 2388 KB Output is correct
47 Correct 3 ms 2388 KB Output is correct
48 Correct 3 ms 2420 KB Output is correct
49 Correct 3 ms 2388 KB Output is correct
50 Correct 3 ms 2388 KB Output is correct
51 Correct 3 ms 2384 KB Output is correct
52 Correct 3 ms 2444 KB Output is correct
53 Correct 3 ms 2388 KB Output is correct
54 Correct 3 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 165 ms 13444 KB Output is correct
4 Correct 227 ms 12976 KB Output is correct
5 Correct 139 ms 13744 KB Output is correct
6 Correct 170 ms 13328 KB Output is correct
7 Correct 180 ms 13336 KB Output is correct
8 Correct 220 ms 12848 KB Output is correct
9 Correct 229 ms 12804 KB Output is correct
10 Correct 256 ms 13296 KB Output is correct
11 Correct 197 ms 13384 KB Output is correct
12 Correct 232 ms 13664 KB Output is correct
13 Correct 211 ms 13120 KB Output is correct
14 Correct 219 ms 13384 KB Output is correct
15 Correct 249 ms 13408 KB Output is correct
16 Correct 257 ms 13616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2256 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 2 ms 2248 KB Output is correct
9 Correct 2 ms 2244 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2244 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 1 ms 2260 KB Output is correct
23 Correct 1 ms 2260 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 2 ms 2260 KB Output is correct
26 Correct 1 ms 2260 KB Output is correct
27 Correct 1 ms 2260 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
29 Correct 165 ms 13444 KB Output is correct
30 Correct 227 ms 12976 KB Output is correct
31 Correct 139 ms 13744 KB Output is correct
32 Correct 170 ms 13328 KB Output is correct
33 Correct 180 ms 13336 KB Output is correct
34 Correct 220 ms 12848 KB Output is correct
35 Correct 229 ms 12804 KB Output is correct
36 Correct 256 ms 13296 KB Output is correct
37 Correct 197 ms 13384 KB Output is correct
38 Correct 232 ms 13664 KB Output is correct
39 Correct 211 ms 13120 KB Output is correct
40 Correct 219 ms 13384 KB Output is correct
41 Correct 249 ms 13408 KB Output is correct
42 Correct 257 ms 13616 KB Output is correct
43 Correct 161 ms 13720 KB Output is correct
44 Correct 230 ms 13444 KB Output is correct
45 Correct 240 ms 13816 KB Output is correct
46 Correct 173 ms 13736 KB Output is correct
47 Correct 186 ms 13716 KB Output is correct
48 Correct 240 ms 13356 KB Output is correct
49 Correct 268 ms 13680 KB Output is correct
50 Correct 206 ms 13576 KB Output is correct
51 Correct 223 ms 13888 KB Output is correct
52 Correct 228 ms 13872 KB Output is correct
53 Correct 221 ms 13484 KB Output is correct
54 Correct 232 ms 13752 KB Output is correct
55 Correct 271 ms 13972 KB Output is correct
56 Correct 290 ms 13924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2256 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 2 ms 2248 KB Output is correct
9 Correct 2 ms 2244 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2244 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 1 ms 2260 KB Output is correct
23 Correct 1 ms 2260 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 2 ms 2260 KB Output is correct
26 Correct 1 ms 2260 KB Output is correct
27 Correct 1 ms 2260 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
29 Correct 3 ms 2392 KB Output is correct
30 Correct 3 ms 2388 KB Output is correct
31 Correct 3 ms 2388 KB Output is correct
32 Correct 2 ms 2388 KB Output is correct
33 Correct 2 ms 2388 KB Output is correct
34 Correct 3 ms 2388 KB Output is correct
35 Correct 3 ms 2384 KB Output is correct
36 Correct 2 ms 2444 KB Output is correct
37 Correct 3 ms 2388 KB Output is correct
38 Correct 3 ms 2388 KB Output is correct
39 Correct 2 ms 2388 KB Output is correct
40 Correct 3 ms 2388 KB Output is correct
41 Correct 3 ms 2388 KB Output is correct
42 Correct 2 ms 2436 KB Output is correct
43 Correct 3 ms 2388 KB Output is correct
44 Correct 3 ms 2388 KB Output is correct
45 Correct 4 ms 2388 KB Output is correct
46 Correct 3 ms 2388 KB Output is correct
47 Correct 3 ms 2388 KB Output is correct
48 Correct 3 ms 2420 KB Output is correct
49 Correct 3 ms 2388 KB Output is correct
50 Correct 3 ms 2388 KB Output is correct
51 Correct 3 ms 2384 KB Output is correct
52 Correct 3 ms 2444 KB Output is correct
53 Correct 3 ms 2388 KB Output is correct
54 Correct 3 ms 2392 KB Output is correct
55 Correct 130 ms 12328 KB Output is correct
56 Correct 212 ms 12604 KB Output is correct
57 Correct 116 ms 12604 KB Output is correct
58 Correct 151 ms 12216 KB Output is correct
59 Correct 222 ms 12316 KB Output is correct
60 Correct 263 ms 12600 KB Output is correct
61 Correct 182 ms 12240 KB Output is correct
62 Correct 215 ms 12600 KB Output is correct
63 Correct 189 ms 12204 KB Output is correct
64 Correct 217 ms 12308 KB Output is correct
65 Correct 244 ms 12548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2248 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2256 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 2 ms 2248 KB Output is correct
9 Correct 2 ms 2244 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 1 ms 2260 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2244 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 1 ms 2260 KB Output is correct
23 Correct 1 ms 2260 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 2 ms 2260 KB Output is correct
26 Correct 1 ms 2260 KB Output is correct
27 Correct 1 ms 2260 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
29 Correct 3 ms 2392 KB Output is correct
30 Correct 3 ms 2388 KB Output is correct
31 Correct 3 ms 2388 KB Output is correct
32 Correct 2 ms 2388 KB Output is correct
33 Correct 2 ms 2388 KB Output is correct
34 Correct 3 ms 2388 KB Output is correct
35 Correct 3 ms 2384 KB Output is correct
36 Correct 2 ms 2444 KB Output is correct
37 Correct 3 ms 2388 KB Output is correct
38 Correct 3 ms 2388 KB Output is correct
39 Correct 2 ms 2388 KB Output is correct
40 Correct 3 ms 2388 KB Output is correct
41 Correct 3 ms 2388 KB Output is correct
42 Correct 2 ms 2436 KB Output is correct
43 Correct 3 ms 2388 KB Output is correct
44 Correct 3 ms 2388 KB Output is correct
45 Correct 4 ms 2388 KB Output is correct
46 Correct 3 ms 2388 KB Output is correct
47 Correct 3 ms 2388 KB Output is correct
48 Correct 3 ms 2420 KB Output is correct
49 Correct 3 ms 2388 KB Output is correct
50 Correct 3 ms 2388 KB Output is correct
51 Correct 3 ms 2384 KB Output is correct
52 Correct 3 ms 2444 KB Output is correct
53 Correct 3 ms 2388 KB Output is correct
54 Correct 3 ms 2392 KB Output is correct
55 Correct 165 ms 13444 KB Output is correct
56 Correct 227 ms 12976 KB Output is correct
57 Correct 139 ms 13744 KB Output is correct
58 Correct 170 ms 13328 KB Output is correct
59 Correct 180 ms 13336 KB Output is correct
60 Correct 220 ms 12848 KB Output is correct
61 Correct 229 ms 12804 KB Output is correct
62 Correct 256 ms 13296 KB Output is correct
63 Correct 197 ms 13384 KB Output is correct
64 Correct 232 ms 13664 KB Output is correct
65 Correct 211 ms 13120 KB Output is correct
66 Correct 219 ms 13384 KB Output is correct
67 Correct 249 ms 13408 KB Output is correct
68 Correct 257 ms 13616 KB Output is correct
69 Correct 161 ms 13720 KB Output is correct
70 Correct 230 ms 13444 KB Output is correct
71 Correct 240 ms 13816 KB Output is correct
72 Correct 173 ms 13736 KB Output is correct
73 Correct 186 ms 13716 KB Output is correct
74 Correct 240 ms 13356 KB Output is correct
75 Correct 268 ms 13680 KB Output is correct
76 Correct 206 ms 13576 KB Output is correct
77 Correct 223 ms 13888 KB Output is correct
78 Correct 228 ms 13872 KB Output is correct
79 Correct 221 ms 13484 KB Output is correct
80 Correct 232 ms 13752 KB Output is correct
81 Correct 271 ms 13972 KB Output is correct
82 Correct 290 ms 13924 KB Output is correct
83 Correct 130 ms 12328 KB Output is correct
84 Correct 212 ms 12604 KB Output is correct
85 Correct 116 ms 12604 KB Output is correct
86 Correct 151 ms 12216 KB Output is correct
87 Correct 222 ms 12316 KB Output is correct
88 Correct 263 ms 12600 KB Output is correct
89 Correct 182 ms 12240 KB Output is correct
90 Correct 215 ms 12600 KB Output is correct
91 Correct 189 ms 12204 KB Output is correct
92 Correct 217 ms 12308 KB Output is correct
93 Correct 244 ms 12548 KB Output is correct
94 Correct 180 ms 14492 KB Output is correct
95 Correct 194 ms 14560 KB Output is correct
96 Correct 153 ms 14804 KB Output is correct
97 Correct 175 ms 14408 KB Output is correct
98 Correct 186 ms 14448 KB Output is correct
99 Correct 229 ms 14444 KB Output is correct
100 Correct 242 ms 14640 KB Output is correct
101 Correct 206 ms 14340 KB Output is correct
102 Correct 233 ms 14544 KB Output is correct
103 Correct 234 ms 14640 KB Output is correct
104 Correct 221 ms 14380 KB Output is correct
105 Correct 244 ms 14472 KB Output is correct
106 Correct 273 ms 14636 KB Output is correct
107 Correct 136 ms 14832 KB Output is correct
108 Correct 162 ms 14124 KB Output is correct
109 Correct 162 ms 14224 KB Output is correct
110 Correct 163 ms 14108 KB Output is correct
111 Correct 164 ms 14224 KB Output is correct
112 Correct 167 ms 14360 KB Output is correct
113 Correct 160 ms 14132 KB Output is correct
114 Correct 162 ms 14128 KB Output is correct
115 Correct 173 ms 14224 KB Output is correct
116 Correct 161 ms 14124 KB Output is correct