Submission #342734

# Submission time Handle Problem Language Result Execution time Memory
342734 2021-01-02T17:06:31 Z ogibogi2004 Trampoline (info1cup20_trampoline) C++14
100 / 100
1587 ms 89308 KB
#include<bits/stdc++.h>
using namespace std;
#define x1 sdfds
#define y1 sdfdfds
#define x2 sdffdsds
#define y2 sdfdds
#define ll int
const ll MAXN=2e5+6;
struct trampoline
{
	ll x,y;
	bool operator<(trampoline const& other)const
	{
		return make_pair(x,y)<make_pair(other.x,other.y);
	}
};
set<ll>xs;
ll n,m,k;
vector<trampoline>tr;
unordered_map<ll,ll> newx;
vector<ll>xs1;
set<ll>ys[MAXN];
vector<ll>g[MAXN];
ll dp[MAXN][18];
map<pair<ll,ll>,ll> no;
bool vis[MAXN];
ll not_root[MAXN];
void dfs(ll u,ll par)
{
	dp[u][0]=par;
	vis[u]=1;
	for(auto v:g[u])
	{
		if(vis[v])continue;
		dfs(v,u);
	}
}
void precompute()
{
	for(ll j=1;j<18;j++)
	{
		for(ll i=0;i<tr.size();i++)
		{
			if(dp[i][j-1]==-1)dp[i][j]=-1;
			else dp[i][j]=dp[dp[i][j-1]][j-1];
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>k;
	for(ll i=0;i<k;++i)
	{
		ll x,y;
		cin>>x>>y;
		xs.insert(x);
		tr.push_back({x,y});
	}
	ll cnt=0;
	for(auto xd:xs)
	{
		newx[xd]=++cnt;
		xs1.push_back(xd);
	}
	for(ll i=0;i<tr.size();++i)
	{
		ys[newx[tr[i].x]].insert(tr[i].y);
		no[{newx[tr[i].x],tr[i].y}]=i;
	}
	for(ll i=0;i<tr.size();++i)
	{
		if(!newx.count(tr[i].x+1))
		{
			continue;
		}
		ll x1=newx[tr[i].x+1];
		auto xd=ys[x1].lower_bound(tr[i].y);
		if(xd==ys[x1].end())continue;
		ll nxt=no[{x1,(*xd)}];
		//cout<<"da\n";
		g[nxt].push_back(i);
		//cout<<tr[i].x<<" "<<tr[i].y<<" "<<x1<<" "<<(*xd)<<endl;
		//cout<<"* "<<nxt<<"->"<<i<<endl;
		not_root[i]=1;
	}
	for(ll i=0;i<tr.size();++i)
	{
		if(vis[i])
		{
			continue;
		}
		if(not_root[i])
		{
			continue;
		}
		dfs(i,-1);
	}
	precompute();
	/*for(ll i=0;i<tr.size();i++)
	{
		cout<<i<<"->"<<dp[i][0]<<endl;
	}
	cout<<endl;*/
	ll q;
	cin>>q;
	for(ll i=0;i<q;++i)
	{
		ll x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		if(y2<y1)
		{
			cout<<"No\n";
			continue;
		}
		if(x2<x1)
		{
			cout<<"No\n";
			continue;
		}
		if(x1==x2)
		{
			cout<<"Yes\n";
			continue;
		}
		if(!newx.count(x1))
		{
			cout<<"No\n";
			continue;
		}
		if(!newx.count(x2-1))
		{
			cout<<"No\n";
			continue;
		}
		ll xx=newx[x1];
		auto xd=ys[xx].lower_bound(y1);
		if(xd==ys[xx].end())
		{
			cout<<"No\n";
			continue;
		}
		ll u=no[{xx,(*xd)}];
		/*if(tr[u].x<x1||tr[u].y<y1)
		{
			cout<<"No\n";
			continue;
		}*/
		for(int j=17;j>=0;--j)
		{
			if(dp[u][j]==-1)continue;
			if(tr[dp[u][j]].x<x2)
			{
				u=dp[u][j];
			}
		}
		if(tr[u].x!=x2-1)
		{
			cout<<"No\n";
			continue;
		}
		if(tr[u].y>y2)
		{
			cout<<"No\n";
			continue;
		}
		cout<<"Yes\n";
		continue;
	}
return 0;
}

Compilation message

trampoline.cpp: In function 'void precompute()':
trampoline.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(ll i=0;i<tr.size();i++)
      |              ~^~~~~~~~~~
trampoline.cpp: In function 'int main()':
trampoline.cpp:68:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for(ll i=0;i<tr.size();++i)
      |             ~^~~~~~~~~~
trampoline.cpp:73:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(ll i=0;i<tr.size();++i)
      |             ~^~~~~~~~~~
trampoline.cpp:89:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(ll i=0;i<tr.size();++i)
      |             ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16364 KB 200 token(s): yes count is 21, no count is 179
2 Correct 22 ms 16620 KB 200 token(s): yes count is 70, no count is 130
3 Correct 18 ms 15980 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 652 ms 56484 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 695 ms 56604 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 637 ms 58480 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 646 ms 56760 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 812 ms 55524 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 905 ms 56832 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 937 ms 56932 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 1072 ms 57948 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 1061 ms 58044 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1251 ms 66908 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 20 ms 15468 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 20 ms 15596 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 19 ms 15852 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 19 ms 15468 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 21 ms 15852 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 19 ms 15468 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1449 ms 69468 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 1310 ms 60764 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 936 ms 57072 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1587 ms 88108 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 1112 ms 78800 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 978 ms 68836 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 959 ms 68996 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 904 ms 68708 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1381 ms 78548 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1428 ms 79352 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1552 ms 89308 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 715 ms 66916 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 775 ms 67044 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 1052 ms 69760 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 830 ms 68600 KB 200000 token(s): yes count is 129674, no count is 70326