Submission #877807

# Submission time Handle Problem Language Result Execution time Memory
877807 2023-11-23T14:59:43 Z saddd Joker (BOI20_joker) C++17
100 / 100
331 ms 19884 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1000001;
const int mxn = 3e5 + 1, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5, p = 31;
//const int base = (1 << 18);
const ll inf = 1e9 + 5, neg = -69420;
struct DSU{
    vt<pii>past_p, past_sz;
    vt<int>checkpoint;
    int p[2 * mxn + 1], sz[2 * mxn + 1];
    void init(){
        for(int i = 0; i <= 2 * mxn; i++){
            p[i] = i; sz[i]  = 1;
        }
        past_sz.clear(); past_p.clear(); checkpoint.clear();
    }
    int fp(int a){
        if(p[a] == a)return(a);
        return(fp(p[a]));
    }
    bool check(int u, int v){
        return(fp(u) == fp(v));
    }
    void unon(int a, int b){
 
        a = fp(a); b = fp(b);
        if(sz[a] < sz[b])swap(a, b);
        past_sz.pb({a, sz[a]}); past_p.pb({b, p[b]});
        if(a != b){
            sz[a] += sz[b]; p[b] = a;
        }
    }
    void rollback(){
        //int before = p[past_p.back().fi], after = past_p.back().se;
        //if(before != past_p.back().fi && after == past_p.back().fi)cnt++;
        p[past_p.back().fi] = past_p.back().se; past_p.pop_back();
        sz[past_sz.back().fi] = past_sz.back().se; past_sz.pop_back();
    }
    void save(){
        checkpoint.pb(past_sz.size());
    }
    void to_last(){
        while(past_sz.size() != checkpoint.back())rollback();
        checkpoint.pop_back();
        
    }
};
DSU dsu;
int n, m, q;
int u[mxn + 1], v[mxn + 1];
int to[mxn + 1];
void input(){
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        cin >> u[i] >> v[i];
        
    }
 
}
void solve(int l, int r, int candl, int candr){
    if(candr == -1 || candl == candr){
        for(int i = l; i <= r; i++)to[i] = candr;
        return;
    }
    if(l > r)return;
    int mid = (l + r) >> 1;
    dsu.save(); dsu.save(); dsu.save();
    for(int i = l; i < mid; i++){
        dsu.unon(u[i] << 1, v[i] << 1 | 1); dsu.unon(u[i] << 1 | 1, v[i] << 1);
        if(dsu.check(u[i] << 1, u[i] << 1 | 1) || dsu.check(v[i] << 1, v[i] << 1 | 1)){
            assert(0);
            break;
        }
    }
    int last = mid;
   
    for(int i = candr; i >= max(mid + 1, candl); i--){
        dsu.unon(u[i] << 1, v[i] << 1 | 1); dsu.unon(u[i] << 1 | 1, v[i] << 1);
        if(dsu.check(u[i] << 1, u[i] << 1 | 1) || dsu.check(v[i] << 1, v[i] << 1 | 1)){
            last = i;
            break;
        }
        
    }
    to[mid] = last;
    
    dsu.to_last();
    bool bad = 0;
    for(int i = candr; i > last; i--){
        dsu.unon(u[i] << 1, v[i] << 1 | 1); dsu.unon(u[i] << 1 | 1, v[i] << 1);
        if(dsu.check(u[i] << 1, u[i] << 1 | 1) || dsu.check(v[i] << 1, v[i] << 1 | 1)){
            bad = 1;
            break;
        }
    }
    if(bad == 1){
        for(int i = l; i < mid; i++)to[i] = last;
        
    }else{
        solve(l, mid - 1, candl, last);
    }
    dsu.to_last();
    for(int i = l; i <= mid; i++){
        dsu.unon(u[i] << 1, v[i] << 1 | 1); dsu.unon(u[i] << 1 | 1, v[i] << 1);
        if(dsu.check(u[i] << 1, u[i] << 1 | 1) || dsu.check(v[i] << 1, v[i] << 1 | 1)){
            break;
        }
    }
    solve(mid + 1, r, last, candr);
    dsu.to_last();
}
void process(){
   dsu.init();
   int last = m;
   for(int i = 0; i < m; i++){
       dsu.unon(u[i] << 1, v[i] << 1 | 1); dsu.unon(u[i] << 1 | 1, v[i] << 1);
       if(dsu.check(u[i] << 1, u[i] << 1 | 1) || dsu.check(v[i] << 1, v[i] << 1 | 1)){
           last = i; break;
       }
   }
   for(int i = last + 1; i < m; i++){
       to[i] = m;
   }
   dsu.init();
   solve(0, last, 0, m - 1); 
  
   while(q--){
      int l, r; cin >> l >> r; --l; --r;
      cout << ((to[l] > r) ? "YES" : "NO") << "\n";
    
   }
}
 
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    process();
    return(0);
}

Compilation message

Joker.cpp: In member function 'void DSU::to_last()':
Joker.cpp:62:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   62 |         while(past_sz.size() != checkpoint.back())rollback();
      |               ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8412 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8408 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8316 KB Output is correct
12 Correct 2 ms 8280 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 3 ms 8280 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8412 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8408 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8316 KB Output is correct
12 Correct 2 ms 8280 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 3 ms 8280 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8504 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 4 ms 8540 KB Output is correct
35 Correct 4 ms 8420 KB Output is correct
36 Correct 4 ms 8540 KB Output is correct
37 Correct 4 ms 8540 KB Output is correct
38 Correct 5 ms 8536 KB Output is correct
39 Correct 4 ms 8540 KB Output is correct
40 Correct 3 ms 8424 KB Output is correct
41 Correct 3 ms 8540 KB Output is correct
42 Correct 3 ms 8608 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 3 ms 8536 KB Output is correct
45 Correct 3 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 3 ms 8540 KB Output is correct
49 Correct 3 ms 8536 KB Output is correct
50 Correct 4 ms 8540 KB Output is correct
51 Correct 3 ms 8608 KB Output is correct
52 Correct 3 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 4 ms 8788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 177 ms 14888 KB Output is correct
4 Correct 327 ms 17908 KB Output is correct
5 Correct 107 ms 18584 KB Output is correct
6 Correct 99 ms 14772 KB Output is correct
7 Correct 104 ms 14936 KB Output is correct
8 Correct 111 ms 15024 KB Output is correct
9 Correct 128 ms 15248 KB Output is correct
10 Correct 174 ms 15024 KB Output is correct
11 Correct 141 ms 14960 KB Output is correct
12 Correct 157 ms 15632 KB Output is correct
13 Correct 115 ms 14772 KB Output is correct
14 Correct 117 ms 14764 KB Output is correct
15 Correct 168 ms 14876 KB Output is correct
16 Correct 177 ms 15284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8412 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8408 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8316 KB Output is correct
12 Correct 2 ms 8280 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 3 ms 8280 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 177 ms 14888 KB Output is correct
30 Correct 327 ms 17908 KB Output is correct
31 Correct 107 ms 18584 KB Output is correct
32 Correct 99 ms 14772 KB Output is correct
33 Correct 104 ms 14936 KB Output is correct
34 Correct 111 ms 15024 KB Output is correct
35 Correct 128 ms 15248 KB Output is correct
36 Correct 174 ms 15024 KB Output is correct
37 Correct 141 ms 14960 KB Output is correct
38 Correct 157 ms 15632 KB Output is correct
39 Correct 115 ms 14772 KB Output is correct
40 Correct 117 ms 14764 KB Output is correct
41 Correct 168 ms 14876 KB Output is correct
42 Correct 177 ms 15284 KB Output is correct
43 Correct 180 ms 15020 KB Output is correct
44 Correct 331 ms 18088 KB Output is correct
45 Correct 176 ms 19380 KB Output is correct
46 Correct 102 ms 15160 KB Output is correct
47 Correct 99 ms 14996 KB Output is correct
48 Correct 136 ms 14952 KB Output is correct
49 Correct 173 ms 15180 KB Output is correct
50 Correct 146 ms 15020 KB Output is correct
51 Correct 145 ms 15352 KB Output is correct
52 Correct 157 ms 15612 KB Output is correct
53 Correct 122 ms 15128 KB Output is correct
54 Correct 147 ms 15016 KB Output is correct
55 Correct 162 ms 15284 KB Output is correct
56 Correct 176 ms 15524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8412 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8408 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8316 KB Output is correct
12 Correct 2 ms 8280 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 3 ms 8280 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8504 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 4 ms 8540 KB Output is correct
35 Correct 4 ms 8420 KB Output is correct
36 Correct 4 ms 8540 KB Output is correct
37 Correct 4 ms 8540 KB Output is correct
38 Correct 5 ms 8536 KB Output is correct
39 Correct 4 ms 8540 KB Output is correct
40 Correct 3 ms 8424 KB Output is correct
41 Correct 3 ms 8540 KB Output is correct
42 Correct 3 ms 8608 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 3 ms 8536 KB Output is correct
45 Correct 3 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 3 ms 8540 KB Output is correct
49 Correct 3 ms 8536 KB Output is correct
50 Correct 4 ms 8540 KB Output is correct
51 Correct 3 ms 8608 KB Output is correct
52 Correct 3 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 4 ms 8788 KB Output is correct
55 Correct 153 ms 13744 KB Output is correct
56 Correct 288 ms 18036 KB Output is correct
57 Correct 75 ms 19884 KB Output is correct
58 Correct 68 ms 13684 KB Output is correct
59 Correct 108 ms 13748 KB Output is correct
60 Correct 150 ms 13744 KB Output is correct
61 Correct 121 ms 13744 KB Output is correct
62 Correct 147 ms 14092 KB Output is correct
63 Correct 84 ms 13408 KB Output is correct
64 Correct 117 ms 13608 KB Output is correct
65 Correct 145 ms 13636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8412 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8408 KB Output is correct
9 Correct 2 ms 8280 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8316 KB Output is correct
12 Correct 2 ms 8280 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8280 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8284 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct
26 Correct 3 ms 8280 KB Output is correct
27 Correct 2 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8504 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 4 ms 8540 KB Output is correct
35 Correct 4 ms 8420 KB Output is correct
36 Correct 4 ms 8540 KB Output is correct
37 Correct 4 ms 8540 KB Output is correct
38 Correct 5 ms 8536 KB Output is correct
39 Correct 4 ms 8540 KB Output is correct
40 Correct 3 ms 8424 KB Output is correct
41 Correct 3 ms 8540 KB Output is correct
42 Correct 3 ms 8608 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 3 ms 8536 KB Output is correct
45 Correct 3 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 3 ms 8540 KB Output is correct
49 Correct 3 ms 8536 KB Output is correct
50 Correct 4 ms 8540 KB Output is correct
51 Correct 3 ms 8608 KB Output is correct
52 Correct 3 ms 8540 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 4 ms 8788 KB Output is correct
55 Correct 177 ms 14888 KB Output is correct
56 Correct 327 ms 17908 KB Output is correct
57 Correct 107 ms 18584 KB Output is correct
58 Correct 99 ms 14772 KB Output is correct
59 Correct 104 ms 14936 KB Output is correct
60 Correct 111 ms 15024 KB Output is correct
61 Correct 128 ms 15248 KB Output is correct
62 Correct 174 ms 15024 KB Output is correct
63 Correct 141 ms 14960 KB Output is correct
64 Correct 157 ms 15632 KB Output is correct
65 Correct 115 ms 14772 KB Output is correct
66 Correct 117 ms 14764 KB Output is correct
67 Correct 168 ms 14876 KB Output is correct
68 Correct 177 ms 15284 KB Output is correct
69 Correct 180 ms 15020 KB Output is correct
70 Correct 331 ms 18088 KB Output is correct
71 Correct 176 ms 19380 KB Output is correct
72 Correct 102 ms 15160 KB Output is correct
73 Correct 99 ms 14996 KB Output is correct
74 Correct 136 ms 14952 KB Output is correct
75 Correct 173 ms 15180 KB Output is correct
76 Correct 146 ms 15020 KB Output is correct
77 Correct 145 ms 15352 KB Output is correct
78 Correct 157 ms 15612 KB Output is correct
79 Correct 122 ms 15128 KB Output is correct
80 Correct 147 ms 15016 KB Output is correct
81 Correct 162 ms 15284 KB Output is correct
82 Correct 176 ms 15524 KB Output is correct
83 Correct 153 ms 13744 KB Output is correct
84 Correct 288 ms 18036 KB Output is correct
85 Correct 75 ms 19884 KB Output is correct
86 Correct 68 ms 13684 KB Output is correct
87 Correct 108 ms 13748 KB Output is correct
88 Correct 150 ms 13744 KB Output is correct
89 Correct 121 ms 13744 KB Output is correct
90 Correct 147 ms 14092 KB Output is correct
91 Correct 84 ms 13408 KB Output is correct
92 Correct 117 ms 13608 KB Output is correct
93 Correct 145 ms 13636 KB Output is correct
94 Correct 183 ms 15536 KB Output is correct
95 Correct 219 ms 18964 KB Output is correct
96 Correct 105 ms 18096 KB Output is correct
97 Correct 104 ms 15500 KB Output is correct
98 Correct 113 ms 15536 KB Output is correct
99 Correct 127 ms 15476 KB Output is correct
100 Correct 151 ms 15664 KB Output is correct
101 Correct 146 ms 15504 KB Output is correct
102 Correct 163 ms 15500 KB Output is correct
103 Correct 173 ms 15792 KB Output is correct
104 Correct 126 ms 15536 KB Output is correct
105 Correct 153 ms 15532 KB Output is correct
106 Correct 188 ms 15396 KB Output is correct
107 Correct 111 ms 18596 KB Output is correct
108 Correct 182 ms 15272 KB Output is correct
109 Correct 196 ms 15364 KB Output is correct
110 Correct 188 ms 15436 KB Output is correct
111 Correct 191 ms 15540 KB Output is correct
112 Correct 190 ms 15640 KB Output is correct
113 Correct 183 ms 15240 KB Output is correct
114 Correct 191 ms 15388 KB Output is correct
115 Correct 181 ms 15228 KB Output is correct
116 Correct 185 ms 15288 KB Output is correct