답안 #1010178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010178 2024-06-28T12:41:08 Z LCJLY Trampoline (info1cup20_trampoline) C++14
100 / 100
1041 ms 117220 KB
#include <bits/stdc++.h>
using namespace std;
	
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef array<int,3>pi2;

vector<int>adj[200005];
bool visited[200005];
int two[22][200005];

void dfs(int index, int par){
	for(int x=0;x<20;x++){
		two[x+1][index]=two[x][two[x][index]];
	}
	visited[index]=true;
	for(auto it:adj[index]){
		if(it==par) continue;
		two[0][it]=index;
		dfs(it,index);
	}
}

void solve(){	
	int n,m,k;
	cin >> n >> m >> k;
	
	pii arr[k];
	map<int,vector<int>>mp;
	for(int x=0;x<k;x++){
		cin >> arr[x].first >> arr[x].second;
		mp[arr[x].first].push_back(arr[x].second);
	}
	
	int ptr=1;
	map<pii,int>mp2;
	unordered_map<int,pii>hash;
	
	for(auto &it:mp){
		sort(it.second.begin(),it.second.end());
		for(auto it2:it.second){
			hash[ptr]={it.first,it2};
			//cout << it.first << " " << it2 << " " << ptr << " check" << endl;
			mp2[{it.first,it2}]=ptr++;
		}
	}
	
	for(auto it:mp){
		int nxt=it.first+1;
		if(mp.find(nxt)!=mp.end()){
			for(auto hold:it.second){
				int index=lower_bound(mp[nxt].begin(),mp[nxt].end(),hold)-mp[nxt].begin();
				if(index<(int)mp[nxt].size()){
					adj[mp2[{it.first,hold}]].push_back(mp2[{nxt,mp[nxt][index]}]);
					adj[mp2[{nxt,mp[nxt][index]}]].push_back(mp2[{it.first,hold}]);
				}
			}
		}
	}
	
	//for(auto it:mp2){
		//show3(a,it.first.first,b,it.first.second,index,it.second);
	//}
	
	auto cur=mp.end();
	while(cur!=mp.begin()){
		cur--;
		int sz=cur->second.size();
		for(int y=sz-1;y>=0;y--){
			int index=mp2[{cur->first,cur->second[y]}];
			if(visited[index]) continue;
			//show(index,index);
			dfs(index,-1);
		}
	}
	
	int q;
	cin >> q;
	
	pii st,ed;
	
	for(int x=0;x<q;x++){
		cin >> st.first >> st.second >> ed.first >> ed.second;
		
		if(st.first==ed.first&&st.second<=ed.second){
			cout << "Yes\n";
			continue;
		}
		else if(st.first>ed.first){
			cout << "No\n";
			continue;
		}
		
		//go to nearest green
		int index=lower_bound(mp[st.first].begin(),mp[st.first].end(),st.second)-mp[st.first].begin();
		if(index>=(int)mp[st.first].size()){
			cout << "No\n";
			continue;
		}
		//show2(x,x,bruh,mp[st.first][index]);
		int take=mp2[{st.first,mp[st.first][index]}];
		
		for(int y=19;y>=0;y--){
			if(two[y][take]==0) continue;
			if(hash[two[y][take]].first<ed.first){
				//show(hash,hash[two[y][take]].first);
				take=two[y][take];
			}
		}
		
		if(hash[take].first+1==ed.first&&hash[take].second<=ed.second){
			cout << "Yes\n";
		}
		else cout << "No\n";
	}
	
	
	
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	//freopen("in.txt","w",stdout);
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 31580 KB 200 token(s): yes count is 21, no count is 179
2 Correct 10 ms 31636 KB 200 token(s): yes count is 70, no count is 130
3 Correct 9 ms 33116 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 79412 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 237 ms 79480 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 221 ms 77692 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 237 ms 79480 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 441 ms 90072 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 453 ms 90780 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 450 ms 89136 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 554 ms 89484 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 597 ms 89400 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 737 ms 98388 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 30812 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 11 ms 30812 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 11 ms 31064 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 10 ms 30908 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 13 ms 31068 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 10 ms 30812 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 894 ms 100136 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 743 ms 91892 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 511 ms 89212 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1041 ms 117220 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 637 ms 99856 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 495 ms 90940 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 481 ms 90828 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 500 ms 88868 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 864 ms 98336 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 863 ms 98424 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 952 ms 107640 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 467 ms 90328 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 455 ms 90084 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 580 ms 89464 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 474 ms 89320 KB 200000 token(s): yes count is 129674, no count is 70326