답안 #387586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387586 2021-04-09T02:46:42 Z casperwang Trampoline (info1cup20_trampoline) C++14
100 / 100
1152 ms 54204 KB
#include <bits/stdc++.h>
#define pb emplace_back
#define All(x) x.begin(), x.end()
#define pii pair<int,int>
#define ff first
#define ss second
#define y1 y_1
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 200000;
const int L = 30;
int N, R, C, T;
pii pts[MAXN+1];
int x1, y1, x2, y2;
map <int, set<pii>> arr;
int anc[MAXN+1][L];

void build() {
	for (int i = 1; i <= N; i++) {
		auto [x, y] = pts[i];
		arr[x].insert(pii(y, i));
	}
	for (int i = 1; i <= N; i++) {
		auto [x, y] = pts[i];
		if (!arr.count(x-1)) continue;
		auto it = arr[x-1].upper_bound(pii(y, N+1));
		if (it != arr[x-1].begin()) {
			anc[i][0] = prev(it)->ss;
		}
	}
	for (int i = 1; i < L; i++) {
		for (int j = 1; j <= N; j++) {
			anc[j][i] = anc[anc[j][i-1]][i-1];
		}
	}
}

bool solve(int x1, int y1, int x2, int y2) {
	if (x1 == x2 && y1 <= y2) return true;
	if (y1 > y2 || x1 > x2) return false;
	if (!arr.count(x2-1)) return false;
	auto it = arr[x2-1].upper_bound(pii(y2, N+1));
	if (it == arr[x2-1].begin()) return false;
	int now = prev(it)->ss;
	int K = x2 - x1 - 1;
	for (int i = 1; i <= K; i *= 2) {
		if (i & K) now = anc[now][__lg(i)];
	}
	return now && pts[now].ss >= y1;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> R >> C >> N;
	for (int i = 1; i <= N; i++) {
		auto &[x, y] = pts[i];
		cin >> x >> y;
	}
	build();
	cin >> T;
	for (int i = 1; i <= T; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		cout << (solve(x1, y1, x2, y2) ? "Yes" : "No") << '\n';
	}
}

Compilation message

trampoline.cpp: In function 'void build()':
trampoline.cpp:24:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |   auto [x, y] = pts[i];
      |        ^
trampoline.cpp:28:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |   auto [x, y] = pts[i];
      |        ^
trampoline.cpp: In function 'int main()':
trampoline.cpp:60:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |   auto &[x, y] = pts[i];
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1740 KB 200 token(s): yes count is 21, no count is 179
2 Correct 11 ms 1996 KB 200 token(s): yes count is 70, no count is 130
3 Correct 9 ms 1560 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 437 ms 34976 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 415 ms 34920 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 455 ms 34756 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 484 ms 34984 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 665 ms 35396 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 703 ms 35348 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 748 ms 35396 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 760 ms 35556 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 791 ms 35592 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 901 ms 41708 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1100 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 8 ms 1220 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 9 ms 1680 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 10 ms 1132 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 9 ms 1356 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 7 ms 1200 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 952 ms 43036 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 841 ms 37316 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 618 ms 35368 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1152 ms 54204 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 859 ms 42340 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 561 ms 35384 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 563 ms 35416 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 673 ms 35388 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 955 ms 41792 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 979 ms 41792 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1092 ms 47956 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 447 ms 35484 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 505 ms 35444 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 752 ms 35652 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 619 ms 35440 KB 200000 token(s): yes count is 129674, no count is 70326