#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int MX = 2e5+5;
vector<int> G;
vector<int> H;
signed main()
{
fast();
int n, q;
cin >> n >> q;
vector<pair<in, int>> Q(q);
vector<in> RH(n+1);
RH[0] = {-INF, -1};
for(int i = 1; i <= n; i++)
{
cin >> RH[i].f >> RH[i].s;
RH[i].f = -RH[i].f;
G.pb(RH[i].f);
}
for(int i = 0; i < q; i++)
{
Q[i].s = i;
cin >> Q[i].f.f >> Q[i].f.s;
Q[i].f.f = -Q[i].f.f;
G.pb(Q[i].f.f);
}
sort(RH.begin(), RH.end());
sort(G.begin(), G.end());
H.pb(G[0]);
for(auto x: G)
{
if(x != H.back())
H.pb(x);
}
G.clear();
for(auto &[u, v]: RH)
{
u = lower_bound(H.begin(), H.end(), u)-H.begin()+1;
G.pb(v);
}
for(auto &[qq, i]: Q)
{
qq.f = lower_bound(H.begin(), H.end(), qq.f)-H.begin()+1;
G.pb(qq.s);
}
H.clear();
sort(G.begin(), G.end());
H.pb(G[0]);
for(auto x: G)
{
if(x != H.back())
H.pb(x);
}
for(auto &[u, v]: RH)
v = lower_bound(H.begin(), H.end(), v)-H.begin()+1;
for(auto &[qq, i]: Q)
qq.s = lower_bound(H.begin(), H.end(), qq.s)-H.begin()+1;
sort(Q.begin(), Q.end());
/*cout << "Printing RH values" << endl;
for(auto [u, v]: RH)
cout << u << " " << v << endl;*/
int r = 1;
vector<int> ans(q, 0);
vector<in> d(n+1, {INF, INF});
d[0] = {-INF, -INF};
for(int i = 0; i < q; i++)
{
int x = Q[i].s;
while((r <= n) && (RH[r].f <= Q[i].f.f))
{
//add RH[r].s
//RH[r].s can provide
in pp = {RH[r].s, r};
int W = upper_bound(d.begin(), d.end(), pp) - d.begin();
if((d[W-1] < pp) && (pp < d[W]))
d[W] = pp;
r++;
}
in ok = {Q[i].f.s, INF};
ans[x] = upper_bound(d.begin(), d.end(), ok)-d.begin()-1;
}
for(int i = 0; i < q; i++)
cout << ans[i] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
264 ms |
18912 KB |
Output is correct |
37 |
Correct |
215 ms |
20028 KB |
Output is correct |
38 |
Correct |
80 ms |
7160 KB |
Output is correct |
39 |
Correct |
158 ms |
16836 KB |
Output is correct |
40 |
Correct |
172 ms |
17696 KB |
Output is correct |
41 |
Correct |
228 ms |
18972 KB |
Output is correct |
42 |
Correct |
119 ms |
17248 KB |
Output is correct |
43 |
Correct |
81 ms |
17396 KB |
Output is correct |
44 |
Correct |
299 ms |
20288 KB |
Output is correct |
45 |
Correct |
284 ms |
19976 KB |
Output is correct |
46 |
Correct |
282 ms |
19812 KB |
Output is correct |
47 |
Correct |
263 ms |
21572 KB |
Output is correct |
48 |
Correct |
265 ms |
20028 KB |
Output is correct |
49 |
Correct |
263 ms |
19748 KB |
Output is correct |
50 |
Correct |
267 ms |
21308 KB |
Output is correct |