#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct Seg{
int tree[800800], sz;
void init(int n){sz = n;}
void update(int p, int x){
p += sz;
tree[p] = max(tree[p], x);
for (p>>=1;p;p>>=1) tree[p] = max(tree[p<<1], tree[p<<1|1]);
}
int query(int r){
int l = 0, ret = 0;
for (l+=sz, r+=sz+1;l<r;l>>=1, r>>=1){
if (l&1) ret = max(ret, tree[l++]);
if (r&1) ret = max(ret, tree[--r]);
}
return ret;
}
}tree;
struct Data{
int x, y, isq, i;
Data(){}
Data(int _x, int _y, int _q, int _i): x(_x), y(_y), isq(_q), i(_i) {}
bool operator < (const Data &D){
if (x==D.x && y==D.y) return isq < D.isq;
if (x==D.x) return y < D.y;
return x > D.x;
}
};
vector<Data> D;
int ans[200200];
vector<int> Y;
void compress(vector<int> &a){sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end());}
int getidx(const vector<int> &a, int x){return lower_bound(a.begin(), a.end(), x) - a.begin();}
int main(){
Y.push_back(0);
int n, q;
scanf("%d %d", &n, &q);
for (int i=1;i<=n;i++){
int x, y;
scanf("%d %d", &x, &y);
Y.push_back(y);
D.emplace_back(x, y, 0, 0);
}
for (int i=1;i<=q;i++){
int x, y;
scanf("%d %d", &x, &y);
Y.push_back(y);
D.emplace_back(x, y, 1, i);
}
compress(Y);
tree.init(Y.size());
sort(D.begin(), D.end());
for (auto &[x, y, isq, i]:D){
y = getidx(Y, y);
if (isq) {ans[i] = tree.query(y); continue;}
tree.update(y, tree.query(y) + 1);
}
for (int i=1;i<=q;i++) printf("%d\n", ans[i]);
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
3 ms |
500 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
540 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
456 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
456 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
3 ms |
500 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
540 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
456 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
456 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
464 KB |
Output is correct |
36 |
Correct |
270 ms |
18120 KB |
Output is correct |
37 |
Correct |
162 ms |
16272 KB |
Output is correct |
38 |
Correct |
97 ms |
8328 KB |
Output is correct |
39 |
Correct |
169 ms |
14620 KB |
Output is correct |
40 |
Correct |
174 ms |
15012 KB |
Output is correct |
41 |
Correct |
209 ms |
16152 KB |
Output is correct |
42 |
Correct |
129 ms |
13708 KB |
Output is correct |
43 |
Correct |
114 ms |
14032 KB |
Output is correct |
44 |
Correct |
347 ms |
22680 KB |
Output is correct |
45 |
Correct |
301 ms |
22652 KB |
Output is correct |
46 |
Correct |
305 ms |
22624 KB |
Output is correct |
47 |
Correct |
278 ms |
22172 KB |
Output is correct |
48 |
Correct |
293 ms |
22780 KB |
Output is correct |
49 |
Correct |
285 ms |
22224 KB |
Output is correct |
50 |
Correct |
271 ms |
22756 KB |
Output is correct |