#include <bits/stdc++.h>
#include "game.h"
using namespace std;
#define REP(i, j, k) for (int i = (j); i < (k); i++)
#define RREP(i, j, k) for (int i = (j); i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int MAXN = 300005;
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
int n, k;
vi adj[MAXN], radj[MAXN];
ii mn[MAXN], mx[MAXN];
vi stk, rstk;
bool vis[MAXN];
bool ans;
void init(int N, int K) {
n = N; k = K;
REP (i, 0, k) {
mn[i] = mx[i] = {i, i};
}
int lo = -1, hi = k, mid = lo + hi >> 1;
REP (i, k, n) {
mn[i] = {mid + 1, hi}; mx[i] = {lo, mid};
}
}
void dfs(int u) {
if (u < k) {
return;
}
if (mn[u].SE <= mx[u].FI) {
ans = 1;
return;
}
for (int v : adj[u]) {
if (mx[u].FI > mx[v].SE) {
if (mn[v].SE <= mx[u].FI) {
ans = 1;
return;
}
mx[v] = mn[v];
dfs(v);
}
}
stk.pb(u);
}
void rdfs(int u) {
if (u < k) {
return;
}
if (mn[u].SE <= mx[u].FI) {
ans = 1;
return;
}
for (int v : radj[u]) {
if (mn[u].SE < mn[v].FI) {
if (mn[u].SE <= mx[v].FI) {
ans = 1;
return;
}
mn[v] = mx[v];
rdfs(v);
}
}
rstk.pb(u);
}
int add_teleporter(int u, int v) {
if (u < k && v < k) {
if (v <= u) {
return 1;
} else {
return 0;
}
}
while (1) {
stk.clear();
rstk.clear();
if (mx[u].FI > mx[v].SE) {
if (mn[v].SE <= mx[u].FI) {
ans = 1;
break;
}
mx[v] = mn[v];
dfs(v);
}
if (mn[v].SE < mn[u].FI) {
if (mn[v].SE <= mx[u].FI) {
ans = 1;
break;
}
mn[u] = mx[u];
rdfs(u);
}
if (stk.empty() && rstk.empty()) {
break;
}
vi tstk;
REP (i, 0, SZ(stk)) {
tstk.pb(stk[i]);
}
RREP (i, SZ(rstk) - 1, 0) {
tstk.pb(rstk[i]);
}
for (int i : tstk) {
vis[i] = 0;
}
for (int u : tstk) {
if (vis[u]) {
continue;
}
vis[u] = 1;
int lo = mn[u].FI, hi = mn[u].SE, mid = lo + hi >> 1;
for (int v : adj[u]) {
if (lo <= mn[v].FI && mn[v].SE <= mid) {
mn[u] = {lo, mid};
break;
}
}
if (mn[u].SE != mid) {
mn[u] = {mid + 1, hi};
}
}
tstk.clear();
REP (i, 0, SZ(rstk)) {
tstk.pb(rstk[i]);
}
RREP (i, SZ(stk) - 1, 0) {
tstk.pb(stk[i]);
}
for (int i : tstk) {
vis[i] = 0;
}
for (int u : tstk) {
if (vis[u]) {
continue;
}
vis[u] = 1;
int lo = mx[u].FI, hi = mx[u].SE, mid = lo + hi >> 1;
for (int v : radj[u]) {
if (mid + 1 <= mx[v].FI && mx[v].SE <= hi) {
mx[u] = {mid + 1, hi};
break;
}
}
if (mx[u].FI != mid + 1) {
mx[u] = {lo, mid};
}
}
}
adj[u].pb(v);
radj[v].pb(u);
return ans;
}
Compilation message
game.cpp: In function 'void init(int, int)':
game.cpp:46:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int lo = -1, hi = k, mid = lo + hi >> 1;
| ~~~^~~~
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:139:56: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
139 | int lo = mn[u].FI, hi = mn[u].SE, mid = lo + hi >> 1;
| ~~~^~~~
game.cpp:165:56: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
165 | int lo = mx[u].FI, hi = mx[u].SE, mid = lo + hi >> 1;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14324 KB |
Output is correct |
3 |
Correct |
10 ms |
14308 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14404 KB |
Output is correct |
6 |
Correct |
9 ms |
14416 KB |
Output is correct |
7 |
Correct |
10 ms |
14384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14324 KB |
Output is correct |
3 |
Correct |
10 ms |
14308 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14404 KB |
Output is correct |
6 |
Correct |
9 ms |
14416 KB |
Output is correct |
7 |
Correct |
10 ms |
14384 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14408 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14368 KB |
Output is correct |
13 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14324 KB |
Output is correct |
3 |
Correct |
10 ms |
14308 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14404 KB |
Output is correct |
6 |
Correct |
9 ms |
14416 KB |
Output is correct |
7 |
Correct |
10 ms |
14384 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14408 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14368 KB |
Output is correct |
13 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14324 KB |
Output is correct |
3 |
Correct |
10 ms |
14308 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14404 KB |
Output is correct |
6 |
Correct |
9 ms |
14416 KB |
Output is correct |
7 |
Correct |
10 ms |
14384 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14408 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14368 KB |
Output is correct |
13 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14324 KB |
Output is correct |
3 |
Correct |
10 ms |
14308 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14404 KB |
Output is correct |
6 |
Correct |
9 ms |
14416 KB |
Output is correct |
7 |
Correct |
10 ms |
14384 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14408 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14368 KB |
Output is correct |
13 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |