#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
map<int, vector<int>> mapa;
map<pair<int,int>,pair<int,int>> next_[21];
void solve()
{
int R,C,n;
cin >> R >> C >> n;
vector<int> byly;
vector<pair<int,int>> points;
rep(i,n)
{
int x,y;
cin >>y >> x;
mapa[y].pb(x);
points.pb({y,x});
}
forall(it, mapa) sort(all(it.ss));
int pop = -1;
forall(it, mapa)
{
if(it.ff != pop) byly.pb(it.ff);
pop = it.ff;
}
rep(i,size(byly))
{
// cout << "y: " << i << " mapa: ";
// forall(it,mapa[i])
// {
// cout << it << " ";
//}
//cout << "\n";
if(i == size(byly)-1 || byly[i] != byly[i+1]-1)
{
forall(it2,mapa[byly[i]])
{
next_[0][{byly[i],it2}] = {byly[i],it2};
}
}
else
{
forall(it2,mapa[byly[i]])
{
vector<int>::iterator iter = lower_bound(all(mapa[byly[i+1]]),it2);
if(iter != mapa[byly[i+1]].end())
{
next_[0][{byly[i],it2}] = {byly[i+1],*iter};
}
else
{
next_[0][{byly[i],it2}] = {byly[i],it2};
}
}
}
}
rep2(k,1,20)
{
forall(it,points)
{
next_[k][it] = next_[k-1][next_[k-1][it]];
}
}
int q;
cin >> q;
rep(i,q)
{
int y1,x1,y2,x2;
cin >> y1 >> x1 >> y2 >> x2;
int odl = y2-y1-1;
if(y2 < y1 || x2 < x1)
{
cout << "No\n"; continue;
}
if(y1 == y2)
{
cout << "Yes\n"; continue;
}
vector<int>::iterator aktpoint_iter = lower_bound(all(mapa[y1]),x1);
if(aktpoint_iter == mapa[y1].end())
{
cout << "No\n"; continue;
}
pair<int,int> aktpoint = {y1,*aktpoint_iter};
rep(k,21)
{
// cout << aktpoint.ff << " " << aktpoint.ss << " aktpoint\n";
if(odl & (1 << k))
{
aktpoint = next_[k][aktpoint];
}
}
if(aktpoint.ff == y2-1 && aktpoint.ss <= x2)
{
cout << "Yes\n";
}
else
{
cout << "No\n";
}
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// random();
int t = 1;
//cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
12116 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
110 ms |
13712 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
63 ms |
9792 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2025 ms |
100676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2066 ms |
124016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
7416 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
43 ms |
7664 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
59 ms |
7864 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
37 ms |
7512 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
52 ms |
7516 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
43 ms |
7256 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2036 ms |
112988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |