Submission #632831

#TimeUsernameProblemLanguageResultExecution timeMemory
632831ertoBridges (APIO19_bridges)C++17
59 / 100
3097 ms121080 KiB
#include <bits/stdc++.h> typedef long long int ll; #define INF 1000000007 #define INF2 998244353 #define N (ll)(1e5+ 5) using namespace std; //#define int ll #define lsb(x) (x & (-x)) const int K = 320; int n, m, cur=0, g, h, q; int u[N], v[N], d[N]; int x[N], y[N], ans[N]; bool used[N]; pair<int, int> upd[N], qu[N]; vector<int> lis[N]; int p[N], sz[N]; vector<int> tb; int get(int x){ return p[x] == x ? x : get(p[x]); } void unite(int x, int y){ int a = get(x), b = get(y); if(a == b)return; if(sz[a] < sz[b]){ swap(a, b); } p[b] = a; sz[a] += sz[b]; tb.push_back(b); } void revert(int x){ while(tb.size() > x){ int t = tb.back(); sz[p[t]] -= sz[t]; p[t] = t; tb.pop_back(); } } bool c1(int x, int y){ return d[x] > d[y]; } bool c2(int x, int y){ return qu[x].second > qu[y].second; } void solve(){ 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 >> g; if(g == 1){ cin >> g >> h; upd[i] = {g, h}; } else{ cin >> g >> h; qu[i] = {g, h}; } } for(int i=0; i<= q / K; i++){ int l = max(1, i * K), r = min((i + 1) * K, q + 1); memset(used, 0, m + 1); fill(sz + 1, sz + n + 1, 1); iota(p + 1, p + n + 1, 1); vector<int> ch, ask, uch; for(int j=l; j<r; j++){ if(upd[j].first){ used[upd[j].first] = 1; ch.push_back(j); } else{ ask.push_back(j); } } for(int j=l; j<r; j++){ if(qu[j].first){ for(int u : ch){ if(d[upd[u].first] >= qu[j].second){ lis[j].push_back(upd[u].first); } } } else{ d[upd[j].first] = upd[j].second; } } for(int j=1; j<=m; j++){ if(!used[j])uch.push_back(j); } sort(uch.begin(), uch.end(), c1); sort(ask.begin(), ask.end(), c2); int p1 = 0; for(int j : ask){ while(p1 < uch.size() && qu[j].second <= d[uch[p1]]){ unite(u[uch[p1]], v[uch[p1]]); p1++; } int prev = tb.size(); for(int l : lis[j]){ unite(u[l], v[l]); } ans[j] = sz[get(qu[j].first)]; revert(prev); } } for(int i=1; i<=q; i++){ if(qu[i].first)cout << ans[i] << '\n'; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; //cin>>T; while (T--){ solve(); } }

Compilation message (stderr)

bridges.cpp: In function 'void revert(int)':
bridges.cpp:37:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |     while(tb.size() > x){
      |           ~~~~~~~~~~^~~
bridges.cpp: In function 'void solve()':
bridges.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |             while(p1 < uch.size() && qu[j].second <= d[uch[p1]]){
      |                   ~~~^~~~~~~~~~~~
#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...