제출 #1039561

#제출 시각아이디문제언어결과실행 시간메모리
1039561juicyReconstruction Project (JOI22_reconstruction)C++17
100 / 100
887 ms30384 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 505, M = 1e5 + 5, inf = 1e9; int n, m, q; int mx[N]; vector<array<int, 2>> g[N]; array<int, 3> edges[M]; void add(int u, int v, int w) { g[u].push_back({v, w}); g[v].push_back({u, w}); } void ers(int u, int v, int w) { g[u].erase(find(g[u].begin(), g[u].end(), array<int, 2>{v, w})); g[v].erase(find(g[v].begin(), g[v].end(), array<int, 2>{u, w})); } void dfs(int u, int p) { for (auto [v, w] : g[u]) { if (v != p) { mx[v] = max(mx[u], w); dfs(v, u); } } } int get(int u, int v) { fill(mx + 1, mx + n + 1, 0); mx[u] = -inf; dfs(u, u); return mx[v]; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> edges[i][1] >> edges[i][2] >> edges[i][0]; } sort(edges + 1, edges + m + 1); vector<array<int, 2>> events; for (int i = m; i >= 1; --i) { auto [c, u, v] = edges[i]; int rt = get(u, v); if (rt) { ers(edges[rt][1], edges[rt][2], rt); } int L = c, R = rt ? (c + edges[rt][0]) / 2 : inf; events.push_back({L, -c}); events.push_back({R + 1, c}); add(u, v, i); } for (int i = 1; i <= n; ++i) { g[i].clear(); } for (int i = 1; i <= m; ++i) { auto [c, u, v] = edges[i]; int lt = -get(u, v); if (lt) { ers(edges[lt][1], edges[lt][2], -lt); } int L = lt ? (edges[lt][0] + 2 + c) / 2 : 1, R = c; if (L <= R) { events.push_back({L, c}); events.push_back({R + 1, -c}); } add(u, v, -i); } sort(events.begin(), events.end()); cin >> q; int j = 0, B = 0; long long A = 0; while (q--) { int X; cin >> X; while (j < events.size() && events[j][0] <= X) { int x = events[j][1]; A += x; B += x < 0 ? 1 : -1; ++j; } cout << (long long) B * X + A << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     while (j < events.size() && events[j][0] <= X) {
      |            ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...