Submission #947537

#TimeUsernameProblemLanguageResultExecution timeMemory
947537kigashBridges (APIO19_bridges)C++17
59 / 100
3067 ms57480 KiB
#include "bits/stdc++.h" using namespace std; // #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using ll = long long; using ld = long double; #define pb push_back #define ff first #define ss second #define sz(x) (ll)(x).size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; } ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN; const ll mod = 1e9+7, N = 1e5+5; #define ll int ll u[N], v[N], w[N], t[N], qx[N], qy[N], ans[N], B = 317; ll p[N], sz[N]; vector<ll> dsu, add[N]; ll get(ll x) { while(p[x]!=x) x = p[x]; return x; } void update(ll x, ll y) { x = get(x), y = get(y); if(x==y) return; if(sz[x]>sz[y]) swap(x, y); dsu.pb(x); sz[y] += sz[x], p[x] = p[y]; } void rollback(ll s) { while(sz(dsu)>s) { ll x = dsu.back(); dsu.pop_back(); sz[p[x]] -= sz[x], p[x] = x; } } void yesyesyes() { ll n, m; cin>>n>>m; for(ll i=1; i<=m; i++) cin>>u[i]>>v[i]>>w[i]; ll q; cin>>q; for(ll i=1; i<=q; i++) cin>>t[i]>>qx[i]>>qy[i]; for(ll l=1; l<=q; l+=B) { ll r = min(q, l+B-1); vector<ll> ask, upd, used(m+1); for(ll i=1; i<=n; i++) p[i] = i, sz[i] = 1; dsu.clear(); for(ll i=l; i<=r; i++) { if(t[i]==1) { upd.pb(i); used[qx[i]] = 1; } else ask.pb(i); } for(ll i=l; i<=r; i++) { if(t[i]==1) w[qx[i]] = qy[i]; else { for(auto j: upd) { if(w[qx[j]]>=qy[i]) add[i].pb(qx[j]); } } } vector<ll> same; for(ll i=1; i<=m; i++) { if(!used[i]) same.pb(i); } sort(all(same), [](ll i, ll j) { return w[i]>w[j]; }); sort(all(ask), [](ll i, ll j) { return qy[i]>qy[j]; }); ll j = 0; for(ll i=0; i<sz(ask); i++) { while(j<sz(same) && w[same[j]]>=qy[ask[i]]) update(u[same[j]], v[same[j]]), j++; ll s = sz(dsu); for(auto k: add[ask[i]]) update(u[k], v[k]); ans[ask[i]] = sz[get(qx[ask[i]])]; rollback(s); } } for(ll i=1; i<=q; i++) { if(t[i]==2) cout<<ans[i]<<"\n"; } return; } signed main(/*Kigash Amir*/) { // freopen(""); ios_base::sync_with_stdio(false); cin.tie(NULL); ll tt = 1; // cin>>tt; for(ll i=1; i<=tt; i++) { yesyesyes(); } }

Compilation message (stderr)

bridges.cpp: In function 'void freopen(std::string)':
bridges.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...