제출 #712758

#제출 시각아이디문제언어결과실행 시간메모리
712758acm다리 (APIO19_bridges)C++17
100 / 100
2187 ms12068 KiB
#ifdef ONLINE_JUDGE #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #endif #include <bits/stdc++.h> #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define precision \ cout.precision(30); \ cerr.precision(10); #define ll long long #define ld long double #define pb(x) push_back(x) #define sz(x) (int)x.size() #define mp(x, y) make_pair(x, y) #define all(x) x.begin(), x.end() #define pc(x) __builtin_popcount(x) #define pcll(x) __builtin_popcountll(x) #define F first #define S second using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); void ioi(string name) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } const int bl = 1000; int n, m, q, p[100005], sz[100005], a[100005], b[100005], c[100005], type[100005], X[100005], Y[100005], w[100005], res[100005]; vector<int> stk, upd[100005]; int get(int v) { while (v != p[v]) v = p[v]; return v; } void unt(int u, int v) { if ((u = get(u)) == (v = get(v))) return; if (sz[u] < sz[v]) swap(u, v); sz[u] += sz[v], p[v] = u; stk.pb(v); } void roll(int old_sz) { while (sz(stk) > old_sz) { int v = stk.back(); stk.pop_back(); sz[p[v]] -= sz[v], p[v] = v; } } int main() { speed; precision; // code cin >> n >> m; for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i]; cin >> q; for (int I = 1, h = 1; I <= q; I++, h++) { cin >> type[h] >> X[h] >> Y[h]; if (!(h % bl) || I == q) { stk.clear(); for (int i = 1; i <= n; i++) sz[i] = 1, p[i] = i; for (int i = 1; i <= m; i++) upd[i].clear(), w[i] = 0; for (int i = 1; i <= h; i++) if (type[i] == 1) upd[X[i]].pb(i), w[X[i]] = 1; vector<pair<int, int>> edge; vector<int> later; for (int i = 1; i <= m; i++) { if (!w[i]) edge.pb(mp(c[i], i)); else later.pb(i); } sort(all(edge)); vector<pair<pair<int, int>, int>> ask; for (int i = 1; i <= h; i++) if (type[i] == 2) ask.pb(mp(mp(Y[i], i), X[i])); sort(all(ask)); for (int i = sz(ask) - 1, j = sz(edge) - 1; i >= 0; i--) { while (j >= 0 && ask[i].F.F <= edge[j].F) { unt(a[edge[j].S], b[edge[j].S]); j--; } int old_sz = sz(stk); for (auto k : later) { int kek = c[k]; for (auto to : upd[k]) { if (to > ask[i].F.S) break; kek = Y[to]; } if (ask[i].F.F <= kek) unt(a[k], b[k]); } res[ask[i].F.S] = sz[get(ask[i].S)]; roll(old_sz); } for (int i = 1; i <= h; i++) if (type[i] == 1) c[X[i]] = Y[i]; for (int i = 1; i <= h; i++) if (type[i] == 2) cout << res[i] << "\n"; h = 0; } } // endl #ifndef ONLINE_JUDGE cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }

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

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