Submission #387582

# Submission time Handle Problem Language Result Execution time Memory
387582 2021-04-09T02:36:40 Z casperwang Trampoline (info1cup20_trampoline) C++14
73 / 100
887 ms 28100 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 = 20;
int N, R, C, T;
pii pts[MAXN+1];
int x1, y1, x2, y2;
map <int, vector<pii>> arr;
int anc[MAXN+1][L];

void build() {
	for (int i = 1; i <= N; i++) {
		auto [x, y] = pts[i];
		arr[x].pb(y, i);
	}
	for (auto &[x, v] : arr)  {
		sort(All(v));
	}
	for (int i = 1; i <= N; i++) {
		auto [x, y] = pts[i];
		if (arr[x-1].size()) {
			auto it = upper_bound(All(arr[x-1]), 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[x2-1].size()) return false;
	auto it = upper_bound(All(arr[x2-1]), 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:27:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |  for (auto &[x, v] : arr)  {
      |             ^
trampoline.cpp:31:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |   auto [x, y] = pts[i];
      |        ^
trampoline.cpp: In function 'int main()':
trampoline.cpp:64:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |   auto &[x, y] = pts[i];
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1228 KB 200 token(s): yes count is 21, no count is 179
2 Correct 7 ms 1356 KB 200 token(s): yes count is 70, no count is 130
3 Correct 5 ms 972 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 256 ms 20548 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 209 ms 20524 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 181 ms 19980 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 198 ms 20548 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 284 ms 20372 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 299 ms 20116 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 322 ms 20440 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 420 ms 20912 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 394 ms 20932 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 717 ms 26752 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 7 ms 844 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 7 ms 844 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 10 ms 1700 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 6 ms 844 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 9 ms 972 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 9 ms 852 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 887 ms 28100 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 634 ms 23048 KB 200000 token(s): yes count is 161254, no count is 38746
3 Incorrect 327 ms 20548 KB expected NO, found YES [4613th token]
4 Halted 0 ms 0 KB -