Submission #563602

#TimeUsernameProblemLanguageResultExecution timeMemory
563602Ooops_sorryBridges (APIO19_bridges)C++17
100 / 100
2829 ms21344 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ld long double #define ll long long mt19937 rnd(51); const int N = 50010, K = 800, M = 1e5 + 10, INF = 1e9; int par[N], sz[N], Sz = 0; bool used[M]; array<int, 4> arr[M]; set<pair<int,int>> val[M]; int find_set(int v) { while (v != par[v]) { v = par[v]; } return v; } void union_set(int a, int b) { a = find_set(a); b = find_set(b); if (a == b) return; if (sz[a] < sz[b]) { swap(a, b); } arr[Sz++] = {b, par[b], a, sz[a]}; par[b] = a; sz[a] += sz[b]; } void upd(int n) { while (Sz > n) { auto mas = arr[--Sz]; par[mas[0]] = mas[1]; sz[mas[2]] = mas[3]; } } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LCOAL ios_base::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < N; i++) { sz[i] = 1; par[i] = i; } int n, m; cin >> n >> m; vector<pair<int,int>> e(m); vector<int> w(m); for (int i = 0; i < m; i++) { cin >> e[i].first >> e[i].second >> w[i]; e[i].first--, e[i].second--; val[i].insert({-1, w[i]}); } int q; cin >> q; vector<array<int, 3>> u(q); vector<int> ans(q, -1); for (int i = 0; i < q; i++) { cin >> u[i][0] >> u[i][1] >> u[i][2]; u[i][1]--; if (u[i][0] == 1) { val[u[i][1]].insert({i, u[i][2]}); } } for (int i = 0; i < q; i += K) { vector<array<int, 3>> qu; for (int j = i; j < min(i + K, q); j++) { if (u[j][0] == 1) { used[u[j][1]] = 1; } else { qu.pb({u[j][2], u[j][1], j}); } } vector<int> a, b; for (int j = 0; j < m; j++) { if (!used[j]) { a.pb(j); } else { b.pb(j); } } sort(a.begin(), a.end(), [&](int i, int j){return w[i] > w[j];}); sort(qu.rbegin(), qu.rend()); int ind = 0; for (int j = 0; j < qu.size(); j++) { while (ind < a.size() && w[a[ind]] >= qu[j][0]) { union_set(e[a[ind]].first, e[a[ind]].second); ind++; } int was = Sz; for (auto to : b) { auto it = prev(val[to].upper_bound({qu[j][2], INF})); if (it->second >= qu[j][0]) { union_set(e[to].first, e[to].second); } } ans[qu[j][2]] = sz[find_set(qu[j][1])]; upd(was); } upd(0); for (int j = 0; j < min(i + K, q); j++) { if (u[j][0] == 1) { used[u[j][1]] = 0; w[u[j][1]] = u[j][2]; } } } for (int i = 0; i < q; i++) { if (ans[i] != -1) { cout << ans[i] << '\n'; } } return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for (int j = 0; j < qu.size(); j++) {
      |                         ~~^~~~~~~~~~~
bridges.cpp:95:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             while (ind < a.size() && w[a[ind]] >= qu[j][0]) {
      |                    ~~~~^~~~~~~~~~
#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...