#include <bits/stdc++.h>
using namespace std;
int r,c,n,t;
pair<int,int>a[200005];
int nxt[200005][20];
int lg[200005];
void nxt0()
{
for (int i = 1; i < n; i++)
{
int lin = a[i].first + 1,col = a[i].second;
pair<int,int>pr = {lin,col};
int st = i + 1,pas = 1 << 17;
while (pas != 0)
{
if (st + pas <= n and pr > a[st + pas])
st += pas;
pas /= 2;
}
st++;
if (st <= n and a[st].first == lin and a[st].second >= col)
nxt[i][0] = st;
}
}
void prec()
{
nxt0();
for (int i = 2; i <= 200000; i++)
lg[i] = 1 + lg[i / 2];
for (int j = 1; j <= lg[n]; j++)
{
for (int i = 1; i <= n - (1 << j); i++)
{
int n1 = nxt[i][j - 1];
if (n1 == 0)
nxt[i][j] = 0;
else
{
int n2 = nxt[n1][j - 1];
if (n2 == 0)
nxt[i][j] = 0;
else
nxt[i][j] = n2;
}
}
}
/*for (int j = 0; j <= lg[n]; j++)
{
for (int i = 1; i <= n - (1 << j) + 1; i++)
cout << nxt[i][j] << ' ';
cout << '\n';
}*/
}
void jump(int x,int y)
{
int pas = 17;
while (pas != -1)
{
if (nxt[x][pas] != 0 and nxt[x][pas] <= y)
x = nxt[x][pas];
pas--;
}
if (a[x].first == a[y].first and a[x].second <= a[y].second)
cout << "Yes\n";
else
cout << "No\n";
}
void query(int xs,int ys,int xf,int yf)
{
if (xs > xf or ys > yf)
{
cout << "No\n";
return;
}
if (xs == xf)
{
cout << "Yes\n";
return;
}
int ts = 0,tf = 0;
int pas = 1 << 17;
pair<int,int>cp = {xs,ys};
while (pas != 0)
{
if (ts + pas <= n and a[ts + pas] < cp)
ts += pas;
pas /= 2;
}
ts++;
if (ts <= n and a[ts].first == xs and a[ts].second >= ys)
ts += 0;
else
ts = 0;
xf--;
pas = 1 << 17;
cp = {xf,yf};
while (pas != 0)
{
if (tf + pas <= n and a[tf + pas] <= cp)
tf += pas;
pas /= 2;
}
if (tf != 0 and a[tf].first == xf and a[tf].second <= yf)
tf += 0;
else
tf = 0;
//cout << ts << ' ' << tf << '\n';
if (ts == 0 or tf == 0)
{
cout << "No\n";
return;
}
jump(ts,tf);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> c >> n;
for (int i =1 ; i <= n; i++)
cin >> a[i].first >> a[i].second;
sort(a + 1,a + n + 1);
prec();
cin >> t;
for (int i =1 ; i <= t; i++)
{
int xs,ys,xf,yf;
cin >> xs >> ys >> xf >> yf;
query(xs,ys,xf,yf);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1876 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
2004 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
1748 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
18260 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
85 ms |
20136 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
90 ms |
19744 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
88 ms |
20132 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
19088 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
257 ms |
19032 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
221 ms |
18904 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
258 ms |
18928 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
250 ms |
19052 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
250 ms |
19044 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1492 KB |
expected YES, found NO [10th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
328 ms |
18892 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |