# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880501 | kh0i | trapezoid (balkan11_trapezoid) | C++17 | 92 ms | 17088 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 "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define F first
#define S second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
assert(l <= r);
return uniform_int_distribution<ll> (l, r)(rng);
}
const ll mod = 30013;
struct Trapezoid{
int a, b, c, d;
bool operator < (const Trapezoid &o){ return a < o.a; }
};
pll combine(const pll &A, const pll &B){
pll res;
res.F = max(A.F, B.F);
if(A.F == B.F) res.S = (A.S + B.S) % mod;
else if(A.F < B.F) res.S = B.S;
else res.S = A.S;
return res;
}
struct SegTri{
vector<pll> st;
int n;
void init(int _n){
n = _n;
st.resize(4 * n + 6, {0, 0});
}
void _update(int id, int l, int r, int pos, pll val){
if(l == r){
st[id] = combine(st[id], val);
return;
}
int mid = (l + r) / 2;
if(pos <= mid)
_update(2 * id, l, mid, pos, val);
else
_update(2 * id + 1, mid + 1, r, pos, val);
st[id] = combine(st[2 * id], st[2 * id + 1]);
}
pll _get(int id, int l, int r, int tl, int tr){
if(l > tr or tl > r)
return {0, 0};
if(tl <= l and r <= tr)
return st[id];
int mid = (l + r) / 2;
return combine(_get(2 * id, l, mid, tl, tr), _get(2 * id + 1, mid + 1, r, tl, tr));
}
void update(int pos, pll val){
_update(1, 1, n, pos, val);
}
pll get(int l, int r){
if(l > r)
return {0, 0};
return _get(1, 1, n, l, r);
}
} dak;
const int N = 1e5 + 3;
int n;
vector<Trapezoid> tr;
vector<int> xx = {0};
pll f[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i){
int a, b, c, d;
cin >> a >> b >> c >> d;
tr.push_back({a, b, c, d});
xx.push_back(c);
xx.push_back(d);
}
sort(all(xx));
xx.resize(unique(all(xx)) - xx.begin());
sort(all(tr));
for(auto &[a, b, c, d] : tr){
c = lower_bound(all(xx), c) - xx.begin() + 1;
d = lower_bound(all(xx), d) - xx.begin() + 1;
}
dak.init(sz(xx) + 2);
dak.update(1, {0, 1});
int cur = 0;
for(int i = 0; i < sz(tr); ++i){
//debug(tr[i].a, tr[i].b, tr[i].c, tr[i].d);
while(cur < i and tr[cur].b < tr[i].a){
debug(tr[cur].d, f[cur]);
dak.update(tr[cur].d, f[cur]);
++cur;
};
f[i] = dak.get(1, tr[i].c - 1);
f[i].F += 1;
debug(i, f[i]);
}
pll res = {0, 0};
for(int i = 0; i < sz(tr); ++i)
res = combine(res, f[i]);
cout << res.F << ' ' << res.S << '\n';
}
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(0);
#define task "troll"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
// cin >> test;
for(int i = 1; i <= test; ++i){
// cout << "Case #" << i << ": ";
solve();
}
#ifdef LOCAL
cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |