#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int r,c,n,q;
ii arr[200005];
int nxt[200005][20];;
map<int,vector<ii> > m;
int main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>r>>c>>n;
rep(x,0,n) cin>>arr[x].fi>>arr[x].se;
sort(arr,arr+n);
rep(x,0,n){
m[arr[x].fi].pub(ii(arr[x].se,x));
}
memset(nxt,-1,sizeof(nxt));
rep(x,0,n){
int temp=-1;
if (m.count(arr[x].fi+1)){
auto iter=lb(all(m[arr[x].fi+1]),ii(arr[x].se,-1));
if (iter!=m[arr[x].fi+1].end()) temp=(*iter).se;
}
nxt[x][0]=temp;
}
rep(x,n,0){
int curr=nxt[x][0];
rep(y,0,20){
if (curr==-1) break;
curr=nxt[x][y+1]=nxt[curr][y];
}
}
cin>>q;
int a,b,c,d;
while (q--){
cin>>a>>b>>c>>d;
//cerr<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
if (a>c || b>d){
cout<<"No"<<endl;
continue;
}
if (a==c){
cout<<"Yes"<<endl;
continue;
}
int idx=-1;
if (m.count(a)){
auto iter=lb(all(m[a]),ii(b,-1));
if (iter!=m[a].end()) idx=(*iter).se;
}
if (idx==-1){
cout<<"No"<<endl;
continue;
}
rep(x,20,0) if (nxt[idx][x]!=-1){
if (arr[nxt[idx][x]].se<=d) idx=nxt[idx][x];
}
if (c-1<=arr[idx].fi) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
16412 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
12 ms |
16464 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
11 ms |
16340 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
26048 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
113 ms |
26048 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
102 ms |
24684 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
114 ms |
26012 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
35600 KB |
expected NO, found YES [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
16460 KB |
expected NO, found YES [125th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
762 ms |
42660 KB |
expected NO, found YES [90481st token] |
2 |
Halted |
0 ms |
0 KB |
- |