# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782560 |
2023-07-14T05:11:21 Z |
Cookie |
Joker (BOI20_joker) |
C++14 |
|
311 ms |
23832 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(int s){
while(past_sz.size() != s)rollback();
}
};
DSU dsu;
int n, m, q;
vt<pii>edge;
int to[mxn + 1];
void input(){
cin >> n >> m >> q;
edge.pb({0, 1});
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v;
edge.pb({u, v});
}
}
void solve(int l, int r, int candl, int candr){
if(l > r)return;
if(candl == candr){
for(int i = l; i <= r; i++)to[i] = candl;
return;
}
dsu.save();
int check1 = dsu.past_sz.size();
bool ok = 1;
int mid = (l + r) >> 1;
for(int i = l; i <= mid; i++){
auto [u, v] = edge[i];
dsu.unon(u << 1, v << 1 | 1); dsu.unon(v << 1, u << 1 | 1);
if(dsu.check(u << 1, u << 1 | 1) || dsu.check(v << 1, v << 1 | 1)){
ok = 0;
}
}
int check2 = dsu.past_sz.size();
dsu.save();
int res = candr;
while(res && ok){
res--;
if(res == 0)break;
auto [u, v] = edge[res];
dsu.unon(u << 1, v << 1 | 1); dsu.unon(v << 1, u << 1 | 1);
if(dsu.check(u << 1, u << 1 | 1) || dsu.check(v << 1, v << 1 | 1)){
ok = 0;
}
}
to[l] = res;
dsu.to_last(check2);
solve(mid + 1, r, res, candr);
dsu.to_last(check1);
for(int i = max(1, res); i < candr; i++){
auto [u, v] = edge[i];
dsu.unon(u << 1, v << 1 | 1); dsu.unon(v << 1, u << 1 | 1);
}
solve(l, mid - 1, candl, res);
dsu.to_last(check1);
}
void process(){
dsu.init();
solve(0, m, 0, m + 1);
while(q--){
int l, r; cin >> l >> r;
cout << ((to[l - 1] > 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(int)':
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 'int' [-Wsign-compare]
62 | while(past_sz.size() != s)rollback();
| ~~~~~~~~~~~~~~~^~~~
Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:90:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
90 | auto [u, v] = edge[i];
| ^
Joker.cpp:102:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
102 | auto [u, v] = edge[res];
| ^
Joker.cpp:114:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
114 | auto [u, v] = edge[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
151 ms |
16048 KB |
Output is correct |
4 |
Correct |
311 ms |
23832 KB |
Output is correct |
5 |
Incorrect |
88 ms |
17288 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |