#include <bits/stdc++.h>
using namespace std;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ind(x,y) lower_bound(x.begin(), x.end(), y) - x.begin()
typedef pair<int,int> pp;
typedef tuple<int,int,int> tp;
int n, q;
vector<int> xp, yp;
vector<pp> pts;
vector<tp> qry;
int ans[200010];
struct SEG {
static const int M = 524288;
int tree[M<<1];
void upd(int pos, int val){
pos += M;
while(pos) tree[pos]=max(tree[pos], val), pos>>=1;
}
int rmax(int l,int r){
l+=M; r+=M;
int ret=0;
while(l<=r){
if(l%2==1) ret=max(ret, tree[l++]);
if(r%2==0) ret=max(ret, tree[r--]);
l>>=1; r>>=1;
}
return ret;
}
} seg;
int main()
{
read(n, q); pts.resize(n);
for(auto& a:pts) read(a.first, a.second), xp.pb(a.first), yp.pb(a.second);
qry.resize(q);
for(int i=0; i<q; ++i){
int x, y;
read(x, y);
qry[i]=make_tuple(x, y, i);
xp.pb(x);
yp.pb(y);
}
sort(all(xp)); xp.erase(unique(all(xp)), xp.end());
sort(all(yp)); yp.erase(unique(all(yp)), yp.end());
for(auto& a:pts) a.first=ind(xp, a.first), a.second=ind(yp, a.second);
for(int j=0; j<q; ++j){
int x, y, i;
tie(x, y, i) = qry[j];
x=ind(xp, x);
y=ind(yp, y);
qry[j] = tie(x, y, i);
}
sort(all(pts), [&](const pp& a, const pp& b){
if(a.first != b.first) return a.first > b.first;
return a.second < b.second;
});
sort(all(qry), greater<tp>());
int ip=0, iq=0;
for(int i=xp.size()-1; 0<=i; --i){
while(ip < pts.size()){
int x, y;
tie(x, y) = pts[ip];
if(x != i) break;
int val = seg.rmax(0, y) + 1;
seg.upd(y, val);
++ip;
}
while(iq < qry.size()){
int x, y, ind;
tie(x, y, ind) = qry[iq];
if(x != i) break;
int val = seg.rmax(0, y);
ans[ind] = val;
++iq;
}
}
for(int i=0; i<q; ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | while(ip < pts.size()){
| ~~~^~~~~~~~~~~~
matryoshka.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | while(iq < qry.size()){
| ~~~^~~~~~~~~~~~
matryoshka.cpp: In function 'void read(int&)':
matryoshka.cpp:3:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | void read(int& x){ scanf("%d",&x); }
| ~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
284 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
284 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
4 ms |
572 KB |
Output is correct |
26 |
Correct |
4 ms |
456 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
460 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
460 KB |
Output is correct |
35 |
Correct |
4 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
284 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
4 ms |
572 KB |
Output is correct |
26 |
Correct |
4 ms |
456 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
460 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
460 KB |
Output is correct |
35 |
Correct |
4 ms |
544 KB |
Output is correct |
36 |
Correct |
423 ms |
15612 KB |
Output is correct |
37 |
Correct |
327 ms |
13604 KB |
Output is correct |
38 |
Correct |
141 ms |
6704 KB |
Output is correct |
39 |
Correct |
278 ms |
12012 KB |
Output is correct |
40 |
Correct |
270 ms |
12528 KB |
Output is correct |
41 |
Correct |
347 ms |
13480 KB |
Output is correct |
42 |
Correct |
200 ms |
11132 KB |
Output is correct |
43 |
Correct |
147 ms |
11436 KB |
Output is correct |
44 |
Correct |
456 ms |
19900 KB |
Output is correct |
45 |
Correct |
490 ms |
20044 KB |
Output is correct |
46 |
Correct |
449 ms |
19924 KB |
Output is correct |
47 |
Correct |
442 ms |
19620 KB |
Output is correct |
48 |
Correct |
458 ms |
20112 KB |
Output is correct |
49 |
Correct |
436 ms |
19620 KB |
Output is correct |
50 |
Correct |
440 ms |
20268 KB |
Output is correct |