제출 #1105763

#제출 시각아이디문제언어결과실행 시간메모리
1105763Perl32Two Currencies (JOI23_currencies)C++14
0 / 100
5 ms2044 KiB
//I wrote this code 4 u <3 #include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif struct Q { int l, r, x; ll y; int i; }; const int K = 777; const int maxN = 100'100; bool used[maxN]; signed main(int32_t argc, char *argv[]) { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; vector<vector<pair<int, int>>> g(n); for (int i = 0; i < n - 1; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].push_back({v, i}); g[v].push_back({u, i}); } vector<pair<int, int>> srt; vector<vector<pair<int, int>>> tmp(n - 1); for (int i = 0; i < m; ++i) { int p, x; cin >> p >> x; tmp[p - 1].push_back({x, i}); srt.push_back({x, i}); } sort(srt.begin(), srt.end()); vector<vector<int>> ex(n - 1); for (int i = 0; i < n - 1; ++i) { for (auto x : tmp[i]) { ex[i].push_back(lower_bound(srt.begin(), srt.end(), x) - srt.begin()); } } vector<int> tin(n), ord; auto Dfs = [&](auto&& self, int u, int p) -> void { tin[u] = (int) ord.size(); for (auto [to, i] : g[u]) { if (to == p) continue; for (auto id : ex[i]) ord.push_back(id); self(self, to, u); for (auto id : ex[i]) ord.push_back(id); } }; Dfs(Dfs, 0, -1); vector<Q> qry(q); for (int i = 0; i < q; ++i) { int u, v, x; ll y; cin >> u >> v >> x >> y; u = tin[u - 1], v = tin[v - 1]; if (u > v) swap(u, v); qry[i] = {u, v, x, y, i}; } sort(qry.begin(), qry.end(), [&](auto i, auto j) { if (i.l / K == i.l / K) { int tl = i.r, tr = j.r; if ((i.l / K) & 1) { tl *= -1; tr *= -1; } return tl < tr; } return i.l < j.l; }); int sz = (srt.size() + K - 1) / K; memset(used, 0, sizeof used); vector<vector<ll>> bl(sz, vector<ll>(K, 0ll)); vector<ll> sm(sz, 0ll); vector<int> cnt(sz, 0); ll s = 0ll; int c = 0; auto chk = [&](int i) { i = ord[i]; int ii = i / K, iii = i % K; if (!used[i]) { sm[ii] += srt[i].first; bl[ii][iii] += srt[i].first; s += srt[i].first; cnt[ii]++; c++; } else { sm[ii] -= srt[i].first; bl[ii][iii] -= srt[i].first; s -= srt[i].first; cnt[ii]--; c--; } used[i] ^= 1; }; vector<int> ans(q); int cl = 0, cr = 0; for (auto [l, r, x, y, id] : qry) { while (cl > l) chk(--cl); while (cl < l) chk(cl++); while (cr > r) chk(--cr); while (cr < r) chk(cr++); ll cur = s; for (int i = sz - 1; i > -1; --i) { if (cur - sm[i] <= y) { for (int j = K - 1; j > -1 && cur > y; --j) { if (bl[i][j]) { x--; cur -= bl[i][j]; } } break; } else { x -= cnt[i]; cur -= sm[i]; } } ans[id] = max(-1, x); } for (auto x : ans) cout << x << '\n'; } /* */

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

currencies.cpp: In lambda function:
currencies.cpp:55:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |         for (auto [to, i] : g[u]) {
      |                   ^
currencies.cpp: In function 'int main(int32_t, char**)':
currencies.cpp:110:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  110 |     for (auto [l, r, x, y, id] : qry) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...