Submission #578090

# Submission time Handle Problem Language Result Execution time Memory
578090 2022-06-16T04:02:44 Z handlename Game (APIO22_game) C++17
2 / 100
8 ms 14416 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
int n,k;
vector<int> adj[300001],rev[300001];
struct node{
	node *l,*r;
	//left node stores stuff which can reach m
	//right node stores stuff which m can reach
	int s,m,e;
	unordered_set<int> stuff;
	node(int ss,int ee){
		s=ss;
		e=ee;
		m=(s+e)/2;
		for (int i=s;i<=e;i++) stuff.insert(i);
		if (s<e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
		if (s==e){
			l=new node(s,s-1);
			r=new node(e,e-1);
		}
		if (s>e){
			stuff.insert(s);
		}
	}
	bool upd(int u,int v){
		if (s>e){
			stuff.insert(u);
			stuff.insert(v);
			return false;
		}
		/*
		cout<<"update "<<s<<' '<<m<<' '<<e<<' '<<u<<' '<<v<<'\n';
		cout<<"left: ";
		for (auto i:l->stuff) cout<<i<<' ';
		cout<<'\n';
		cout<<"right: ";
		for (auto i:r->stuff) cout<<i<<' ';
		cout<<'\n';
		*/
		bool uleft=l->stuff.find(u)!=l->stuff.end();
		bool uright=r->stuff.find(u)!=r->stuff.end();
		bool vleft=l->stuff.find(v)!=l->stuff.end();
		bool vright=r->stuff.find(v)!=r->stuff.end();
		if (uleft){
			if (vleft) return l->upd(u,v);
			if (vright) return false;
			return false; //v can only reach stuff on right, u->m->right, so u->v->right useless
		}
		if (uright){
			if (vleft) return true;
			if (vright) return r->upd(u,v);
			stuff.insert(v);
			if (r->upd(u,v)) return true;
			for (auto i:adj[v]){
				if (upd(v,i)) return true;
			}
			return false;
		}
		if (vleft){
			stuff.insert(u);
			if (l->upd(u,v)) return true;
			for (auto i:rev[u]){
				if (upd(i,u)) return true;
			}
			return false;
		}
		if (vright){
			return false; //only stuff on left can reach u, left->m->v, so left->u->v useless
		}
		return false;
	}
}*root;
void init(int N,int K){
	n=N;
	k=K;
	for (int i=1;i<k;i++){
		adj[i].pb(i+1);
		rev[i+1].pb(i);
	}
	root=new node(1,k);
}
int add_teleporter(int u,int v){
	u++;
	v++;
	adj[u].pb(v);
	rev[v].pb(u);
	if (u==v && u<=k) return 1;
	if (u==v) return 0;
	return root->upd(u,v);
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 8 ms 14332 KB Output is correct
10 Incorrect 8 ms 14288 KB Wrong Answer[1]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 8 ms 14332 KB Output is correct
10 Incorrect 8 ms 14288 KB Wrong Answer[1]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 8 ms 14332 KB Output is correct
10 Incorrect 8 ms 14288 KB Wrong Answer[1]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 8 ms 14332 KB Output is correct
10 Incorrect 8 ms 14288 KB Wrong Answer[1]
11 Halted 0 ms 0 KB -