#include <iostream>
#include <algorithm>
#define cell(x,y) kus(x,y)
using namespace std;
struct cell {
int x,y;
bool operator <(const cell a) const {
return x<a.x || (a.x==x && y<a.y);
}
} green[200001];
int n;
static cell kus(int x, int y) {
cell rez;
rez.x=x;
rez.y=y;
return rez;
}
static int findfirst(int x, int y) {
cell val=cell(x,y);
int temp,bound=-1;
for(int i=(1<<17); i>0; i>>=1) {
temp=min(n,bound+i);
if(green[temp]<val)
bound=temp;
}
return bound+1;
}
int st[200001][18];
int main() {
int q,r,c;
cin >> r >> c >> n;
for(int i=0,a,b; i<n; i++) {
cin >> a >> b;
green[i]=cell(a,b);
}
green[n]=cell(r+1,c+1);
sort(green,green+n);
for(int i=0;i<n; i++) {
st[i][0]=findfirst(green[i].x+1,green[i].y);
if(green[st[i][0]].x!=green[i].x+1)
st[i][0]=n;
}
st[n][0]=n;
for(int step=1; step<18; step++) {
for(int j=0; j<=n;j++) {
st[j][step]=st[st[j][step-1]][step-1];
}
}
cin >> q;
for(int tc=0,x1,x2,y1,y2,diff,curr; tc<q; tc++) {
cin >> x1 >> y1 >> x2 >> y2;
if(x1==x2) {
cout << "Yes\n";
}
else if(x2-x1>n || x2<x1 || y2<y1)
cout << "No\n";
else {
diff=x2-x1;
curr=findfirst(x1,y1);
if(green[curr].x!=x1)
cout << "No\n";
else {
--diff;
for(int i=0; i<18; i++) {
if((1<<i)&diff)
curr=st[curr][i];
}
//cout << green[curr].x <<' '<< green[curr].y <<'\n';
cout << (green[curr].x+1==x2 && green[curr].y<=y2?"Yes\n":"No\n");
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
988 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
8 ms |
1100 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
7 ms |
844 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
15864 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
186 ms |
17752 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
183 ms |
17456 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
191 ms |
17748 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
958 ms |
16648 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
975 ms |
27012 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
976 ms |
27096 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
1000 ms |
27064 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
984 ms |
27016 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
1010 ms |
27080 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
588 KB |
expected NO, found YES [16th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1111 ms |
16692 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Incorrect |
1061 ms |
28228 KB |
expected NO, found YES [22020th token] |
3 |
Halted |
0 ms |
0 KB |
- |