#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 30013;
int n;
struct Segment
{
int x;
int y;
};
bool cross(const Segment& fr, const Segment& sc)
{
return fr.x <= sc.y && fr.y >= sc.x;
}
struct Trapezoid
{
Segment up;
Segment down;
};
Trapezoid a[maxn];
pair<long long, long long> dp[maxn];
struct Event
{
int upPos;
int downPos;
int type;
int idx;
Event()
{
}
Event(int _upPos, int _downPos, int _type, int _idx)
{
upPos = _upPos;
downPos = _downPos;
type = _type;
idx = _idx;
}
bool operator < (const Event& other) const
{
return upPos < other.upPos;
}
};
vector<Event> events;
unordered_map<int, int> compressedValues;
vector<int> toCompress;
struct Node
{
long long maxLength;
long long cnt;
Node()
{
}
Node(long long _maxLength, long long _cnt)
{
maxLength = _maxLength;
cnt = _cnt;
}
};
struct SegmentTree
{
Node tree[8 * maxn];
Node combine(Node lhs, Node rhs)
{
if (lhs.maxLength < rhs.maxLength)
{
return rhs;
}
if (rhs.maxLength < lhs.maxLength)
{
return lhs;
}
return Node(lhs.maxLength, (lhs.cnt + rhs.cnt) % mod);
}
void update(int node, int l, int r, int pos, pair<long long, long long> val)
{
if (l == r)
{
tree[node] = combine(tree[node], Node(val.first, val.second));
return;
}
int mid = (l + r) / 2;
if (pos <= mid)
{
update(2 * node, l, mid, pos, val);
}
else
{
update(2 * node + 1, mid + 1, r, pos, val);
}
tree[node] = combine(tree[2 * node], tree[2 * node + 1]);
}
Node query(int node, int l, int r, int ql, int qr)
{
if (ql <= l && r <= qr)
{
return tree[node];
}
int mid = (l + r) / 2;
Node result = Node(0, 0);
if (ql <= mid)
{
result = combine(result, query(2 * node, l, mid, ql, qr));
}
if (qr >= mid + 1)
{
result = combine(result, query(2 * node + 1, mid + 1, r, ql, qr));
}
return result;
}
void update(int pos, pair<long long, long long> val)
{
update(1, 1, 2 * n, pos, val);
}
pair<long long, long long> query(int l, int r)
{
Node res = query(1, 1, 2 * n, l, r);
res = combine(Node(0, 1), res);
return make_pair(res.maxLength, res.cnt);
}
};
SegmentTree tree;
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i].up.x >> a[i].up.y >> a[i].down.x >> a[i].down.y;
}
sort(a + 1, a + n + 1, [&](const Trapezoid& fr, const Trapezoid& sc)
{
return fr.down.x < sc.down.x;
});
for (int i = 1; i <= n; ++i)
{
events.push_back(Event(a[i].up.x, a[i].down.x, 1, i));
events.push_back(Event(a[i].up.y, a[i].down.y, 2, i));
toCompress.push_back(a[i].down.x);
toCompress.push_back(a[i].down.y);
}
sort(toCompress.begin(), toCompress.end());
int currNumber = 0;
for (int i = 0; i < toCompress.size(); ++i)
{
if (i == 0 || toCompress[i] != toCompress[i - 1])
{
++currNumber;
}
compressedValues[toCompress[i]] = currNumber;
}
sort(events.begin(), events.end());
pair<long long, long long> result = make_pair(1, 1);
for (int i = 1; i <= n; ++i)
{
dp[i].first = 0;
dp[i].second = 1;
}
for (int i = 0; i < events.size(); ++i)
{
int up = events[i].upPos;
int down = compressedValues[events[i].downPos];
int type = events[i].type;
int idx = events[i].idx;
if (type == 1) // calculate
{
if (down >= 2)
{
dp[idx] = tree.query(1, down - 1);
}
++dp[idx].first;
//cout << idx << " :: " << dp[idx].first << endl;
if (result.first < dp[idx].first)
{
result.first = dp[idx].first;
result.second = dp[idx].second;
}
else if (result.first == dp[idx].first)
{
result.second += dp[idx].second;
result.second %= mod;
}
}
else // add up to tree
{
tree.update(down, dp[idx]);
}
}
cout << result.first << ' ' << result.second << endl;
return 0;
}
Compilation message
trapezoid.cpp: In function 'int main()':
trapezoid.cpp:194:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
194 | for (int i = 0; i < toCompress.size(); ++i)
| ~~^~~~~~~~~~~~~~~~~~~
trapezoid.cpp:214:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
214 | for (int i = 0; i < events.size(); ++i)
| ~~^~~~~~~~~~~~~~~
trapezoid.cpp:216:13: warning: unused variable 'up' [-Wunused-variable]
216 | int up = events[i].upPos;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
3 ms |
3160 KB |
Output is correct |
7 |
Correct |
4 ms |
3160 KB |
Output is correct |
8 |
Correct |
5 ms |
3612 KB |
Output is correct |
9 |
Correct |
10 ms |
4632 KB |
Output is correct |
10 |
Correct |
19 ms |
6932 KB |
Output is correct |
11 |
Correct |
25 ms |
7444 KB |
Output is correct |
12 |
Correct |
56 ms |
13560 KB |
Output is correct |
13 |
Correct |
79 ms |
14336 KB |
Output is correct |
14 |
Correct |
85 ms |
20876 KB |
Output is correct |
15 |
Correct |
98 ms |
20988 KB |
Output is correct |
16 |
Correct |
111 ms |
21200 KB |
Output is correct |
17 |
Correct |
120 ms |
21744 KB |
Output is correct |
18 |
Correct |
82 ms |
24312 KB |
Output is correct |
19 |
Correct |
123 ms |
23368 KB |
Output is correct |
20 |
Correct |
132 ms |
25380 KB |
Output is correct |