#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 || green[st[i][0]].y<=green[i].y)
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)
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]<cell(x2,y2)?"Yes\n":"No\n");
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
996 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
185 ms |
15868 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1004 ms |
16692 KB |
expected NO, found YES [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
588 KB |
expected NO, found YES [2nd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1127 ms |
16716 KB |
expected NO, found YES [22nd token] |
2 |
Halted |
0 ms |
0 KB |
- |