Submission #339079

#TimeUsernameProblemLanguageResultExecution timeMemory
339079cheissmartTrampoline (info1cup20_trampoline)C++14
0 / 100
1008 ms27192 KiB
#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; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...