Add a lot more of my solutions.

I don't remember which ones doesn't pass though
This commit is contained in:
2025-09-12 14:51:10 -03:00
parent 2a94def2d6
commit 8b03716512
114 changed files with 14012 additions and 95 deletions

View File

@@ -1,9 +1,7 @@
/* Problem URL: https://cses.fi/problemset/task/1140 */
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define rmin(a, b) a = min(a, b)
@@ -69,52 +67,6 @@ auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
return is;
}
class segtree {
vl seg;
ll _query(int i, int l, int r, int ql, int qr) {
if (l > qr || r < ql) {
return -1;
}
if (l >= ql && r <= qr) {
return seg[i];
}
int mid = (l + r) / 2;
return max(_query(i * 2, l, mid, ql, qr), _query(i * 2 + 1, mid + 1, r, ql, qr));
}
public:
segtree() = delete;
segtree(vl &items): seg(items.size() * 2) {
size_t n = items.size();
for (size_t i = n; i < n * 2; i++) {
seg[i] = items[i - n];
}
for (size_t i = n - 1; i > 0; i--) {
seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
}
}
void update(ll v, int i) {
i += seg.size() / 2;
if (seg[i] >= v) {
return;
}
seg[i] = v;
i /= 2;
for (; i > 0; i /= 2) {
seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
}
}
ll query(int i) {
return _query(1, 0, seg.size() / 2 - 1, 0, i);
}
};
int main()
{
ios::sync_with_stdio(false);
@@ -122,39 +74,33 @@ int main()
int n;
cin >> n;
V<tuple<ll, ll, ll>> fds(n);
set<ll> lol;
for (auto &[i, e, v] : fds) {
cin >> i >> e >> v;
lol.insert(e);
V<tuple<ll, ll, ll>> q(n);
map<ll, int> var;
for (auto &[x, y, z] : q) {
cin >> x >> y >> z;
var[x] = 0;
var[y] = 0;
}
pair<vl, vl> ends(vl(lol.size(), 0), vl(lol.size()));
auto itr = lol.begin();
for (size_t i = 0; itr != lol.end(); i++, itr++) {
ends.second[i] = *itr;
int v = 0;
for (auto &i : var) {
i.second = v;
v++;
}
sort(fds.begin(), fds.end());
ll neutral = 1e9 + 1;
while (__builtin_popcount(ends.second.size()) != 1) {
ends.first.push_back(-1);
ends.second.push_back(neutral++);
V<V<pair<int, ll>>> proj(var.size());
for (auto [s, e, v] : q) {
proj[var[e]].emplace_back(var[s], v);
}
segtree seg(ends.first);
for (auto [i, f, v] : fds) {
auto itr = lower_bound(ends.second.begin(), ends.second.end(), i);
if (itr == ends.second.begin()) {
seg.update(v, lower_bound(ends.second.begin(), ends.second.end(), f) - ends.second.begin());
continue;
vl dp(var.size() + 1);
nrep(i, 1, dp.size()) {
dp[i] += dp[i - 1];
for (auto [s, v] : proj[i - 1]) {
rmax(dp[i], dp[s] + v);
}
ll up = seg.query(itr - ends.second.begin() - 1) + v;
seg.update(up, lower_bound(ends.second.begin(), ends.second.end(), f) - ends.second.begin());
}
cout << seg.query(ends.first.size() - 1) << '\n';
cout << dp.back() << '\n';
}