#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 = 30013;
int n,a,b,c,d;
ii ans,dp[N];
vector <aa> points;
vector <int> compress;
ii merges(ii a,ii b){
ii res;
if (a.fi > b.fi) res = a;
else if (a.fi < b.fi) res = b;
else res = {a.fi,a.se + b.se};
res.se %= MOD;
return res;
}
struct SMT{
int n;
vector<ii> t;
SMT(int _n = 0) : n(_n){
t.assign((n << 2),{0,0});
}
void update(int id,int l,int r,int pos,ii val){
if (r < pos || l > pos) return;
if (l == r){
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] = merges(t[id * 2],t[id * 2 + 1]);
}
ii getmax(int id,int l,int r,int u,int v){
if (r < u || l > v) return {-1e18,0};
if (u <= l && r <= v) return t[id];
int mid = (l + r) >> 1;
ii t1 = getmax(id*2,l,mid,u,v);
ii t2 = getmax(id*2+1,mid+1,r,u,v);
return merges(t1,t2);
}
};
int calc(int val){
return lower_bound(compress.begin(),compress.end(),val) - compress.begin() + 1;
}
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){
ii it = tnm.getmax(1,1,m,1,pos);
dp[i] = merges({1,1},{it.fi+1,it.se});
} else{
tnm.update(1,1,m,pos,dp[i]);
}
}
for (int i = 1; i <= n; i++) ans = merges(ans,dp[i]);
cout << ans.fi << ' ' << ans.se;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |