#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;
}
};
int N,Q;
pii A[MAX],C[MAX];
int main() {
fio();
cin>>N>>Q;
for (int i=1; i<=N; i++) {
int x,y; cin>>x>>y;
A[i]={x,y};
}
while (Q--) {
int x,y;
cin>>x>>y;
vector<pii> B; B.pb({0,0});
vector<int> Y;
for (int i=1; i<=N; i++) {
if (x<=A[i].F && A[i].S<=y) {
B.pb(A[i]);
Y.pb(A[i].S);
}
}
sort(all(B),[](pii a, pii b){
if (a.F==b.F) return a.S>b.S;
return a.F<b.F;
});
cmprs(Y);
int M=sz(B)-1;
for (int i=1; i<=M; i++) {
B[i].S=lb(all(Y),B[i].S)-Y.begin()+1;
}
segtr seg; seg.rst(M+10);
vector<int> dp(M+10);
for (int i=M; i>=1; i--) {
dp[i]=seg.qry(0,B[i].S-1)+1;
seg.upd(B[i].S,dp[i]);
}
cout<<*max_element(all(dp))<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |