QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#805259 | #7578. Salty Fish | Rong7 | AC ✓ | 570ms | 103828kb | C++14 | 2.8kb | 2024-12-08 15:05:16 | 2024-12-08 15:05:18 |
Judging History
answer
// Go in my style.
// Not afraid to dark.
#include <bits/stdc++.h>
using namespace std;
clock_t sttime;
#define STCLOCK sttime = clock ();
#define TIMENOW fprintf (stderr, "\nNOW TIME COSSEMED: %0.4lf\n", 1.0 * (clock () - sttime) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))
#define int 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 (int 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 = 3e5;
int n, m, fa[N + 5], x[N + 5], d[N + 5], c[N + 5], a[N + 5];
int dep[N + 5], md[N + 5], ls[N + 5];
vector < int > cm[N + 5], to[N + 5];
map < int , int > cf[N + 5];
void init (int u){
md[u] = dep[u]; ls[u] = 0;
for (int v : to[u]){
dep[v] = dep[u] + 1, init (v);
if (md[v] > md[u])
md[u] = md[v], ls[u] = v;
}
}
void sol (int u, int r){
if (ls[u]) sol (ls[u], r);
for (int v : to[u])
if (v != ls[u]){
sol (v, v);
for (auto x : cf[v])
cf[r][x.first] += x.second;
}
cf[r][dep[u]] += a[u];
for (int o : cm[u]){
int rd = c[o], del;
map < int , int > ::iterator it;
while (rd > 0 && cf[r].begin () != (it = cf[r].upper_bound (dep[u] + d[o]))){
-- it; del = min (rd, it->second);
it->second -= del, rd -= del;
if (it->second == 0) cf[r].erase (it);
}
}
}
inline void ARKNIGHTS (){
io::read (n), io::read (m);
for (int i = 1;i <= n;++ i) to[i].clear ();
for (int i = 2;i <= n;++ i) to[io::read (fa[i])].push_back (i);
for (int i = 1;i <= n;++ i) io::read (a[i]);
for (int i = 1;i <= n;++ i) cm[i].clear (), cf[i].clear ();
for (int i = 1;i <= m;++ i){
io::read (x[i]), io::read (d[i]), io::read (c[i]);
cm[x[i]].push_back (i);
}
dep[1] = 1, init (1);
sol (1, 1);
int ans = 0;
for (auto x : cf[1]) ans += x.second;
io::write (ans), putchar ('\n');
}
signed main (){
STCLOCK
for (int T = io::read ();T --;) ARKNIGHTS ();
TIMENOW
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 48208kb
input:
1 6 3 1 1 2 2 3 2 5 4 3 3 2 2 1 3 3 1 7 1 2 4
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 570ms
memory: 103828kb
input:
1003 100 100 1 2 3 4 5 6 7 8 9 10 6 1 2 4 1 11 17 14 17 2 13 8 8 5 11 7 18 6 2 10 23 11 13 3 9 1 33 20 3 9 32 35 11 41 42 29 33 45 21 35 9 36 12 54 19 24 57 31 32 5 3 10 46 15 46 48 20 44 5 41 67 7 18 30 27 6 29 69 57 75 62 74 18 64 17 21 38 60 79 69 54 90 83 83 31 96 31 93 53 152 498 653 559 287 38...
output:
20180 17083 14650 19924 15814 20189 20894 18175 18478 13758 20217 23680 15562 12882 18046 18132 20548 17000 23734 18740 24814 16728 20979 19727 16450 21717 15739 22081 17803 23024 14820 21503 23497 15804 18097 17197 21236 21286 14250 11632 18335 12317 16313 22840 18583 15245 19331 25978 22388 17091 ...
result:
ok 1003 numbers