Submission #426909

# Submission time Handle Problem Language Result Execution time Memory
426909 2021-06-14T10:48:50 Z pavement Trampoline (info1cup20_trampoline) C++17
100 / 100
1530 ms 98352 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
int R, C, N, T, r1, c1, r2, c2, a[200005], b[200005], anc[200005][25];
bool in[200005];
vector<int> adj[200005];
map<ii, int> _lab;
map<int, vector<int> > vec;
 
inline int lab(int a, int b) {
	assert(_lab.find(mp(a, b)) != _lab.end());
	return _lab[mp(a, b)];
}
 
void dfs(int n, int e = -1) {
	anc[n][0] = e;
	for (int i = 1; i <= 20; i++)
		if (anc[n][i - 1] != -1) anc[n][i] = anc[anc[n][i - 1]][i - 1];
	for (auto u : adj[n]) if (u != e) dfs(u, n);
}
 
main() {
	memset(anc, -1, sizeof anc);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> R >> C >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i] >> b[i];
		vec[a[i]].pb(b[i]);
		_lab[mp(a[i], b[i])] = i;
	}
	for (auto &i : vec) sort(i.second.begin(), i.second.end());
	for (auto i : vec) {
		for (int j : i.second) {
			auto tmp = lower_bound(vec[i.first + 1].begin(), vec[i.first + 1].end(), j);
			if (tmp != vec[i.first + 1].end()) {
				adj[lab(i.first + 1, *tmp)].pb(lab(i.first, j));
				in[lab(i.first, j)] = 1;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		if (!in[i]) dfs(i);
	}
	cin >> T;
	while (T--) {
		cin >> r1 >> c1 >> r2 >> c2;
		if (r1 > r2) cout << "No\n";
		else if (r1 == r2) {
			if (c1 <= c2) cout << "Yes\n";
			else cout << "No\n";
		} else {
			auto tmp = lower_bound(vec[r1].begin(), vec[r1].end(), c1);
			if (tmp != vec[r1].end()) {
				int curr = lab(r1, *tmp), up = 0;
				for (int i = 20; i >= 0; i--)
					if (anc[curr][i] != -1 && up + (1 << i) < r2 - r1) {
						curr = anc[curr][i];
						up += (1 << i);
						assert(a[curr] == r1 + up);
					}
				if (a[curr] == r2 - 1 && b[curr] <= c2) cout << "Yes\n";
				else cout << "No\n";
			} else cout << "No\n";
		}
	}
}

Compilation message

trampoline.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 45128 KB 200 token(s): yes count is 21, no count is 179
2 Correct 33 ms 45196 KB 200 token(s): yes count is 70, no count is 130
3 Correct 34 ms 44900 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 528 ms 66468 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 494 ms 66560 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 480 ms 67552 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 507 ms 66688 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 881 ms 64916 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 1032 ms 65376 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 922 ms 66156 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 1089 ms 67520 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 1083 ms 67464 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1323 ms 75900 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 36 ms 44748 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 34 ms 44748 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 34 ms 45380 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 34 ms 44728 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 37 ms 44940 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 40 ms 44620 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1530 ms 78460 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 1340 ms 70056 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 958 ms 66328 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1517 ms 98352 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 1283 ms 76688 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 977 ms 65480 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 1043 ms 65536 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 916 ms 66184 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1413 ms 75960 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1470 ms 76380 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1510 ms 86396 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 810 ms 65168 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 841 ms 65028 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 1122 ms 67332 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 795 ms 66960 KB 200000 token(s): yes count is 129674, no count is 70326