제출 #888411

#제출 시각아이디문제언어결과실행 시간메모리
888411nnhzzz다리 (APIO19_bridges)C++17
100 / 100
1453 ms35168 KiB
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <locale> #include <map> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <unordered_set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <valarray> #include <vector> #include <cstring> #include <unordered_map> #include <cmath> #include <array> #include <cassert> #include <random> #include <chrono> using namespace std; #define __Nothing__ signed main() #define BIT(i,j) (((i)>>(j))&1LL) #define MASK(i) (1LL<<(i)) #define ALL(x) (x).begin(),(x).end() #define SZ(x) (int)(x).size() #define fi first #define se second #define ll long long #define ld long double #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define REPDIS(i,be,en,j) for(int i = (be); i<=(en); i+=j) #define REPD(i,be,en) for(int i = (be); i>=(en); i--) #define REP(i,be,en) for(int i = (be); i<=(en); i++) #define endl "\n" #define MP make_pair // #define int ll //-----------------------------------------------------------------------------------------------// int readInt(){ char c; do{ c = getchar(); }while(c!='-' && !isdigit(c)); bool neg = (c=='-'); int res = neg?0:c-'0'; while(isdigit(c=getchar())) res = (res<<3)+(res<<1)+(c-'0'); return neg?-res:res; } //------------------------------------------------------------------------------------------------// const ll LINF = 1e18; const int INF = 1e9; const int LOG = 20; const int MAXN = 1e5+7; const int N = 1e2+3; const int MOD = 1e9+7; const int BASE = 1e3; const ld EPS = 1e-9; const ld PI = acos(-1); const int OFFSET = 1e3; //------------------------------------------------------------------------------------------------// template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;} template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;} template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; } template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; } //------------------------------------------------------------------------------------------------// struct DSU{ vi par,s; stack<int> st; int n; void reset(){ iota(ALL(par),0); REP(i,1,n) s[i] = 1; } int find(int u){ while(u!=par[u]) u = par[u]; return u; } bool same(int u, int v){ return find(u)==find(v); } void unite(int u, int v){ u = find(u); v = find(v); if(u==v) return ; if(s[u]<s[v]) swap(u,v); s[u] += s[v]; par[v] = par[u]; st.push(v); } int getsize(int i){ i = find(i); return s[i]; } void rollback(int k){ while(SZ(st)>k){ int u = st.top(); st.pop(); s[par[u]] -= s[u]; par[u] = u; } } int get(){ return SZ(st); } DSU(int _n):n(_n){ s.assign(n+3,1); par.resize(n+3); iota(ALL(par),0); } }; int u[MAXN],v[MAXN],w[MAXN],op[MAXN],x[MAXN],y[MAXN],ok[MAXN],res[MAXN]; vi tmp[MAXN]; bool cmp1(int i, int j){ return y[i]>y[j]; } bool cmp2(int i, int j){ return w[i]>w[j]; } void solve(){ int n,m; cin >> n >> m; int len = 2000; REP(i,1,m) cin >> u[i] >> v[i] >> w[i]; int query; cin >> query; REP(i,1,query) cin >> op[i] >> x[i] >> y[i]; DSU dsu(n); REPDIS(l,1,query,len){ int r = min(query+1,l+len); REP(i,1,m) ok[i] = 0; dsu.reset(); vi ask,up,_up; REP(i,l,r-1){ if(op[i]==1){ ok[x[i]] = 1; up.push_back(i); continue; } ask.push_back(i); } REP(i,1,m) if(ok[i]==0) _up.push_back(i); REP(i,l,r-1){ if(op[i]==1){ w[x[i]] = y[i]; continue; } tmp[i-l].clear(); for(int &j:up){ if(w[x[j]]>=y[i]) tmp[i-l].push_back(x[j]); } } sort(ALL(ask),cmp1); sort(ALL(_up),cmp2); int ptr = 0; for(int &i:ask){ while(ptr<SZ(_up) && w[_up[ptr]]>=y[i]){ dsu.unite(u[_up[ptr]],v[_up[ptr]]); ++ptr; } int pre = dsu.get(); for(int &j:tmp[i-l]) dsu.unite(u[j],v[j]); res[i] = dsu.getsize(x[i]); dsu.rollback(pre); } } REP(i,1,query){ if(op[i]==2){ cout << res[i] << endl; } } } __Nothing__{ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } #define task1 "sadge" if(fopen(task1".inp","r")){ freopen(task1".inp","r",stdin); freopen(task1".out","w",stdout); } int test = 1; while(test--){ solve(); } cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n"; return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/

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

bridges.cpp: In function 'int main()':
bridges.cpp:211:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  211 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:212:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  212 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:216:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  216 |         freopen(task1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:217:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  217 |         freopen(task1".out","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...