이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#include "bits/stdc++.h"
using namespace std;
//~ #ifndef ONLINE_JUDGE
//~ #include "debug.h"
//~ #else
//~ #define debug(...)
//~ #define debugArr(...)
//~ #endif
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
const int inf = 1e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
void solve() {
int r,c,n;
cin >> r >> c >> n;
int a[n],b[n];
vector<pair<int,int>> v;
map<int,vector<pair<int,int>>> mp;
set<int> st;
for(int i = 0;i < n;i++) {
cin >> a[i] >> b[i];
v.pb({a[i],b[i]});
st.insert(a[i]);
}
sort(rall(v));
int id = 0;
vector<vector<pair<int,int>>> up(n,vector<pair<int,int>> (20,{-1,-1}));
vector<int> pr(n,-1);
for(auto [i,j] : v) {
mp[i].pb({j,id++});
}
for(auto i : st) sort(all(mp[i]));
id = 0;
for(auto [i,j] : v) {
if(mp.find(i + 1) == mp.end()) {
id++;
continue;
}
int lst = pr[id - 1] - 1;
if(pr[id - 1] == -1) lst = mp[i + 1].size() - 1;
while(lst >= 0 && mp[i + 1][lst].ff >= j) {
lst--;
}
lst++;
pr[id] = lst;
if(lst == (int)mp[i + 1].size()) continue;
up[id][0] = {mp[i + 1][lst]};
for(int k = 1;k < 20;k++) {
if(up[id][k - 1].ss == -1) break;
up[id][k] = {up[up[id][k - 1].ss][k - 1]};
}
id++;
}
auto get = [&](int a,int k) -> int {
int val = inf;
for(int i = 0;i < 20;i++) {
if(k >> i & 1) {
val = up[a][i].ff;
a = up[a][i].ss;
if(a == -1) {
return -1;
}
}
}
return val;
};
int q;
cin >> q;
while(q--) {
int xs,ys,xf,yf;
cin >> xs >> ys >> xf >> yf;
if(xs == xf) {
cout << "Yes\n";
continue;
}
int ans = -1,l = 0,r = mp[xs].size() - 1;
while(l <= r) {
int mid = (l + r) >> 1;
if(mp[xs][mid].ff >= ys) {
l = mid + 1;
ans = mid;
} else {
r = mid - 1;
}
}
if(ans == -1) {
cout << "No\n";
} else {
int x;
if(xf - xs <= 1) {
x = mp[xs][ans].ff;
} else {
x = get(mp[xs][ans].ss,xf - xs - 1);
}
if(x <= yf && x != -1) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t = 1;
//~ cin >> t;
while(t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |