This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1000 * 1000 + 7;
int n, q;
vector<int> ed[N], red[N];
int p[N], k[N], cnt[N];
bool answer;
bool Chk(int a, int b, int r)
{
if(r == 0) return false;
return !(((1<<r) & a) ^ ((1<<r) & b));
}
void Upd(int v)
{
if(p[v] > k[v] || (v >= q && p[v] >= k[v])) answer = true;
//cerr << "U: " << v << " " << p[v] << " " << k[v] << " " << answer << "\n";
if(answer) return;
if(!Chk(p[v], k[v], cnt[v])) return;
while(Chk(p[v], k[v], cnt[v])) --cnt[v];
for(int i = 0; i < (int)ed[v].size(); ++i)
if(p[ed[v][i]] < p[v])
{
p[ed[v][i]] = p[v];
Upd(ed[v][i]);
}
for(int i = 0; i < (int)red[v].size(); ++i)
if(k[red[v][i]] > k[v])
{
k[red[v][i]] = k[v];
Upd(red[v][i]);
}
}
void init(int _n, int _k)
{
n = _n; q = _k;
for(int i = 0; i < q; ++i)
{
p[i] = i + 1; k[i] = i + 1;
}
for(int i = q; i < n; ++i)
{
p[i] = 0;
k[i] = q + 1;
cnt[i] = 20;
}
for(int i = 0; i < n; ++i)
while(Chk(p[i], k[i], cnt[i]))
--cnt[i];
}
int add_teleporter(int u, int v)
{
if(u == v && v < q) return 1;
//cerr << "EDGE: " << u << " " << v << "\n";
ed[u].pb(v); red[v].pb(u);
if(p[v] < p[u])
{
p[v] = p[u];
Upd(v);
}
if(k[u] > k[v])
{
k[u] = k[v];
Upd(u);
}
if(answer)
return 1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |