QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#446433 | #7905. Ticket to Ride | Rong7 | WA | 2ms | 4376kb | C++14 | 3.8kb | 2024-06-17 10:26:05 | 2024-06-17 10:26:05 |
Judging History
answer
// Not afraid to dark.
#include <bits/stdc++.h>
using namespace std;
clock_t start_time, end_time;
#define GET_START start_time = clock ();
#define GET_END end_time = clock (); fprintf (stderr, "TIME COSSEMED : %0.3lf\n", 1.0 * (end_time - start_time) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))
#define ll long long
namespace io {
int read_pos, read_dt; char read_char;
inline int read (int &p = read_pos){
p = 0, read_dt = 1; read_char = getchar ();
while (! isdigit (read_char)){
if (read_char == '-')
read_dt = - 1;
read_char = getchar ();
}
while (isdigit (read_char)){
p = (p << 1) + (p << 3) + read_char - 48;
read_char = getchar ();
}
return p = p * read_dt;
}
int write_sta[65], write_top;
inline void write (ll x){
if (x < 0)
putchar ('-'), x = - x;
write_top = 0;
do
write_sta[write_top ++] = x % 10, x /= 10;
while (x);
while (write_top)
putchar (write_sta[-- write_top] + 48);
}
}
const int N = 1e4;
int n, m;
ll f[N + 5], ans[N + 5];
struct node {
int l, r, v;
inline node (){
l = r = v = 0;
}
inline void read (){
io::read (l), io::read (r), io::read (v);
}
};
vector < node > tl[N + 5];
int fa[N + 5], rep[N + 5], cnt[N + 5];
int find (int v){
if (fa[v] == v)
return fa[v];
return fa[v] = find (fa[v]);
}
inline void Merge (int u, int v){
u = find (u), v = find (v);
if (cnt[u] < cnt[v])
swap (u, v);
if (u != v){
fa[v] = u;
rep[u] = min (rep[u], rep[v]);
cnt[u] += cnt[v];
}
}
struct ty {
int pre, nex, delta, cc;
ty (){
pre = 0, nex = n + 1, delta = 0, cc = 0;
}
} te[N + 5];
inline void Addty (int u, int v, int i){
te[u].nex = te[v].pre = i;
te[i].pre = u, te[i].nex = v;
te[u].cc = f[i] - f[u];
te[i].cc = f[v] - f[i];
}
inline void Delty (int i){
static int u, v;
u = te[i].pre, v = te[i].nex;
te[u].delta += te[i].delta;
te[u].cc += te[i].cc;
te[u].nex = v;
te[v].pre = u;
}
inline void ARKNIGHTS (){
io::read (n), io::read (m);
for (int i = 1;i <= n;++ i)
tl[i].clear ();
for (int i = 1;i <= m;++ i){
node t; t.read ();
++ t.l;
tl[t.r].push_back (t);
}
for (int i = 1;i <= n;++ i){
f[i] = f[i - 1];
for (auto x : tl[i])
f[i] += x.v;
}
ans[n] = f[n], ans[0] = 0;
for (int t = 1;t < n;++ t){
for (int i = n;i > 0;-- i)
f[i] = f[i - 1];
for (int i = 0;i <= n + 1;++ i)
te[i] = ty ();
cnt[t] = 1, fa[t] = t, rep[t] = t;
Addty (0, n + 1, t);
for (int i = t + 1, las;i <= n;++ i){
for (auto x : tl[i])
if (x.l - 1 >= t){
int u = rep[find (x.l - 1)];
te[u].delta += x.v;
while (te[u].nex != n + 1 && te[u].delta >= te[u].cc){
Merge (u, te[u].nex);
Delty (te[u].nex);
}
}
cnt[i] = 1, fa[i] = i, rep[i] = i;
las = te[n + 1].pre;
if (f[i] <= f[las] + te[las].delta){
f[i] = f[las] + te[las].delta;
Merge (las, i);
} else
Addty (las, n + 1, i);
}
ans[n - t] = f[n];
}
for (int i = 1;i <= n;++ i)
io::write (ans[i]), putchar (' '); puts ("");
}
signed main (){
GET_START
for (int T = io::read ();T --;)
ARKNIGHTS ();
GET_END
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4376kb
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: 4272kb
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 1334798432 1334798432 2675644351 2675644351 976357580 1594205360 2103791342 2721639122 2965756455 3485691742 418...
result:
wrong answer 4th lines differ - expected: '127680943 773727734 1334798432 2227456393 2675644351 2675644351', found: '127680943 773727734 1334798432 1334798432 2675644351 2675644351 '