#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using ii = pair<int,int>;
using pii = pair<int,ii>;
using aa = array<int,4>;
const int N = 2e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;
int n,a,b,c,d,dp[N],ans;
aa p[N];
vector <aa> points;
vector <int> compress;
struct SMT{
int n;
vector<int> t;
vector<int> lazy;
SMT(int _n = 0) : n(_n){
t.assign((n << 2),0);
lazy.assign((n << 2),0);
}
void push(int id,int l,int r){
if (l == r || !lazy[id]) return;
for (int i = 0; i <= 1; i++){
t[id*2+i] += lazy[id];
lazy[id*2+i] += lazy[id];
}
lazy[id] = 0;
}
void update(int id,int l,int r,int pos,int val){
if (r < pos || l > pos) return;
if (l == r){
t[id] = max(t[id],val);
return;
}
int mid = (l + r) >> 1;
update(id*2,l,mid,pos,val);
update(id*2+1,mid+1,r,pos,val);
t[id] = max(t[id * 2],t[id * 2 + 1]);
}
int getmax(int id,int l,int r,int u,int v){
if (r < u || l > v) return (int)-1e18;
if (u <= l && r <= v) return t[id];
int mid = (l + r) >> 1;
return max(getmax(id*2,l,mid,u,v),getmax(id*2+1,mid+1,r,u,v));
}
};
int calc(int val){
return lower_bound(compress.begin(),compress.end(),val) - compress.begin() + 1;
}
/*
p[i][0]: l
p[i][1]: r
p[i][2]: l1
p[i][3]: r1
*/
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a >> b >> c >> d;
points.push_back({a,0,c,i});
points.push_back({b,1,d,i});
compress.push_back(c);
compress.push_back(d);
}
sort(compress.begin(),compress.end());
compress.erase(unique(compress.begin(),compress.end()),compress.end());
sort(points.begin(),points.end());
int m = (int)compress.size();
SMT tnm(m);
for (aa &it : points) it[2] = calc(it[2]);
for (auto [x,type,pos,i] : points){
if (!type){
dp[i] = tnm.getmax(1,1,m,1,pos) + 1;
} else{
tnm.update(1,1,m,pos,dp[i]);
}
}
for (int i = 1; i <= n; i++) ans = max(ans,dp[i]);
cout << ans << ' ' << 0;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |