#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
const int maxn = 100100;
const ll mod = 30013;
map<int, int> up, down;
int tree[2*4*maxn][2];
int upmax, downmax, n;
int dp[maxn];
int dpways[maxn];
struct trapez {
public:
int a, b, c, d;
} arr[maxn];
void update(int ux, int value, int valueb, int li=0, int ri=downmax, int index=1) {
if(li==ri) {
tree[index][0] += value;
tree[index][1] += valueb;
if(tree[index][1] > mod)
tree[index][1] -= mod;
}
else {
int mid = (li+ri)/2;
if(ux <= mid) update(ux, value, valueb, li, mid, 2*index);
else if(ux > mid) update(ux, value, valueb, mid+1, ri, 2*index+1);
if(tree[2*index][0] == tree[2*index+1][0]) {
tree[index][0] = tree[2*index][0];
tree[index][1] = (tree[2*index][1] + tree[2*index+1][1]);
if(tree[index][1] > mod) tree[index][1] -= mod;
}
else if(tree[2*index][0] > tree[2*index+1][0]) {
tree[index][0] = tree[2*index][0];
tree[index][1] = tree[2*index][1];
}
else {
tree[index][0] = tree[2*index+1][0];
tree[index][1] = tree[2*index+1][1];
}
}
}
pii emp;
pii query(int ql, int qr, int li=0, int ri=downmax, int index=1) {
if(li > qr || ri < ql) return emp;
else if(li >= ql && ri <= qr) return make_pair(tree[index][0], tree[index][1]);
else {
int mid = (li+ri)/2;
pii a = query(ql,qr,li,mid,2*index);
pii b = query(ql,qr,mid+1,ri,2*index+1);
if(a.first == b.first) return make_pair(a.first, (a.second+b.second)%mod);
else if(a.first > b.first) return a;
else return b;
}
}
vector<pair<int, bool> > events[2*maxn];
int main() {
emp.first = 0;
emp.second = 0;
scanf("%d", &n);
for(int i=0;i<n;i++) {
scanf("%d %d %d %d", &arr[i].a, &arr[i].b, &arr[i].c, &arr[i].d);
up[arr[i].a] = 1;
up[arr[i].b] = 1;
down[arr[i].c] = 1;
down[arr[i].d] = 1;
}
upmax = downmax = 1;
for(auto i:up) {
up[i.first] = upmax++;
}
for(auto i:down) {
down[i.first] = downmax++;
}
for(int i=0;i<n;i++) {
arr[i].a = up[arr[i].a];
arr[i].b = up[arr[i].b];
arr[i].c = down[arr[i].c];
arr[i].d = down[arr[i].d];
events[arr[i].a].push_back(make_pair(i, true));
events[arr[i].b].push_back(make_pair(i, false));
}
update(0,0,1);
int result = 0;
int ways = 0;
for(int i=1;i<=upmax;i++) {
for(auto j:events[i]) {
if(j.second) {
pii temp = query(0, arr[j.first].c);
dp[j.first] = temp.first + 1;
dpways[j.first] = temp.second;
if(dp[j.first] > result) {
result = dp[j.first];
ways = dpways[j.first];
}
else if(dp[j.first] == result) {
ways += dpways[j.first];
if(ways > mod) ways-=mod;
}
}
else update(arr[j.first].d, dp[j.first], dpways[j.first]);
}
}
printf("%d %d", result, ways);
return 0;
}
Compilation message
trapezoid.cpp: In function 'int main()':
trapezoid.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
trapezoid.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &arr[i].a, &arr[i].b, &arr[i].c, &arr[i].d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
5224 KB |
Output is correct |
3 |
Correct |
7 ms |
5300 KB |
Output is correct |
4 |
Correct |
8 ms |
5500 KB |
Output is correct |
5 |
Correct |
11 ms |
5756 KB |
Output is correct |
6 |
Correct |
19 ms |
6184 KB |
Output is correct |
7 |
Correct |
18 ms |
6652 KB |
Output is correct |
8 |
Correct |
24 ms |
6800 KB |
Output is correct |
9 |
Correct |
46 ms |
8520 KB |
Output is correct |
10 |
Correct |
92 ms |
11944 KB |
Output is correct |
11 |
Correct |
117 ms |
13084 KB |
Output is correct |
12 |
Correct |
260 ms |
21092 KB |
Output is correct |
13 |
Correct |
314 ms |
23936 KB |
Output is correct |
14 |
Correct |
374 ms |
28388 KB |
Output is correct |
15 |
Correct |
476 ms |
30024 KB |
Output is correct |
16 |
Execution timed out |
527 ms |
31368 KB |
Time limit exceeded |
17 |
Execution timed out |
533 ms |
32680 KB |
Time limit exceeded |
18 |
Correct |
499 ms |
34020 KB |
Output is correct |
19 |
Execution timed out |
547 ms |
34916 KB |
Time limit exceeded |
20 |
Execution timed out |
597 ms |
36708 KB |
Time limit exceeded |