제출 #655129

#제출 시각아이디문제언어결과실행 시간메모리
655129DeMen100ns다리 (APIO19_bridges)C++17
100 / 100
1774 ms14264 KiB
#include<bits/stdc++.h> using namespace std; #define app push_back const int N = 1e5 + 7, K = 600; struct Edge { int u, v, c; }; struct Quer { int t, i, c; bool operator < (Quer p) { return c > p.c; } }; struct Seg { int l, r, i, c; bool operator < (Seg p) { return c > p.c; } }; int n, m, q; int par[N], cnt[N]; void init() { for (int i = 1; i <= n; ++i) { par[i] = i; cnt[i] = 1; } } int root(int u) { if (u == par[u]) return u; else return par[u] = root(par[u]); } void merge(int u, int v) { u = root(u); v = root(v); if (u == v) return; if (cnt[v] < cnt[u]) swap(u, v); par[u] = v; cnt[v] += cnt[u]; } Edge ed[N]; Quer d[N]; int lf[N], w[N]; vector <Seg> v; int ans[N]; bool upd[N]; vector <int> g[N]; bool comp(int i, int j) { return d[i].c > d[j].c; } bool used[N]; vector <int> vis; int dfs(int u) { int ans = cnt[u]; used[u] = 1; vis.app(u); for (int v : g[u]) { if (!used[v]) { ans += dfs(v); } } return ans; } void solve(int L, int R) { memset(upd, 0, sizeof upd); vector <int> q; for (int i = L; i <= R; ++i) { if (d[i].t == 1) { upd[d[i].i] = 1; } else { q.app(i); } } sort(q.begin(), q.end(), comp); int ptr = 0; vector <Seg> t; init(); for (int i : q) { while (ptr < v.size() && v[ptr].c >= d[i].c) { if (R < v[ptr].l || v[ptr].r < L) { } else if (v[ptr].l <= L && R <= v[ptr].r) { int e = v[ptr].i; merge(ed[e].u, ed[e].v); } else { t.app(v[ptr]); } ++ptr; } for (auto s : t) { if (s.l <= i && i <= s.r) { int u = root(ed[s.i].u), v = root(ed[s.i].v); g[u].app(v); g[v].app(u); } } ans[i] = dfs(root(d[i].i)); for (int e : vis) used[e] = 0; vis.clear(); for (auto s : t) { if (s.l <= i && i <= s.r) { int u = root(ed[s.i].u), v = root(ed[s.i].v); g[u].clear(); g[v].clear(); } } } } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> ed[i].u >> ed[i].v >> ed[i].c; w[i] = ed[i].c; } cin >> q; for (int i = 0; i < q; ++i) { cin >> d[i].t >> d[i].i >> d[i].c; if (d[i].t == 1) { --d[i].i; v.app({lf[d[i].i], i - 1, d[i].i, w[d[i].i]}); lf[d[i].i] = i; w[d[i].i] = d[i].c; } } for (int i = 0; i < m; ++i) { v.app({lf[i], q - 1, i, w[i]}); } sort(v.begin(), v.end()); for (int a = 0; ; ++a) { int L = a * K; int R = min(L + K - 1, q - 1); if (R < L) break; solve(L, R); } for (int i = 0; i < q; ++i) { if (d[i].t == 2) cout << ans[i] << '\n'; } }

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

bridges.cpp: In function 'void solve(int, int)':
bridges.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Seg>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         while (ptr < v.size() && v[ptr].c >= d[i].c) {
      |                ~~~~^~~~~~~~~~
#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...