# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042230 |
2024-08-02T17:01:28 Z |
Neco_arc |
Joker (BOI20_joker) |
C++17 |
|
79 ms |
14164 KB |
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Joker"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r)(rng);
}
int n, m, q;
int f[maxn];
struct dl { int u, v; } a[maxn];
struct DSU {
int lab[maxn], col[maxn], bad;
int *addr[6 * maxn], val[6 * maxn], top;
DSU() { memset(lab, -1, sizeof lab); }
void Add(int *a, int b) { if(*a != b) addr[++top] = a, val[top] = *a, *a = b; }
void RollBack(int Time) { while(top > Time) *addr[top] = val[top], --top; }
int get_rt(int u) {
return lab[u] < 0 ? u : get_rt(lab[u]);
}
int cl(int u) {
return lab[u] < 0 ? col[u] : (col[u] ^ cl(lab[u]));
}
void uni(int u, int v) {
int p = get_rt(u), q = get_rt(v);
int w = cl(u) == cl(v);
if(p == q) {
Add(&bad, bad | w );
return;
}
if(lab[p] > lab[q]) swap(p, q);
Add(&col[q], col[q] ^ w);
Add(&lab[p], lab[p] + lab[q]), Add(&lab[q], p);
}
} Dsu;
void DnC(int l, int r, int optL, int optR) {
if(l > r) return;
int mid = (l + r) >> 1, pos = mid + 1;
int T1 = Dsu.top;
fid(i, optR, mid + 1) Dsu.uni(a[i].u, a[i].v);
fi(i, optL, min(mid, optR)) {
if(i) Dsu.uni(a[i].u, a[i].v);
if(Dsu.bad) { pos = i; break; }
}
f[mid] = pos;
pos = min(pos, mid);
Dsu.RollBack(T1);
fi(i, pos + 1, optR) if(i) Dsu.uni(a[i].u, a[i].v);
DnC(l, mid - 1, optL, pos);
Dsu.RollBack(T1);
fi(i, optL, pos - 1) if(i) Dsu.uni(a[i].u, a[i].v);
DnC(mid + 1, r, pos, optR);
Dsu.RollBack(T1);
}
void solve()
{
cin >> n >> m >> q;
fi(i, 1, m) {
int x, y; cin >> x >> y;
a[i] = {x, y};
}
DnC(1, m, 0, m);
fi(i, 1, q) {
int l, r; cin >> l >> r;
cout << (l > f[r] ? "YES\n" : "NO\n");
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
Joker.cpp: In function 'int main()':
Joker.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
120 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Incorrect |
79 ms |
14164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |