QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472866 | #943. Dynamic Diameter | Nelofus | Compile Error | / | / | C++20 | 2.6kb | 2024-07-11 19:59:49 | 2024-07-11 19:59:50 |
Judging History
This is the latest submission verdict.
- [2024-07-11 19:59:50]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-07-11 19:59:49]
- Submitted
answer
include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 1e5 + 10;
std::basic_string<int> G[N];
int idx;
i64 mxw;
i64 wgt[N];
struct edge {
int id;
int v;
} E[N << 1];
void add(int u, int v, int eid) {
E[++idx] = {eid, v};
G[u] += idx;
E[++idx] = {eid, u};
G[v] += idx;
}
// n 条边, 进入与离开的位置。
int in[N], out[N];
i64 a[N << 1];
int tot;
void dfs(int u, int fa) {
for (const int &i : G[u]) {
if (E[i].v == fa)
continue;
a[++tot] = wgt[E[i].id];
in[E[i].id] = tot;
dfs(E[i].v, u);
a[++tot] = -wgt[E[i].id];
out[E[i].id] = tot;
}
}
int n, m;
struct node {
int l, r;
i64 sum;
i64 lans, rans;
i64 lmax, rmin;
i64 maxv;
i64 ans;
} tr[N << 3];
inline void pushup(int u) {
const node &ls = tr[u << 1], &rs = tr[u << 1 | 1];
node &rt = tr[u];
rt.sum = ls.sum + rs.sum;
rt.ans = std::max({ls.ans, rs.ans, ls.rans + rs.lmax, rs.lans - ls.rmin});
rt.lans = std::max({ls.lans, rs.lans - ls.sum, ls.maxv + rs.lmax});
rt.rans = std::max({rs.rans, rs.sum + ls.rans, rs.maxv - ls.rmin});
rt.lmax = std::max(ls.lmax, ls.sum + rs.lmax);
rt.rmin = std::min(rs.rmin, rs.sum + ls.rmin);
rt.maxv = std::max(ls.maxv + rs.sum, rs.maxv - ls.sum);
}
void build(int u, int l, int r) {
tr[u].l = l, tr[u].r = r;
if (l == r) {
tr[u].ans = tr[u].lans = tr[u].rans = abs(a[l]);
tr[u].sum = a[l];
tr[u].lmax = std::max(a[l], 0ll);
tr[u].rmin = std::min(a[l], 0ll);
tr[u].maxv = tr[u].ans;
return ;
}
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void modify(int u, int pos) {
if (tr[u].l == tr[u].r) {
tr[u].ans = tr[u].lans = tr[u].rans = abs(a[pos]);
tr[u].sum = a[pos];
tr[u].lmax = std::max(a[pos], 0ll);
tr[u].rmin = std::min(a[pos], 0ll);
tr[u].maxv = tr[u].ans;
return ;
}
int mid = tr[u].l + tr[u].r >> 1;
if (pos <= mid)
modify(u << 1, pos);
if (pos > mid)
modify(u << 1 | 1, pos);
pushup(u);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m >> mxw;
for (int i = 1; i < n; i++) {
int u, v;
std::cin >> u >> v >> wgt[i];
add(u, v, i);
}
dfs(1, 0);
build(1, 1, 2 * n - 2);
// std::cout << tr[1].ans << '\n';
i64 lst = 0;
for (int _ = 1; _ <= m; _++) {
int d;
std::cin >> d;
d = (d + lst) % (n - 1) + 1;
std::cin >> wgt[d];
wgt[d] = (wgt[d] + lst) % mxw;
a[in[d]] = wgt[d];
a[out[d]] = -wgt[d];
modify(1, in[d]);
modify(1, out[d]);
lst = tr[1].ans;
std::cout << lst << '\n';
}
return 0;
}
Details
answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:10: error: ‘bits’ was not declared in this scope 1 | include <bits/stdc++.h> | ^~~~ answer.code:1:15: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 1 | include <bits/stdc++.h> | ^~~~ | std answer.code:1:1: error: ‘include’ does not name a type 1 | include <bits/stdc++.h> | ^~~~~~~ answer.code:6:6: error: ‘basic_string’ in namespace ‘std’ does not name a template type 6 | std::basic_string<int> G[N]; | ^~~~~~~~~~~~ answer.code:1:1: note: ‘std::basic_string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’? +++ |+#include <string> 1 | include <bits/stdc++.h> answer.code:8:1: error: ‘i64’ does not name a type 8 | i64 mxw; | ^~~ answer.code:9:1: error: ‘i64’ does not name a type 9 | i64 wgt[N]; | ^~~ answer.code: In function ‘void add(int, int, int)’: answer.code:17:9: error: ‘G’ was not declared in this scope 17 | G[u] += idx; | ^ answer.code: At global scope: answer.code:24:1: error: ‘i64’ does not name a type 24 | i64 a[N << 1]; | ^~~ answer.code: In function ‘void dfs(int, int)’: answer.code:27:29: error: ‘G’ was not declared in this scope 27 | for (const int &i : G[u]) { | ^ answer.code:30:17: error: ‘a’ was not declared in this scope 30 | a[++tot] = wgt[E[i].id]; | ^ answer.code:30:28: error: ‘wgt’ was not declared in this scope 30 | a[++tot] = wgt[E[i].id]; | ^~~ answer.code: At global scope: answer.code:42:9: error: ‘i64’ does not name a type 42 | i64 sum; | ^~~ answer.code:43:9: error: ‘i64’ does not name a type 43 | i64 lans, rans; | ^~~ answer.code:44:9: error: ‘i64’ does not name a type 44 | i64 lmax, rmin; | ^~~ answer.code:45:9: error: ‘i64’ does not name a type 45 | i64 maxv; | ^~~ answer.code:46:9: error: ‘i64’ does not name a type 46 | i64 ans; | ^~~ answer.code: In function ‘void pushup(int)’: answer.code:52:12: error: ‘struct node’ has no member named ‘sum’ 52 | rt.sum = ls.sum + rs.sum; | ^~~ answer.code:52:21: error: ‘const struct node’ has no member named ‘sum’ 52 | rt.sum = ls.sum + rs.sum; | ^~~ answer.code:52:30: error: ‘const struct node’ has no member named ‘sum’ 52 | rt.sum = ls.sum + rs.sum; | ^~~ answer.code:53:12: error: ‘struct node’ has no member named ‘ans’ 53 | ...