답안 #884602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884602 2023-12-07T18:08:55 Z LinkedArray Trampoline (info1cup20_trampoline) C++17
100 / 100
416 ms 38864 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 2e5;

pair<int, int> green[MAXN + 5];
int depth[MAXN + 5];
vector<vector<int>> up(MAXN + 5, vector<int>(log2(MAXN) + 5));

int binLift (int node, int k, int log) {
	int i;
	
	for (i = 0; i < log; i++) {
		if (k & (1 << i)) {
			node = up[node][i];
		}
	}
	
	return node;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int r, c, n, q, x1, y1, x2, y2, st, dr, mij, log, i, j;
	
	cin >> r >> c >> n;
	for (i = 1; i <= n; i++) {
		cin >> green[i].first >> green[i].second;
	}
	sort(green + 1, green + 1 + n);
	
	log = 0;
	while ((1 << log) <= n) {
		log++;
	}
	
	for (i = n; i >= 1; i--) {
		// binary search
		pair<int, int> target = {green[i].first + 1, green[i].second};
		st = 1, dr = n;
		while (st <= dr) {
			mij = (st + dr) / 2;
			
			if (green[mij] >= target) {
				dr = mij - 1;
			} else {
				st = mij + 1;
			}
		}
		// ans = (dr == n ? 0 : dr + 1);
		
		// -----------
		int ans = (dr == n ? 0 : dr + 1);
		bool found = (green[ans].first == target.first);
		
		if (found) {
			depth[i] = depth[ans] + 1;
			
			up[i][0] = ans;
			for (j = 1; j < log; j++) {
				up[i][j] = up[ up[i][j - 1] ][j - 1];
			}
		}
	}	
	
	
	cin >> q;
	for (i = 1; i <= q; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		
		if (x1 > x2 || y1 > y2) {
			cout << "No\n";
		} else {
			if (x1 == x2) {
				cout << "Yes\n";
			} else {
				// query logic
				
				// binary search
				pair<int, int> target = {x1, y1};
				st = 1, dr = n;
				while (st <= dr) {
					mij = (st + dr) / 2;
					
					if (green[mij] >= target) {
						dr = mij - 1;
					} else {
						st = mij + 1;
					}
				}
				// ans = (dr == n ? 0 : dr + 1);
				
				// -----------
				int ans = (dr == n ? 0 : dr + 1);
				
				if (green[ans].first > x1 || green[ans].second > y2) {
					cout << "No\n";
				} else {
					int linDif = (x2 - x1 - 1);
					
					if (depth[ans] < linDif) {
						cout << "No\n";
					} else {
						int ans_pos = binLift(ans, linDif, log);
						
						if (green[ans_pos].first <= x2 && green[ans_pos].second <= y2) {
							cout << "Yes\n";
						} else {
							cout << "No\n";
						}
					}
				}
			}
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25948 KB 200 token(s): yes count is 21, no count is 179
2 Correct 17 ms 26088 KB 200 token(s): yes count is 70, no count is 130
3 Correct 16 ms 25948 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 26104 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 81 ms 28076 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 80 ms 27732 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 79 ms 27988 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 26792 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 174 ms 26756 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 168 ms 26968 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 173 ms 26868 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 185 ms 26964 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 175 ms 26960 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 25948 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 19 ms 26204 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 17 ms 26200 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 17 ms 26204 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 18 ms 26204 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 18 ms 26204 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 26964 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 286 ms 38532 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 205 ms 38484 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 322 ms 38480 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 218 ms 38484 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 216 ms 38864 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 245 ms 38636 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 219 ms 38480 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 358 ms 38616 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 377 ms 38524 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 416 ms 38776 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 203 ms 38512 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 205 ms 38712 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 324 ms 38696 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 212 ms 38648 KB 200000 token(s): yes count is 129674, no count is 70326