제출 #486400

#제출 시각아이디문제언어결과실행 시간메모리
486400urosk다리 (APIO19_bridges)C++14
100 / 100
2035 ms32328 KiB
//https://usaco.guide/problems/apio-2019bridges/solution // __builtin_popcount(x) broj bitova // __builtin_popcountll(x) // __builtin_clz(x) vodece nule // __builtin_clzll(x) // __builtin_ctz(x) nule na pocetku // __builtin_ctzll(x) // 2000000011 // 2000000033 #include "bits/stdc++.h" #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll int #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define rall(a) a.begin(),a.end(),greater<int>() #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pi 3.14159265358979323846 #define here cerr<<"---------------------------\n" #define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;} #define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}} #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rnd(ll l,ll r){ return uniform_int_distribution<ll>(l,r)(rng); } void setIO(string inoutname) { freopen((inoutname+".in").c_str(),"r",stdin); freopen((inoutname+".out").c_str(),"w",stdout); } #define mod 1 ll gcd(ll a, ll b) { if(b==0) return a; if(a==0) return b; if(a>=b) return gcd(a%b,b); return gcd(a,b%a); } ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } ll add(ll a,ll b){ a+=b; a+=mod; if(a>=mod) a%=mod; return a; } ll mul(ll a,ll b){return(a*b)%mod;} #define maxn 100005 #define maxd 1005 ll n,m,q; ll u[maxn],v[maxn],w[maxn]; ll tip[maxn],x[maxn],y[maxn]; ll dsu[maxn]; bool menja[maxn]; ll ans[maxn]; vector<ll> join[maxd]; ll siz[maxn]; stack<ll> s; ll d = 1; ll root(ll u){while(u!=dsu[u]) u = dsu[u];return u;} void upd(ll x,ll y){ x = root(x); y = root(y); if(x==y) return; if(siz[x]>siz[y]) swap(x,y); s.push(x); dsu[x] = y; siz[y]+=siz[x]; } void roluj(ll x){ while(sz(s)>x){ ll u = s.top(); ll v = dsu[u]; siz[v]-=siz[u]; dsu[u] = u; s.pop(); } } void tc(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n >> m; for(ll i = 1;i<=m;i++) cin >> u[i] >> v[i] >> w[i]; cin >> q; d = 1000; for(ll i = 1;i<=q;i++) cin >> tip[i] >> x[i] >> y[i]; for(ll l = 1;l<=q;l+=d){ ll r = min(q,l+d-1); fill(siz+1,siz+n+1,1); iota(dsu+1,dsu+n+1,1); fill(menja,menja+m+1,0); vector<ll> up,ask,p; for(ll i = l;i<=r;i++){ if(tip[i]==1){ menja[x[i]] = 1; up.pb(i); }else ask.pb(i); } for(ll i = 1;i<=m;i++) if(!menja[i]) p.pb(i); for(ll i = l;i<=r;i++){ if(tip[i]==1){ w[x[i]] = y[i]; }else{ join[i-l].clear(); for(ll j : up) if(w[x[j]]>=y[i]) join[i-l].pb(x[j]); } } sort(all(ask),[&](ll a,ll b){return y[a]>y[b];}); sort(all(p),[&](ll a,ll b){return w[a]>w[b];}); ll it = 0; for(ll i : ask){ while(it<sz(p)&&w[p[it]]>=y[i]){ upd(u[p[it]],v[p[it]]); it++; } ll sizi = sz(s); for(ll j : join[i-l]) upd(u[j],v[j]); ans[i] = siz[root(x[i])]; roluj(sizi); } } for(ll i = 1;i<=q;i++) if(tip[i]==2) cout<<ans[i]<<endl; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); //setIO("lol"); int t; t = 1; while(t--){ tc(); } return 0; }

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

bridges.cpp: In function 'void setIO(std::string)':
bridges.cpp:48:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:49:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |      freopen((inoutname+".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...