답안 #1028107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028107 2024-07-19T13:44:44 Z vjudge1 Trampoline (info1cup20_trampoline) C++17
11 / 100
1045 ms 93504 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 600100
#define M 32
#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<int> adj[N], comprez;
vector<pair<int,int>> ikinci;
int gittik[N];
void dfs(int x,int a,int b){
	if(x==-1)return;
	if(gittik[x])return ;
	gittik[x]=1;
	lca[x][0]=x;
	pair<int,int> pa={a+1,b};

	int yeni=(upper_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin());
	if(yeni==ikinci.size()){
		lca[x][1]=x;
		return;
	}
	if(ikinci[yeni].f==a+1&&gittik[yeni]==0){
		lca[x][1]=yeni;
		dfs(yeni,a+1,ikinci[yeni].s);
		return;
	}

	lca[x][1]=x;
}
void doldur(){
	for(int i=2;i<M;i++){
		for(int j=0;j<ikinci.size();j++){
			lca[j][i]=lca[lca[j][i-1]][i-1];
		}
	}
	//cout<<lca[0][0]<<" "<<lca[0][1]<<"  "<<lca[1][0]<<" "<<lca[1][1]<<endl;
}
int qua(int x,int y,int a,int b){
	a--;
	int kim=(lower_bound(comprez.begin(),comprez.end(),x)-comprez.begin());
	if(kim==comprez.size()||comprez[kim]!=x)return 0;
		
	int yer=(lower_bound(adj[kim].begin(),adj[kim].end(),y)-adj[kim].begin());
	if(yer==adj[kim].size()) return 0;

	pair<int,int> pa={x,adj[kim][yer]};
	int node=lower_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin();

	int l=0,r=1000000000;
	while(l<=r){
		int mid=(l+r)/2;
		int yedek=node;
		for(int i=0;i<M;i++){
			if((mid&(1<<i))){
				yedek=lca[yedek][i];
			}
		}
		x=ikinci[yedek].f, y=ikinci[yedek].s;
		//cout<<yedek<<" "<<x<<" "<<y<<"   "<<l<<" "<<r<<" "<<mid<<endl;
		if(x==a){
			if(y<=b)return 1;
			return 0;
		}
		if(x>=a){
			r=mid-1;
		}
		else l=mid+1;
	}
	return 0;
}
void solve(){
	int r,c,n;cin>>r>>c>>n;
	vector<pair<int,int>> v;
	vector<int> yedek;
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		v.pb({b,a});
		yedek.pb(a);yedek.pb(b);
		//yedek.pb(a+1);
		ikinci.pb({a,b});
		//ikinci.pb({a+1,b});
	}
	sort(v.begin(),v.end());
	sort(yedek.begin(),yedek.end());
	sort(ikinci.begin(),ikinci.end());
	comprez.pb(yedek[0]);
	for(int i=1;i<n*2;i++){
		if(yedek[i]!=yedek[i-1])comprez.pb(yedek[i]);
	}

	for(auto u:v){
		int yer=u.s;
		int kim=lower_bound(comprez.begin(),comprez.end(),yer)-comprez.begin();
		adj[kim].pb(u.f);
	}
	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){
			if(y<=b)cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
			continue;
		}
		if(x>a||y>b){
			cout<<"No"<<endl;
			continue;
		}
		int ok=qua(x,y,a,b);
		if(ok)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}


}


signed main(){
	lalala;
	solve();
	
}

Compilation message

trampoline.cpp: In function 'void dfs(long long int, long long int, long long int)':
trampoline.cpp:29:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  if(yeni==ikinci.size()){
      |     ~~~~^~~~~~~~~~~~~~~
trampoline.cpp: In function 'void doldur()':
trampoline.cpp:43:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int j=0;j<ikinci.size();j++){
      |               ~^~~~~~~~~~~~~~
trampoline.cpp: In function 'long long int qua(long long int, long long int, long long int, long long int)':
trampoline.cpp:52:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  if(kim==comprez.size()||comprez[kim]!=x)return 0;
      |     ~~~^~~~~~~~~~~~~~~~
trampoline.cpp:55:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  if(yer==adj[kim].size()) return 0;
      |     ~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 17368 KB expected YES, found NO [5th token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 172 ms 80280 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 526 ms 92308 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 576 ms 92684 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 561 ms 91668 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 674 ms 91672 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 666 ms 91796 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 777 ms 92980 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 16720 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1045 ms 93504 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -