# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874337 | Macker | trapezoid (balkan11_trapezoid) | C++17 | 192 ms | 11516 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream> // #include <fstream>
#include <vector>
#include <list>
#include <algorithm>
#include <math.h>
#include <tuple>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <array>
#include <climits>
#include <cassert>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
//ifstream cin("optmilk.in");
//ofstream cout("optmilk.out");
vector<pair<int, int>> st;
int len = 1;
int mod = 30013;
vector<int> xs;
int cx(int x) {
return lower_bound(all(xs), x) - xs.begin();
}
pair<int, int> query(int f, int t, int i = 1, int s = 0, int e = len) {
if (f >= e || t <= s) return { -1, -1 };
if (f <= s && e <= t) return st[i];
pair<int, int> a = query(f, t, i * 2, s, (s + e) / 2);
pair<int, int> b = query(f, t, i * 2 + 1, (s + e) / 2, e);
if (a.first > b.first) return a;
if (a.first < b.first) return b;
if (a.first == b.first) return { a.first, (a.second + b.second) % mod };
}
void add(int idx, int val, int cnt, int i = 1, int s = 0, int e = len) {
if (s > idx || e <= idx) return;
if (s == idx && s == e - 1) {
if (st[i].first == val) st[i].second = (st[i].second + cnt) % mod;
if (st[i].first < val) st[i] = { val, cnt % mod };
return;
}
add(idx, val, cnt, i * 2, s, (s + e) / 2);
add(idx, val, cnt, i * 2 + 1, (s + e) / 2, e);
if (st[i * 2].first == st[i * 2 + 1].first) st[i] = { st[i * 2].first, st[i * 2].second + st[i * 2 + 1].second };
if (st[i * 2].first > st[i * 2 + 1].first) st[i] = st[i * 2];
if (st[i * 2].first < st[i * 2 + 1].first) st[i] = st[i * 2 + 1];
st[i].second %= mod;
}
int main()
{
int n; cin >> n;
vector<array<int, 5>> ev; // y, t - 0add/1query, x1, -1/(val, val)
for (int i = 0; i < n; i++) {
int y, yy, x, xx; cin >> x >> xx >> y >> yy;
ev.push_back({ y, 1, x, yy, -1 });
ev.push_back({ yy, 0, xx, -1, -1 });
xs.push_back(x);
xs.push_back(xx);
}
sort(all(ev));
sort(all(xs));
while (len < xs.size()) len *= 2;
st.resize(len * 2, { 0, 0 });
for (int i = 0; i < ev.size(); i++) {
int y = ev[i][0], t = ev[i][1], x = ev[i][2];
if (t == 1) {
pair<int, int> val = query(0, cx(x) + 1);
if (val.first == 0) val.second = 1;
array<int, 5>& tmp = *lower_bound(all(ev), array<int, 5>({ev[i][3], -1, -1, -1, -1 }));
tmp[3] = val.first + 1; tmp[4] = val.second % mod;
}
else {
int ans = ev[i][3], cnt = ev[i][4];
add(cx(x), ans, cnt);
}
}
cout << st[1].first << " " << st[1].second % mod << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |