#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5, mod=30013;
int n, a[nx], b[nx], c[nx], d[nx], t, p;
vector<pair<int, int>> A, B;
map<int, int> mp;
struct value
{
int mx, f;
value(): mx(0), f(0) {}
value(int mx, int f): mx(mx), f(f) {}
friend value operator+(const value &lhs, const value &rhs) {
if (lhs.mx>rhs.mx) return lhs;
if (lhs.mx<rhs.mx) return rhs;
return value(lhs.mx, (lhs.f+rhs.f)%mod);
}
} dp[nx], ans;
struct fenwick
{
value d[nx];
void add(int i, value x)
{
while (i<nx) d[i]=(d[i]+x), i+=(i&-i);
}
value query(int i)
{
value res=value(0, 0);
while (i>0) res=(res+d[i]), i-=(i&-i);
return res;
}
} f;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=0; i<n; i++) cin>>a[i]>>b[i]>>c[i]>>d[i], A.push_back({a[i], i}), B.push_back({b[i], i}), mp[c[i]]=0, mp[d[i]]=0;
sort(A.begin(), A.end());
sort(B.begin(), B.end());
for (auto &[x, y]:mp) y=++t;
for (int i=0; i<n; i++)
{
while (B[p].first<A[i].first) f.add(mp[d[B[p].second]], dp[B[p].second]), p++;
dp[A[i].second]=f.query(mp[c[A[i].second]]-1);
dp[A[i].second].mx++;
if (dp[A[i].second].f==0) dp[A[i].second].f=1;
ans=ans+dp[A[i].second];
}
cout<<ans.mx<<' '<<ans.f;
}
/*
3
1 2 1 2
3 4 3 4
5 6 5 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4696 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
4952 KB |
Output is correct |
7 |
Correct |
4 ms |
5212 KB |
Output is correct |
8 |
Correct |
6 ms |
5212 KB |
Output is correct |
9 |
Correct |
11 ms |
5724 KB |
Output is correct |
10 |
Correct |
18 ms |
6992 KB |
Output is correct |
11 |
Correct |
24 ms |
7508 KB |
Output is correct |
12 |
Correct |
58 ms |
10536 KB |
Output is correct |
13 |
Correct |
67 ms |
11588 KB |
Output is correct |
14 |
Correct |
76 ms |
12968 KB |
Output is correct |
15 |
Correct |
93 ms |
13376 KB |
Output is correct |
16 |
Correct |
111 ms |
14136 KB |
Output is correct |
17 |
Correct |
111 ms |
14632 KB |
Output is correct |
18 |
Correct |
87 ms |
15160 KB |
Output is correct |
19 |
Correct |
109 ms |
15676 KB |
Output is correct |
20 |
Correct |
133 ms |
16440 KB |
Output is correct |