# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782552 |
2023-07-14T05:04:34 Z |
Cookie |
Joker (BOI20_joker) |
C++14 |
|
316 ms |
27440 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;
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();
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; break;
}
}
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; break;
}
}
to[l] = res;
dsu.to_last();
solve(mid + 1, r, res, candr);
dsu.to_last();
for(int i = 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);
}
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()':
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();
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
89 | auto [u, v] = edge[i];
| ^
Joker.cpp:100:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
100 | auto [u, v] = edge[res];
| ^
Joker.cpp:112:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
112 | auto [u, v] = edge[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
3 ms |
4952 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
3 ms |
4952 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
152 ms |
16968 KB |
Output is correct |
4 |
Correct |
316 ms |
27440 KB |
Output is correct |
5 |
Incorrect |
93 ms |
21320 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
3 ms |
4952 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
3 ms |
4952 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
3 ms |
4952 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |