제출 #318754

#제출 시각아이디문제언어결과실행 시간메모리
318754BeanZ다리 (APIO19_bridges)C++14
100 / 100
2618 ms131676 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 1e5 + 5; vector<pair<ll, ll>> rb; vector<ll> join[N]; ll u[N], v[N], d[N], t[N], a[N], b[N], ch[N], p[N], ans[N]; void rollback(ll u){ while (rb.size() > u){ p[rb.back().first] = rb.back().second; rb.pop_back(); } } ll find_set(ll u){ if (p[u] < 0) return u; return find_set(p[u]); } void dsu(ll u, ll v){ u = find_set(u); v = find_set(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); rb.push_back({u, p[u]}); rb.push_back({v, p[v]}); p[u] += p[v]; p[v] = u; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n, m; cin >> n >> m; for (int i = 1; i <= m; i++){ cin >> u[i] >> v[i] >> d[i]; } ll q; cin >> q; for (int i = 1; i <= q; i++){ cin >> t[i] >> a[i] >> b[i]; } const int base = 1000; for (int l = 1; l <= q; l += base){ for (int i = 1; i <= n; i++) p[i] = -1; ll r = min(l + base - 1, q); for (int i = 1; i <= m; i++) ch[i] = 0; rb.clear(); vector<ll> memupd, memres, un; for (int i = l; i <= r; i++){ if (t[i] == 1) memupd.push_back(a[i]); } for (int i = l; i <= r; i++){ if (t[i] == 1){ d[a[i]] = b[i]; ch[a[i]] = 1; } else { for (auto j : memupd){ if (d[j] >= b[i]){ join[i].push_back(j); } } memres.push_back(i); } } for (int i = 1; i <= m; i++){ if (ch[i] == 0) un.push_back(i); } sort(un.begin(), un.end(), [&](ll g, ll h){return d[g] > d[h];}); sort(memres.begin(), memres.end(), [&](ll g, ll h){return b[g] > b[h];}); ll now = 0; //for (auto j : memres) cout << j << " "; //cout << endl; for (auto j : memres){ while (now < un.size() && d[un[now]] >= b[j]){ dsu(u[un[now]], v[un[now]]); //cout << u[un[now]] << " " << v[un[now]] << " " << now << " " << a[j] << " " << j << endl; now++; } ll tmp = rb.size(); for (auto o : join[j]){ dsu(u[o], v[o]); } //cout << b[j] << endl; //cout << j << endl; ans[j] = -p[find_set(a[j])]; //cout << j << " " << ans[j] << endl; rollback(tmp); } } for (int i = 1; i <= q; i++){ if (t[i] == 2) cout << ans[i] << endl; } } /* 3 4 1 2 5 2 3 2 3 1 4 2 3 8 1 2 1 5 */

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

bridges.cpp: In function 'void rollback(int)':
bridges.cpp:11:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |     while (rb.size() > u){
      |            ~~~~~~~~~~^~~
bridges.cpp: In function 'int main()':
bridges.cpp:79:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             while (now < un.size() && d[un[now]] >= b[j]){
      |                    ~~~~^~~~~~~~~~~
bridges.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         freopen("test.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...