Submission #1028711

# Submission time Handle Problem Language Result Execution time Memory
1028711 2024-07-20T07:27:43 Z DangerNoodle7591 Trampoline (info1cup20_trampoline) C++17
100 / 100
736 ms 56992 KB
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define int long long int
#define endl '\n'
#define N 200100
#define M 30
#define big 2147483647 
#define bigg 9223372036854775807 
#define pb push_back
#define p push
#define ins insert
#define f first
#define s second

int lca[N][M];
vector<pair<int,int>> ikinci;
int gittik[N];
void dfs(int x,int a,int b){
	if(gittik[x])return ;
	gittik[x]=1;
	lca[x][0]=x;
	pair<int,int> pa={a+1,b};
	int yeni=(lower_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin());

	if(yeni!=(int)ikinci.size()&&ikinci[yeni].f==a+1){
		lca[x][0]=yeni;
		if(gittik[yeni]==0)dfs(yeni,a+1,ikinci[yeni].s);
		return;
	}
}
void doldur(){
	for(int i=1;i<M;i++){
		for(int j=0;j<(int)ikinci.size();j++){
			lca[j][i]=lca[lca[j][i-1]][i-1];
		}
	}
}
int qua(int x,int y,int a,int b){
	a--;
	pair<int,int> pa={x,y};
	int node=lower_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin();
	if(node==(int)ikinci.size()||ikinci[node].f!=x) return 0;
	//cout<<a-x<<"  "<<ikinci[node].f<<" "<<ikinci[node].s<<endl;
	int fark=a-x;

	for(int i=0;i<M;i++){
		if((fark&(1<<i))){
			node=lca[node][i];
		}
	}
	x=ikinci[node].f, y=ikinci[node].s;
	//cout<<x<<" "<<y<<endl;
	if(x==a&&y<=b)return 1;
	return 0;
}

signed main(){
	//lalala;
	int r,c,n;cin>>r>>c>>n;
	vector<pair<int,int>> v;
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		v.pb({b,a});
		ikinci.pb({a,b});
	}
	sort(v.begin(),v.end());
	sort(ikinci.begin(),ikinci.end());
	for(int i=0;i<(int)ikinci.size();i++){
		if(gittik[i])continue;
		dfs(i,ikinci[i].f,ikinci[i].s);
	}
	doldur();
	int q;cin>>q;
	while(q--){
		int x,y,a,b;cin>>x>>y>>a>>b;
		if(x>a||y>b){
			cout<<"No"<<endl;
			continue;
		}
		if(x==a){
			cout<<"Yes"<<endl;
			continue;
		}
		int ok=qua(x,y,a,b);
		if(ok)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5332 KB 200 token(s): yes count is 21, no count is 179
2 Correct 6 ms 5076 KB 200 token(s): yes count is 70, no count is 130
3 Correct 5 ms 4700 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 148 ms 56308 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 148 ms 56040 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 143 ms 55464 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 146 ms 56220 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 680 ms 55976 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 608 ms 56468 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 605 ms 56472 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 700 ms 56792 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 583 ms 56992 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 590 ms 56232 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4696 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 16 ms 4700 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 15 ms 4912 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 13 ms 4700 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 15 ms 4900 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 14 ms 4908 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 736 ms 56824 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 670 ms 56732 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 629 ms 55960 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 711 ms 56988 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 625 ms 56484 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 640 ms 56768 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 652 ms 56120 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 585 ms 56488 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 594 ms 56228 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 691 ms 56272 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 730 ms 56484 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 558 ms 55972 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 585 ms 56888 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 678 ms 56592 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 585 ms 56232 KB 200000 token(s): yes count is 129674, no count is 70326