#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 30013;
const int N = 2e5+2;
struct Node {
int best, count;
Node operator + (const Node &other) {
if (best == other.best)
return {best, (other.count + count) % MOD};
else if (best > other.best)
return *this;
else
return other;
}
} aint[4 * N], ans;
void update (int nod, int st, int dr, int poz, Node val) {
if (st == dr) {
aint[nod] = val;
return;
}
int mij = (st + dr) / 2;
if (poz <= mij)
update(2 * nod, st, mij, poz, val);
else
update(2 * nod + 1, mij + 1, dr, poz, val);
aint[nod] = aint[2 * nod] + aint[2 * nod + 1];
}
void query (int nod, int st, int dr, int a, int b) {
if (a <= st && dr <= b) {
ans = ans + aint[nod];
return;
}
int mij = (st + dr) / 2;
if (a <= mij)
query(2 * nod, st, mij, a, b);
if (b > mij)
query(2 * nod + 1, mij + 1, dr, a, b);
}
struct event {
int type, time, x, ind;
bool operator < (const event other) {
return time < other.time;
}
} v[N];
int a[N][4];
int n;
Node dp[N];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
vector<int>idk;
for (int i = 1; i <= n; i++) {
for (auto j : {0, 1, 2, 3})
cin >> a[i][j];
idk.push_back(a[i][2]);
idk.push_back(a[i][3]);
}
sort(idk.begin(), idk.end());
for (int i = 1; i <= n; i++) {
v[2 * i - 1] = {0, a[i][0], (int)(lower_bound(idk.begin(), idk.end(), a[i][2]) - idk.begin() + 1), i};
v[2 * i] = {1, a[i][1], (int)(lower_bound(idk.begin(), idk.end(), a[i][3]) - idk.begin() + 1), i};
}
sort(v + 1, v + 2 * n + 1);
for (int i = 1; i <= 2 * n; i++) {
if (v[i].type == 1) {
update(1, 1, 2 * n, v[i].x, dp[v[i].ind]);
}
else {
ans = {0, 0};
query(1, 1, 2 * n, 1, v[i].x);
if (!ans.best) ans.count = 1;
dp[v[i].ind] = {ans.best + 1, ans.count};
}
}
ans = dp[1];
for (int i = 2; i <= n; i++)
ans = ans + dp[i];
cout << ans.best << " " << ans.count;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
5 ms |
1044 KB |
Output is correct |
9 |
Correct |
10 ms |
1752 KB |
Output is correct |
10 |
Correct |
21 ms |
2864 KB |
Output is correct |
11 |
Correct |
30 ms |
3104 KB |
Output is correct |
12 |
Correct |
58 ms |
5716 KB |
Output is correct |
13 |
Correct |
64 ms |
6344 KB |
Output is correct |
14 |
Correct |
76 ms |
8892 KB |
Output is correct |
15 |
Correct |
89 ms |
9376 KB |
Output is correct |
16 |
Correct |
117 ms |
9608 KB |
Output is correct |
17 |
Correct |
107 ms |
9944 KB |
Output is correct |
18 |
Correct |
90 ms |
10180 KB |
Output is correct |
19 |
Correct |
100 ms |
10000 KB |
Output is correct |
20 |
Correct |
114 ms |
10692 KB |
Output is correct |