# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1094158 | VMaksimoski008 | 사다리꼴 (balkan11_trapezoid) | C++17 | 218 ms | 31188 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 30013;
const int LOG = 20;
const int maxn = 1e5 + 5;
struct SegTree {
int n;
vector<pii> tree;
SegTree(int _n) : n(_n), tree(4*_n, {0, 0}) {}
pii merge(pii a, pii b) {
if(a.first > b.first) return a;
if(a.first < b.first) return b;
return { a.first, (a.second + b.second) % mod };
}
void update(int u, int tl, int tr, int p, int v, int w) {
if(tl == tr) {
tree[u] = merge(tree[u], { v, w });
} else {
int tm = (tl + tr) / 2;
if(p <= tm) update(2*u, tl, tm, p, v, w);
else update(2*u+1, tm+1, tr, p, v, w);
tree[u] = merge(tree[2*u], tree[2*u+1]);
}
}
pii query(int u, int tl, int tr, int l, int r) {
if(l > tr || tl > r) return { 0, 0 };
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return merge(query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r));
}
void update(int p, int v, int w) { update(1, 0, n-1, p, v, w); }
pii query(int l, int r) { return query(1, 0, n-1, l, r); }
};
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n; cin >> n;
vector<array<int, 4> > v(n);
set<int> s;
for(int i=0; i<n; i++) {
for(int j=0; j<4; j++) cin >> v[i][j];
for(int j=0; j<4; j++) s.insert(v[i][j]);
}
vector<int> comp(s.begin(), s.end());
sort(v.begin(), v.end());
for(int i=0; i<n; i++)
for(int j=0; j<4; j++) v[i][j] = lower_bound(comp.begin(), comp.end(), v[i][j]) - comp.begin();
vector<pii> dp(n);
SegTree tree(comp.size());
priority_queue<pii> pq;
for(int i=0; i<n; i++) {
dp[i] = { 1, 1 };
while(!pq.empty() && pq.top().first < v[i][0]) {
tree.update(v[pq.top().second][3], dp[pq.top().second].first, dp[pq.top().second].second);
pq.pop();
}
auto res = tree.query(0, v[i][2]-1);
if(res.first) dp[i] = { res.first + 1, res.second };
pq.push({ v[i][1], i });
}
while(!pq.empty()) {
tree.update(v[pq.top().second][3], dp[pq.top().second].first, dp[pq.top().second].second);
pq.pop();
}
auto [mx, ways] = tree.query(0, comp.size() - 1);
cout << mx << " " << ways << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |