Submission #675241

# Submission time Handle Problem Language Result Execution time Memory
675241 2022-12-27T03:24:48 Z TranGiaHuy1508 Trampoline (info1cup20_trampoline) C++17
0 / 100
396 ms 28828 KB
#include <bits/stdc++.h>
using namespace std;

void main_program();

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	main_program();
}

int R, C, n, q;
vector<pair<int, int>> inp;
map<int, vector<pair<int, int>>> mp;
int nxt[21][200'005];

void main_program(){
	cin >> R >> C >> n;

	inp.resize(n+1);

	for (int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		inp[i+1] = {a, b};
		mp[a].emplace_back(b, i+1);
	}

	for (int i = 0; i <= n; i++) nxt[0][i] = 0;

	for (auto it = mp.rbegin(); it != mp.rend(); it++){
		auto [x, vy] = *it;
		if (!mp.count(x+1)) continue;
		for (auto [y, i]: vy){
			auto it2 = lower_bound(mp[x+1].begin(), mp[x+1].end(), make_pair(y, -1));
			if (it2 == mp[x+1].end()) continue;
			auto [x2, j] = *it2;

			nxt[0][i] = j;
		}
	}

	for (int lg = 1; lg < 21; lg++){
		for (int i = 0; i <= n; i++){
			nxt[lg][i] = nxt[lg-1][nxt[lg-1][i]];
		}
	}

	cin >> q;

	for (int qr = 0; qr < q; qr++){
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		if (x1 > x2){
			cout << "No\n";
			continue;
		}
		if (x1 == x2){
			if (y1 <= y2) cout << "Yes\n";
			else cout << "No\n";
			continue;
		}
		if (y1 > y2){
			cout << "No\n";
			continue;
		}

		int D = x2 - x1 - 1;

		int crr = 0;
		if (mp.count(x1)){
			auto it = lower_bound(mp[x1].begin(), mp[x1].end(), make_pair(y1, -1));
			if (it != mp[x1].end()){
				crr = (*it).second;
			}
		}

		for (int lg = 20; lg >= 0; lg--){
			if ((D >> lg) & 1) crr = nxt[lg][crr];
		}

		if (!crr) cout << "No\n";
		else{
			if (inp[crr].first == x2 - 1 && inp[crr].second <= y2) cout << "Yes\n";
			else cout << "No\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1364 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 21436 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 150 ms 21488 KB expected YES, found NO [4th token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 980 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 28828 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -