Add a bunch of other problems.
Some are not finished...
This commit is contained in:
@@ -0,0 +1,231 @@
|
||||
/* Problem URL: https://codeforces.com/gym/105231/problem/L */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n, m, k, t;
|
||||
cin >> n >> m >> k >> t;
|
||||
|
||||
vl fds(n);
|
||||
cin >> fds;
|
||||
|
||||
V<tuple<int, int, int>> gates;
|
||||
|
||||
rep(i, k) {
|
||||
int n, l, r;
|
||||
cin >> n >> l >> r;
|
||||
n--;
|
||||
|
||||
gates.emplace_back(n, l, r);
|
||||
}
|
||||
|
||||
ll inf = INT64_MAX >> 1;
|
||||
vvl dis(n, vl(k, inf));
|
||||
|
||||
V<V<pair<int, ll>>> graph(n);
|
||||
|
||||
auto dijkstra = [&](int i, int k) {
|
||||
priority_queue<pair<ll, int>, V<pair<ll, int>>, greater<>> pq;
|
||||
|
||||
dis[i][k] = 0;
|
||||
pq.emplace(0, i);
|
||||
|
||||
while (!pq.empty()) {
|
||||
auto [c, now] = pq.top();
|
||||
pq.pop();
|
||||
|
||||
if (c > dis[now][k]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto [j, cost] : graph[now]) {
|
||||
if (dis[j][k] > cost + c) {
|
||||
dis[j][k] = cost + c;
|
||||
pq.emplace(cost + c, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
while (m--) {
|
||||
int a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
a--, b--;
|
||||
|
||||
graph[a].emplace_back(b, c);
|
||||
graph[b].emplace_back(a, c);
|
||||
}
|
||||
|
||||
rep(i, k) {
|
||||
dijkstra(get<0>(gates[i]), i);
|
||||
}
|
||||
|
||||
vi pos(t + 2, 0);
|
||||
for (auto [i, l, r] : gates) {
|
||||
pos[l]++;
|
||||
pos[r + 1]--;
|
||||
}
|
||||
|
||||
nrep(i, 1, t) {
|
||||
pos[i] += pos[i - 1];
|
||||
}
|
||||
|
||||
vl ans(t + 2, 0);
|
||||
|
||||
rep(i, n) {
|
||||
priority_queue<pair<ll, int>> pq;
|
||||
rep(j, k) {
|
||||
pq.emplace(dis[i][j], j);
|
||||
}
|
||||
|
||||
set<tuple<ll, int ,int>> inter;
|
||||
while (!pq.empty()) {
|
||||
auto [c, j] = pq.top();
|
||||
pq.pop();
|
||||
|
||||
auto [n, l, r] = gates[j];
|
||||
|
||||
auto itr = inter.begin();
|
||||
while (itr != inter.end()) {
|
||||
auto [cost, tl, tr] = *itr;
|
||||
if (l <= tl && r >= tr) {
|
||||
inter.erase(make_tuple(cost, tl, tr));
|
||||
ans[tl] -= cost * fds[i];
|
||||
ans[tr + 1] += cost * fds[i];
|
||||
itr = inter.begin();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l >= tl && r <= tr) {
|
||||
inter.erase(make_tuple(cost, tl, tr));
|
||||
ans[tl] -= cost * fds[i];
|
||||
ans[tr + 1] += cost * fds[i];
|
||||
if (l - 1 >= tl) {
|
||||
inter.emplace(cost, tl, l - 1);
|
||||
ans[tl] += cost * fds[i];
|
||||
ans[l] -= cost * fds[i];
|
||||
}
|
||||
if (r + 1 <= tr) {
|
||||
inter.emplace(cost, r + 1, tr);
|
||||
ans[r + 1] += cost * fds[i];
|
||||
ans[tr + 1] -= cost * fds[i];
|
||||
}
|
||||
itr = inter.begin();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l >= tl && l <= tr) {
|
||||
inter.erase(make_tuple(cost, tl, tr));
|
||||
ans[tl] -= cost * fds[i];
|
||||
ans[tr + 1] += cost * fds[i];
|
||||
if (l - 1 >= tl) {
|
||||
inter.emplace(cost, tl, l - 1);
|
||||
ans[tl] += cost * fds[i];
|
||||
ans[l] -= cost * fds[i];
|
||||
}
|
||||
itr = inter.begin();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r >= tl && r <= tr) {
|
||||
inter.erase(make_tuple(cost, tl, tr));
|
||||
ans[tl] -= cost * fds[i];
|
||||
ans[tr + 1] += cost * fds[i];
|
||||
if (r + 1 <= tr) {
|
||||
inter.emplace(cost, r + 1, tr);
|
||||
ans[r + 1] += cost * fds[i];
|
||||
ans[tr + 1] -= cost * fds[i];
|
||||
}
|
||||
itr = inter.begin();
|
||||
continue;
|
||||
}
|
||||
|
||||
itr++;
|
||||
}
|
||||
|
||||
inter.emplace(c, l, r);
|
||||
ans[l] += c * fds[i];
|
||||
ans[r + 1] -= c * fds[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= t; i++) {
|
||||
ans[i] += ans[i - 1];
|
||||
if (!pos[i]) {
|
||||
cout << "-1\n";
|
||||
continue;
|
||||
}
|
||||
cout << ans[i] << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user