제출 #623013

#제출 시각아이디문제언어결과실행 시간메모리
623013tamthegod다리 (APIO19_bridges)C++14
100 / 100
2193 ms125624 KiB
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e5 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, m; int block_size = 1000; int mark[maxN]; int lab[maxN]; int res[maxN]; vector<pair<int, int>> vc; int Findset(int u) { return lab[u] < 0 ? u : Findset(lab[u]); } void Unite(int u, int v) { int r = Findset(u), s = Findset(v); if(r == s) return; if(lab[r] > lab[s]) swap(r, s); vc.pb({r, lab[r]}); vc.pb({s, lab[s]}); lab[r] += lab[s]; lab[s] = r; } void roll_back(int sz) { while(vc.size() > sz) { pair<int, int> tmp = vc.back(); vc.pop_back(); lab[tmp.fi] = tmp.se; } } struct TEdge { int u, v, w; } e[maxN]; int q; struct TQuery { int type; int s, w; } qu[maxN]; vector<int> upd[maxN]; void ReadInput() { cin >> n >> m; for(int i=1; i<=m; i++) { int u, v, w; cin >> u >> v >> w; e[i] = {u, v, w}; } cin >> q; for(int i=1; i<=q; i++) { cin >> qu[i].type >> qu[i].s >> qu[i].w; } } void Solve() { for(int i=1; i<=block_size; i++) { memset(lab, -1, sizeof lab); vc.clear(); int l = block_size * (i - 1) + 1, r = min(q, block_size * i); if(l > q) break; for(int j=1; j<=m; j++) mark[j] = 0; for(int j=l; j<=r; j++) { if(qu[j].type == 1) { mark[qu[j].s] = 1; } } vector<int> unchanged, query, changed; for(int j=1; j<=m; j++) { if(!mark[j]) unchanged.pb(j); else changed.pb(j); } for(int j=l; j<=r; j++) if(qu[j].type == 2) query.pb(j); for(int j=l; j<=r; j++) { if(qu[j].type == 1) e[qu[j].s].w = qu[j].w; else { for(int v : changed) if(e[v].w >= qu[j].w) upd[j].pb(v); } } sort(unchanged.begin(), unchanged.end(), [](int i, int j) { return e[i].w > e[j].w; }); sort(query.begin(), query.end(), [](int i, int j) { return qu[i].w > qu[j].w; }); int p = 0; for(int j : query) { while(p < unchanged.size() && e[unchanged[p]].w >= qu[j].w) { Unite(e[unchanged[p]].u, e[unchanged[p]].v); p++; } int sz = vc.size(); for(int v : upd[j]) { // if(j == 5) cout << v << " "; Unite(e[v].u, e[v].v); } res[j] = -lab[Findset(qu[j].s)]; roll_back(sz); } } for(int i=1; i<=q; i++) { if(qu[i].type == 2) cout << res[i] << '\n'; } } int32_t main() { // freopen("x.inp", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(nullptr); ReadInput(); Solve(); }

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

bridges.cpp: In function 'void roll_back(int)':
bridges.cpp:37:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |     while(vc.size() > sz)
      |           ~~~~~~~~~~^~~~
bridges.cpp: In function 'void Solve()':
bridges.cpp:121:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |             while(p < unchanged.size() && e[unchanged[p]].w >= qu[j].w)
      |                   ~~^~~~~~~~~~~~~~~~~~
#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...