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>
using namespace std;
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, k;
vector<int> Adj[N], Adj2[N];
int mn[N], mx[N];
void init(int n_, int k_){
n = n_, k = k_;
for(int i = 0; i < n; i++){
mn[i] = oo, mx[i] = -oo;
}
for(int i = 0; i <= (k - 2); i++){
Adj[i].pb(i + 1);
Adj2[i + 1].pb(i);
}
for(int i = 0; i < k; i++){
if(i >= 1) mx[i] = i - 1;
if(i != (k - 1)) mn[i] = i + 1;
}
}
//int mx[N], mn[N];// have path from mx[] -> x, x -> mn[]
bool ck = 0;
//vector<int> Adj2[N];
void upd1(int u){
ck |= (mx[u] >= mn[u]);
for(auto v : Adj[u]){
if(mx[v] < mx[u]){
mx[v] = mx[u];
upd1(v);
}
}
}
void upd2(int u){
ck |= (mx[u] >= mn[u]);
for(auto v : Adj2[u]){
if(mn[v] > mn[u]){
mn[v] = mn[u];
upd2(v);
}
}
}
int add_teleporter(int x, int y){
Adj[x].pb(y);
Adj2[y].pb(x);
if(x < k && y < k){
if(x >= y) ck = 1;
}
else if(x < k){
mx[y] = max(mx[y], x);
}
else if(y < k){
mn[y] = min(mn[y], x);
}
upd1(x);
upd1(y);
upd2(x);
upd2(y);
// for(int i = 0; i < n; i++) cout << mn[i] << " " << mx[i] << "\n";
return ck;
}
Compilation message (stderr)
game.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
| ~~~~~^~~
# | 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... |