제출 #1118618

#제출 시각아이디문제언어결과실행 시간메모리
1118618stefanneagu다리 (APIO19_bridges)C++17
46 / 100
3074 ms11416 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 1; int nra = 1; int bit[nmax]; int n, m; int root[nmax], sz[nmax]; int mr[nmax], ms[nmax]; struct DSU { void init() { for(int i = 1; i <= n; i++) { root[i] = i; sz[i] = 1; } } int find(int a) { if(root[a] == a) { return a; } return root[a] = find(root[a]); } void unite(int a, int b) { if(a == b) { return; } if(sz[a] > sz[b]) { swap(a, b); } root[a] = b; sz[b] += sz[a]; } int mfind(int a) { if(bit[a] != nra) { bit[a] = nra; mr[a] = find(a); ms[a] = sz[find(a)]; } if(mr[a] == a) { return a; } return mr[a] = mfind(mr[a]); } void munite(int a, int b) { if(a == b) { return; } if(ms[a] > ms[b]) { swap(a, b); } mr[a] = b; ms[b] += ms[a]; } }; struct str { int a, b, c; }; struct special { int t, a, b, c; }; vector<str> qry, upd, edges; vector<special> e2; int ans[nmax], mark[nmax], to[nmax]; int pas = 1; bool cmp(special x, special y) { if(x.c != y.c) { return x.c > y.c; } return x.t < y.t; } bool cmp2(str x, str y) { return x.c < y.c; } bool cmp3(str x, str y) { return x.b > y.b; } void solve() { vector<special> curr;// doar; vector<pair<int, int>> unsafe; for(int i = 1; i <= m; i++) { if(mark[i] == pas) { unsafe.push_back({i, edges[i].c}); } } sort(qry.begin(), qry.end(), cmp3); int ie = 0, iq = 0; while(ie < e2.size() || iq < qry.size()) { while(ie < e2.size() && mark[e2[ie].t] == pas) { ie++; } if(iq == qry.size() || (ie < e2.size() && e2[ie].c >= qry[iq].b)) { curr.push_back({0, e2[ie].a, e2[ie].b, e2[ie].c}); // doar.push_back({e2[ie].t, e2[ie].a, e2[ie].b, e2[ie].c}); ie++; } else { curr.push_back({1, qry[iq].a, qry[iq].b, qry[iq].c}); iq++; } } DSU ds; ds.init(); for(auto _ : curr) { int t = _.t, a = _.a, b = _.b, c = _.c; if(t == 0) { ds.unite(ds.find(a), ds.find(b)); } else { for(auto it : upd) { if(it.c <= c) { edges[it.a].c = it.b; } } for(auto it : unsafe) { if(edges[it.first].c >= b) { ds.munite(ds.mfind(edges[it.first].a), ds.mfind(edges[it.first].b)); } edges[it.first].c = it.second; } ans[c] = ms[ds.mfind(a)]; nra++; } } pas++; sort(upd.begin(), upd.end(), cmp2); for(auto it : upd) { edges[it.a].c = it.b; } e2.clear(); for(int i = 1; i <= m; i++) { e2.push_back({i, edges[i].a, edges[i].b, edges[i].c}); } sort(e2.begin(), e2.end(), cmp); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; edges.push_back({-1, -1, -1}); for(int i = 1; i <= m; i++) { int a, b, c; cin >> a >> b >> c; if(a > b) { swap(a, b); } edges.push_back({a, b, c}); e2.push_back({i, a, b, c}); } sort(e2.begin(), e2.end(), cmp); int q; cin >> q; int block = sqrt(q); for(int i = 1; i <= q; i++) { int t, a, b; cin >> t >> a >> b; if(t == 1) { // update mark[a] = pas; upd.push_back({a, b, i}); } else { // query qry.push_back({a, b, i}); } if(i % block == 0 || i == q) { solve(); upd.clear(); qry.clear(); } } for(int i = 1; i <= q; i++) { if(ans[i] != 0) { cout << ans[i] << "\n"; } } return 0; }

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

bridges.cpp: In function 'void solve()':
bridges.cpp:103:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<special>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |  while(ie < e2.size() || iq < qry.size()) {
      |        ~~~^~~~~~~~~~~
bridges.cpp:103:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |  while(ie < e2.size() || iq < qry.size()) {
      |                          ~~~^~~~~~~~~~~~
bridges.cpp:104:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<special>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |    while(ie < e2.size() && mark[e2[ie].t] == pas) {
      |          ~~~^~~~~~~~~~~
bridges.cpp:107:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |    if(iq == qry.size() || (ie < e2.size() && e2[ie].c >= qry[iq].b)) {
      |       ~~~^~~~~~~~~~~~~
bridges.cpp:107:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<special>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |    if(iq == qry.size() || (ie < e2.size() && e2[ie].c >= qry[iq].b)) {
      |                            ~~~^~~~~~~~~~~
#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...