제출 #683490

#제출 시각아이디문제언어결과실행 시간메모리
683490Nursik다리 (APIO19_bridges)C++14
100 / 100
2013 ms12328 KiB
#include <stdio.h> #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define f first #define s second #define ld long double #define bug cout << "bug\n"; const int maxn = 1e5 + 1, maxm = 5e4 + 1; const int mod = 1e9 + 7, inf = 1e9, block = 800, hb = 126067, base = 1000050017; const ll biginf = 5e18; const ld eps = 1e-15; using namespace std; int n, m, q; int u[maxn], v[maxn], d[maxn], used[maxn], ans[maxn]; int t[maxn]; int x[maxn], y[maxn]; vector<int> add[block + block]; struct dsu{ int p[maxm], sz[maxm]; stack<pair<int, int>> st; void init(){ for (int i = 1; i <= n; ++i){ p[i] = i, sz[i] = 1; } while (st.size() > 0){ st.pop(); } } int get(int v){ if (v == p[v]) return v; return get(p[v]); } void unite(int a, int b){ a = get(a), b = get(b); if (a == b) return; if (sz[a] > sz[b]) swap(a, b); p[a] = b; sz[b] += sz[a]; st.push(mp(a, sz[a])); } void rollback(int y){ while (st.size() != y){ pair<int, int> cur = st.top(); int r = p[cur.f]; sz[r] -= cur.s; p[cur.f] = cur.f; st.pop(); } } } rt; int main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; ++i){ cin >> u[i] >> v[i] >> d[i]; } cin >> q; for (int i = 1; i <= q; ++i){ cin >> t[i]; if (t[i] == 1){ cin >> x[i] >> y[i]; } else{ cin >> x[i] >> y[i]; } } for (int i = 1; i <= q; i += block){ rt.init(); int l = i, r = min(q, i + block - 1); vector<int> changed; vector<pair<int, int>> unchanged; vector<pair<int, int>> ask; for (int j = l; j <= r; ++j){ if (t[j] == 1){ used[x[j]] = 1; changed.pb(x[j]); } else{ ask.pb(mp(y[j], j)); } } for (int j = l; j <= r; ++j){ if (t[j] == 1){ d[x[j]] = y[j]; } else{ add[j - l].clear(); for (auto it : changed){ if (d[it] >= y[j]){ add[j - l].pb(it); } } } } for (int j = 1; j <= m; ++j){ if (used[j] == 0){ unchanged.pb(mp(d[j], j)); } used[j] = 0; } sort(ask.begin(), ask.end()); sort(unchanged.begin(), unchanged.end()); int uk = (int)unchanged.size() - 1; for (int j = (int)ask.size() - 1; j >= 0; --j){ while (uk >= 0 && unchanged[uk].f >= ask[j].f){ int z = unchanged[uk].s; rt.unite(u[z], v[z]); uk -= 1; } int cur = (int)rt.st.size(); int pos = ask[j].s; for (auto it : add[pos - l]){ rt.unite(u[it], v[it]); } ans[pos] = rt.sz[rt.get(x[pos])]; rt.rollback(cur); } } for (int i = 1; i <= q; ++i){ if (t[i] == 2){ cout << ans[i] << '\n'; } } } /* */

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

bridges.cpp: In member function 'void dsu::rollback(int)':
bridges.cpp:76:26: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |         while (st.size() != y){
      |                ~~~~~~~~~~^~~~
#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...