QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708888 | #7905. Ticket to Ride | IllusionaryDominance | WA | 2ms | 3724kb | C++20 | 2.7kb | 2024-11-04 09:16:53 | 2024-11-04 09:16:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 10000 + 5;
const ll INF64 = 1e18;
int N, M, l[MAX_N], r[MAX_N], val[MAX_N], fath[MAX_N];
ll suml[MAX_N], tot, f[MAX_N], ans[MAX_N];
vector <pair <int, int>> rightp[MAX_N];
struct Node{
int pre, suf;
ll val, lazy;
void clear() {
pre = -1;
suf = -1;
val = 0;
lazy = 0;
}
inline ll operator () () const {return val + lazy;}
}node[MAX_N];
int tl;
int Find(int x) {
return x == fath[x] ? x : fath[x] = Find(fath[x]);
}
void ins(int i) {
node[i].pre = tl;
if (tl != -1) {
node[tl].suf = i;
}
tl = i;
}
void del(int i) {
if (node[i].pre != -1) {
node[node[i].pre].suf = node[i].suf;
node[node[i].pre].lazy += node[i].lazy;
}
if (node[i].suf != -1) {
node[node[i].suf].pre = node[i].pre;
fath[Find(node[i].suf)] = Find(i);
}
node[i].clear();
}
void solve() {
tot = 0;
for (int i = 1; i <= N; i ++) {
suml[i] = 0;
rightp[i].clear();
}
cin >> N >> M;
for (int i = 1; i <= M; i ++) {
cin >> l[i] >> r[i] >> val[i];
l[i] ++; tot += val[i]; suml[l[i]] += val[i];
rightp[r[i]].emplace_back(l[i], val[i]);
}
ans[N] = tot;
for (int i = 1; i <= N; i ++) {
f[i] = INF64;
}
f[0] = 0;
for (int i = 1; i < N; i ++) {
static ll g[MAX_N];
for (int j = 0; j <= N; j ++) {
fath[j] = j;
node[j].clear();
}
tl = -1;
ll res = INF64;
node[i - 1].val = f[i - 1];
ins(i - 1);
for (int j = i; j <= N; j ++) {
node[tl].lazy += suml[j];
g[j] = node[tl]();
for (auto [lp, v] : rightp[j]) {
int k = Find(lp - 1);
if (k >= i - 1) {
node[k].lazy -= v;
while (node[k].suf != -1 && node[k]() <= node[node[k].suf].val) {
del(node[k].suf);
}
}
}
if (node[tl]() > f[j]) {
node[j].val = f[j];
ins(j);
}else {
fath[j] = Find(j - 1);
}
res = min(res, g[j]);
}
memcpy(f, g, sizeof(ll) * (N + 1));
ans[N - i] = tot - res;
}
for (int i = 1; i <= N; i ++) cout << ans[i] << "\n "[i < N];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
input:
2 4 3 0 2 3 3 4 2 0 3 1 3 1 1 3 100
output:
2 3 5 6 0 100 100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3672kb
input:
1000 2 9 0 2 396628655 1 2 268792718 0 2 16843338 1 2 717268783 0 1 693319712 0 1 856168102 1 2 407246545 1 2 527268921 0 1 536134606 6 2 2 5 451394766 0 5 695984050 9 7 0 6 73936815 2 9 505041862 4 5 223718927 5 7 179262261 3 5 449258178 0 5 493128 0 3 994723920 6 6 3 5 433389755 2 4 773727734 4 5 ...
output:
2085622420 4419671380 0 0 451394766 451394766 1147378816 1147378816 223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 127680943 773727734 2547963408 3109034106 2675644351 2675644351 976357580 1594205360 2103791342 2721639122 3562857638 3936588085 4180705...
result:
wrong answer 4th lines differ - expected: '127680943 773727734 1334798432 2227456393 2675644351 2675644351', found: '127680943 773727734 2547963408 3109034106 2675644351 2675644351'