답안 #339079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339079 2020-12-24T14:28:44 Z cheissmart Trampoline (info1cup20_trampoline) C++14
0 / 100
1008 ms 27192 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

map<int, V<pi>> mp; 

signed main()
{
	IO_OP;
	
	int r, c, n;
	cin >> r >> c >> n;
	V<array<int, 3>> v(n);
	vi p(n);
	iota(ALL(p), 0);
	function<int(int)> find = [&] (int u) {
		return p[u] == u ? u : p[u] = find(p[u]);
	};
	auto unite = [&] (int x, int y) {
		int rx = find(x), ry = find(y);
		p[rx] = ry;
	};
	for(int i = 0; i < n; i++)
		cin >> v[i][0] >> v[i][1], v[i][2] = i;
	sort(ALL(v));
	for(auto p:v)
		mp[p[0]].EB(p[1], p[2]);

	for(auto& tt:mp) {
		int row = tt.F;
		for(pi p:tt.S) {
			int col = p.F, id = p.S;
			if(mp.count(row + 1) == 0) continue;
			auto it = lower_bound(ALL(mp[row+1]), MP(col, -INF));
			if(it != mp[row+1].end()) {
				int idd = it -> S;
				unite(id, idd);
			}
		}
	}
	int t;
	cin >> t;
	while(t--) {
		int x, y, xx, yy;
		cin >> x >> y >> xx >> yy;
		if(xx < x || yy < y) {
			cout << "No" << endl;
			continue;
		}
		if(x == xx) {
			cout << "Yes" << endl;
			continue;
		}
		xx--;
		auto it = lower_bound(ALL(mp[x]), MP(y, -INF));
		auto itt = upper_bound(ALL(mp[xx]), MP(yy, INF));
		if(it != mp[x].end() && itt != mp[xx].begin()) {
			itt--;
			int u = it -> S, v = it -> S;
			if(find(u) == find(v))
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 620 KB expected NO, found YES [2nd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 8172 KB expected NO, found YES [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 735 ms 18284 KB expected NO, found YES [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 748 KB expected NO, found YES [59th token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1008 ms 27192 KB expected NO, found YES [23rd token]
2 Halted 0 ms 0 KB -