#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
const int MN = 200200;
const int LOG = 20;
ll nx[MN][LOG];
struct Q {
ll id;
pl st,ed;
bool operator< (const Q& other) {
return st.second < other.st.second;
}
};
vector<Q> qu;
vector<pl> tr;
map<ll,ll> mu;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
ll mr,mc;
cin >> mr >> mc;
ll n,N;
cin >> n;
for(int i=0;i<n;i++) {
ll a,b;
cin >> a >> b;
tr.emplace_back(a,b);
}
sort(tr.begin(),tr.end(),[&](const pl& a, const pl& b){
if(a.second > b.second) {return true;}
if(a.second < b.second) {return false;}
return a.first > b.first;
});
cin >> N;
vector<ll> ans(N,0);
for(int i=0;i<N;i++) {
ll sr,sc,tr,tc;
cin >> sr >> sc >> tr >> tc;
qu.push_back({i,{sr,sc},{tr,tc}});
}
ll trp = 0;
sort(qu.begin(),qu.end());
for(int qi=N-1;qi>=0;qi--) {
Q q = qu[qi];
while(trp < tr.size() && tr[trp].second >= q.st.second) {
ll r = tr[trp].first;
mu[r] = trp;
if(mu.count(r+1)) {
nx[trp][0] = mu[r+1];
} else {
nx[trp][0] = trp;
}
for(int i=1;i<LOG;i++) {
nx[trp][i] = nx[nx[trp][i-1]][i-1];
}
trp++;
}
ll idx = q.id;
if(q.st.first == q.ed.first) {
if(q.st.second <= q.ed.second) {
ans[idx] = 1;
} else {
ans[idx] = 0;
}
} else if(!mu.count(q.st.first)) {
ans[idx] = 0;
} else {
ll no = mu[q.st.first];
ll dif = q.ed.first-q.st.first-1;
if(dif < 0) {ans[idx] = 0;} else {
for(int i=LOG-1;i>=0;i--) {
if(dif&(1<<i)) {
no = nx[no][i];
}
}
}
if(tr[no].first+1 == q.ed.first && tr[no].second <= q.ed.second) {
ans[idx] = 1;
} else {
ans[idx] = 0;
}
}
}
for(int i=0;i<N;i++) {
cout << (ans[i]?"Yes":"No") << '\n';
}
}
Compilation message
trampoline.cpp: In function 'int main()':
trampoline.cpp:45:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while(trp < tr.size() && tr[trp].second >= q.st.second) {
| ~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2032 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
6 ms |
2288 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
1772 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
35292 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
186 ms |
37084 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
110 ms |
36700 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
170 ms |
37084 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
52940 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
257 ms |
59212 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
261 ms |
59084 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
290 ms |
59212 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
288 ms |
59340 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
441 ms |
60620 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1736 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
7 ms |
1992 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
2120 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
7 ms |
1992 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
8 ms |
1992 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
6 ms |
1992 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
555 ms |
52724 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
395 ms |
59144 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
267 ms |
59212 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
759 ms |
69164 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
401 ms |
61132 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
261 ms |
59348 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
256 ms |
59236 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
261 ms |
59340 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
528 ms |
60796 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
532 ms |
60648 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
676 ms |
64844 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
256 ms |
59004 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
247 ms |
59084 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
288 ms |
59168 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
252 ms |
59212 KB |
200000 token(s): yes count is 129674, no count is 70326 |