//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "game.h"
typedef int ll;
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
using namespace std;
struct NIGGA {
vector<vector<ll>> g, rg;
vector<ll> l, r, nle;
ll n, k;
bool c = false;
NIGGA(ll nn, ll nk) {
n = nn;
k = nk;
n -= k;
ll x = 1;
while (x < k + 2) {
x *= 2;
}
nle.resize(n, x);
l.resize(n, -1);
r.resize(n, k);
g.resize(n);
rg.resize(n);
}
void upd(ll v) {
if (r[v] <= l[v] || c) {
c = true;
return;
}
if ((r[v] - l[v]) * 2 > nle[v]) {
return;
}
while ((r[v] - l[v]) * 2 <= nle[v]) {
nle[v] /= 2;
}
for (auto i : g[v]) {
assign_max(l[i], l[v]);
upd(i);
}
for (auto i : rg[v]) {
assign_min(r[i], r[v]);
upd(i);
}
}
bool check() {
return c;
}
bool get(ll& a) {
if (a < k) {
return false;
} else {
a -= k;
return true;
}
}
void add(ll a, ll b) {
bool c1 = get(a);
bool c2 = get(b);
if (c1 && c2) {
assign_max(l[b], l[a]);
g[a].push_back(b);
assign_min(r[a], r[b]);
rg[b].push_back(a);
upd(a);
upd(b);
return;
}
if (!c1 && !c2) {
if (a <= b) {
c = true;
}
return;
}
if (c2) {
assign_max(l[b], a);
upd(b);
return;
}
if (c1) {
assign_min(r[a], b);
upd(a);
return;
}
}
};
NIGGA nigger(2, 1);
void init(ll n, ll k) {
nigger = NIGGA(n, k);
}
int add_teleporter(ll u, ll v) {
nigger.add(u, v);
if (nigger.check()) {
return 1;
}
return 0;
}
#ifdef LOCAL
int main() {
ll n, m, k;
cin >> n >> m >> k;
init(n, k);
for (ll i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
cout << add_teleporter(a, b) << '\n';
}
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |