#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;
const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 202020; // PLZ CHK!
struct segtr{
//0-indexed!
vector<ll> tr, a;
int n;
void rst(int sz) {
n=sz;
tr.resize((n+1)<<1);
}
void upd(int i, ll v) {
tr[i+n] = max(tr[i+n], v); i+=n; //AWARE OF UPD POLICY!!
for (i>>=1; i; i>>=1) tr[i] = max(tr[i<<1], tr[i<<1|1]);
}
ll qry(int l, int r) {
ll ret = -LINF;
for (l+=n, r+=n; l<=r; l>>=1, r>>=1) {
if (l&1) ret = max(ret, tr[l++]);
if (~r&1) ret = max(ret, tr[r--]);
}
return ret;
}
};
typedef array<int,3> arr;
int N,Q,D[MAX];
pii A[MAX];
arr C[MAX];
int ans[MAX];
int main() {
fio();
cin>>N>>Q;
vector<int> Y;
Y.pb(0);
for (int i=1; i<=N; i++) {
int x,y; cin>>x>>y;
A[i]={x,y};
Y.pb(y);
}
for (int i=1; i<=Q; i++) {
int x,y; cin>>x>>y;
C[i]={x,y,i};
Y.pb(y);
}
sort(A+1,A+N+1,[](pii a, pii b){
if (a.F==b.F) return a.S>b.S;
return a.F<b.F;
});
sort(C+1,C+Q+1,[](auto a, auto b){
if (a[0]==b[0]) return a[1]>b[1];
return a[0]<b[0];
});
cmprs(Y);
for (int i=1; i<=N; i++) A[i].S=lb(all(Y),A[i].S)-Y.begin()+1;
for (int i=1; i<=Q; i++) C[i][1]=lb(all(Y),C[i][1])-Y.begin()+1;
segtr seg; seg.rst(MAX*2);
for (int i=N; i>=1; i--) {
D[i]=seg.qry(0,A[i].S)+1;
seg.upd(A[i].S,D[i]);
}
segtr segq; segq.rst(MAX*2);
for (int i=Q,j=N; i>=1; i--) {
auto [a,b,idx]=C[i];
while (j>=1 && a<=A[j].F) segq.upd(A[j].S,D[j]), j--;
ans[idx]=segq.qry(0,b);
}
for (int i=1; i<=Q; i++) cout<<ans[i]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
13148 KB |
Output is correct |
2 |
Correct |
5 ms |
13148 KB |
Output is correct |
3 |
Correct |
6 ms |
12892 KB |
Output is correct |
4 |
Correct |
5 ms |
13044 KB |
Output is correct |
5 |
Correct |
5 ms |
13024 KB |
Output is correct |
6 |
Correct |
5 ms |
13148 KB |
Output is correct |
7 |
Correct |
5 ms |
13148 KB |
Output is correct |
8 |
Correct |
5 ms |
13148 KB |
Output is correct |
9 |
Correct |
5 ms |
13020 KB |
Output is correct |
10 |
Correct |
5 ms |
12888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
13148 KB |
Output is correct |
2 |
Correct |
5 ms |
13148 KB |
Output is correct |
3 |
Correct |
6 ms |
12892 KB |
Output is correct |
4 |
Correct |
5 ms |
13044 KB |
Output is correct |
5 |
Correct |
5 ms |
13024 KB |
Output is correct |
6 |
Correct |
5 ms |
13148 KB |
Output is correct |
7 |
Correct |
5 ms |
13148 KB |
Output is correct |
8 |
Correct |
5 ms |
13148 KB |
Output is correct |
9 |
Correct |
5 ms |
13020 KB |
Output is correct |
10 |
Correct |
5 ms |
12888 KB |
Output is correct |
11 |
Correct |
5 ms |
12888 KB |
Output is correct |
12 |
Correct |
6 ms |
13036 KB |
Output is correct |
13 |
Correct |
5 ms |
12892 KB |
Output is correct |
14 |
Correct |
7 ms |
12892 KB |
Output is correct |
15 |
Correct |
5 ms |
13148 KB |
Output is correct |
16 |
Correct |
6 ms |
13148 KB |
Output is correct |
17 |
Correct |
5 ms |
13100 KB |
Output is correct |
18 |
Correct |
5 ms |
13148 KB |
Output is correct |
19 |
Correct |
6 ms |
12892 KB |
Output is correct |
20 |
Correct |
6 ms |
13148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
13148 KB |
Output is correct |
2 |
Correct |
5 ms |
13148 KB |
Output is correct |
3 |
Correct |
6 ms |
12892 KB |
Output is correct |
4 |
Correct |
5 ms |
13044 KB |
Output is correct |
5 |
Correct |
5 ms |
13024 KB |
Output is correct |
6 |
Correct |
5 ms |
13148 KB |
Output is correct |
7 |
Correct |
5 ms |
13148 KB |
Output is correct |
8 |
Correct |
5 ms |
13148 KB |
Output is correct |
9 |
Correct |
5 ms |
13020 KB |
Output is correct |
10 |
Correct |
5 ms |
12888 KB |
Output is correct |
11 |
Correct |
5 ms |
12888 KB |
Output is correct |
12 |
Correct |
6 ms |
13036 KB |
Output is correct |
13 |
Correct |
5 ms |
12892 KB |
Output is correct |
14 |
Correct |
7 ms |
12892 KB |
Output is correct |
15 |
Correct |
5 ms |
13148 KB |
Output is correct |
16 |
Correct |
6 ms |
13148 KB |
Output is correct |
17 |
Correct |
5 ms |
13100 KB |
Output is correct |
18 |
Correct |
5 ms |
13148 KB |
Output is correct |
19 |
Correct |
6 ms |
12892 KB |
Output is correct |
20 |
Correct |
6 ms |
13148 KB |
Output is correct |
21 |
Correct |
5 ms |
13148 KB |
Output is correct |
22 |
Correct |
6 ms |
13148 KB |
Output is correct |
23 |
Correct |
6 ms |
13324 KB |
Output is correct |
24 |
Correct |
7 ms |
13148 KB |
Output is correct |
25 |
Correct |
7 ms |
13148 KB |
Output is correct |
26 |
Correct |
7 ms |
13148 KB |
Output is correct |
27 |
Correct |
7 ms |
13276 KB |
Output is correct |
28 |
Correct |
7 ms |
13216 KB |
Output is correct |
29 |
Correct |
7 ms |
13272 KB |
Output is correct |
30 |
Correct |
8 ms |
13148 KB |
Output is correct |
31 |
Correct |
8 ms |
13148 KB |
Output is correct |
32 |
Correct |
7 ms |
13148 KB |
Output is correct |
33 |
Correct |
8 ms |
13112 KB |
Output is correct |
34 |
Correct |
8 ms |
13144 KB |
Output is correct |
35 |
Correct |
7 ms |
13148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
13148 KB |
Output is correct |
2 |
Correct |
5 ms |
13148 KB |
Output is correct |
3 |
Correct |
6 ms |
12892 KB |
Output is correct |
4 |
Correct |
5 ms |
13044 KB |
Output is correct |
5 |
Correct |
5 ms |
13024 KB |
Output is correct |
6 |
Correct |
5 ms |
13148 KB |
Output is correct |
7 |
Correct |
5 ms |
13148 KB |
Output is correct |
8 |
Correct |
5 ms |
13148 KB |
Output is correct |
9 |
Correct |
5 ms |
13020 KB |
Output is correct |
10 |
Correct |
5 ms |
12888 KB |
Output is correct |
11 |
Correct |
5 ms |
12888 KB |
Output is correct |
12 |
Correct |
6 ms |
13036 KB |
Output is correct |
13 |
Correct |
5 ms |
12892 KB |
Output is correct |
14 |
Correct |
7 ms |
12892 KB |
Output is correct |
15 |
Correct |
5 ms |
13148 KB |
Output is correct |
16 |
Correct |
6 ms |
13148 KB |
Output is correct |
17 |
Correct |
5 ms |
13100 KB |
Output is correct |
18 |
Correct |
5 ms |
13148 KB |
Output is correct |
19 |
Correct |
6 ms |
12892 KB |
Output is correct |
20 |
Correct |
6 ms |
13148 KB |
Output is correct |
21 |
Correct |
5 ms |
13148 KB |
Output is correct |
22 |
Correct |
6 ms |
13148 KB |
Output is correct |
23 |
Correct |
6 ms |
13324 KB |
Output is correct |
24 |
Correct |
7 ms |
13148 KB |
Output is correct |
25 |
Correct |
7 ms |
13148 KB |
Output is correct |
26 |
Correct |
7 ms |
13148 KB |
Output is correct |
27 |
Correct |
7 ms |
13276 KB |
Output is correct |
28 |
Correct |
7 ms |
13216 KB |
Output is correct |
29 |
Correct |
7 ms |
13272 KB |
Output is correct |
30 |
Correct |
8 ms |
13148 KB |
Output is correct |
31 |
Correct |
8 ms |
13148 KB |
Output is correct |
32 |
Correct |
7 ms |
13148 KB |
Output is correct |
33 |
Correct |
8 ms |
13112 KB |
Output is correct |
34 |
Correct |
8 ms |
13144 KB |
Output is correct |
35 |
Correct |
7 ms |
13148 KB |
Output is correct |
36 |
Correct |
212 ms |
25032 KB |
Output is correct |
37 |
Correct |
142 ms |
24772 KB |
Output is correct |
38 |
Correct |
76 ms |
17868 KB |
Output is correct |
39 |
Correct |
138 ms |
23352 KB |
Output is correct |
40 |
Correct |
141 ms |
23864 KB |
Output is correct |
41 |
Correct |
164 ms |
24752 KB |
Output is correct |
42 |
Correct |
99 ms |
22988 KB |
Output is correct |
43 |
Correct |
79 ms |
23240 KB |
Output is correct |
44 |
Correct |
236 ms |
27076 KB |
Output is correct |
45 |
Correct |
245 ms |
28620 KB |
Output is correct |
46 |
Correct |
240 ms |
28584 KB |
Output is correct |
47 |
Correct |
231 ms |
28280 KB |
Output is correct |
48 |
Correct |
221 ms |
28944 KB |
Output is correct |
49 |
Correct |
221 ms |
28360 KB |
Output is correct |
50 |
Correct |
217 ms |
28872 KB |
Output is correct |