제출 #370608

#제출 시각아이디문제언어결과실행 시간메모리
370608Jarif_Rahman다리 (APIO19_bridges)C++17
0 / 100
3054 ms27572 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const int sq = 316, lim = 2e5; vector<int> sorter[lim]; void counting_sort(tuple<int, int, int> *a, tuple<int, int, int> *b){ vector<tuple<int, int, int>> v; for(int i = 0; a+i < b; i++){ sorter[get<0>(*(a+i))].pb(i); } for(int i = 0; i < lim; i++){ while(!sorter[i].empty()) v.pb(*(a+sorter[i].back())), sorter[i].pop_back(); } for(int i = 0; i < v.size(); i++) *(a+i) = v[i]; } struct dsu{ int n; vector<int> sz, p; stack<tuple<int, int, int>> st; dsu(int nn){ n = nn; sz.resize(n, 1); p.resize(n); for(int i = 0; i < n; i++) p[i] = i; } inline int get(int x){ if(p[x] != x) p[x] = get(p[x]); return p[x]; } int unite(int a, int b){ a = get(a), b = get(b); if(a == b) return 0; if(sz[b] > sz[a]) swap(a, b); st.push({a, b, sz[b]}); sz[a]+=sz[b]; sz[b] = 0; p[b] = a; return 1; } void rollback(){ auto [a, b, bsz] = st.top(); st.pop(); sz[a]-=bsz; sz[b] = bsz; p[b] = b; } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); vector<int> compressor; map<int, int> mp; int n, m; cin >> n >> m; tuple<int, int, int> edge[m]; for(int i = 0; i < m; i++){ int a, b, w; cin >> a >> b >> w; a--, b--; edge[i] = {w, a, b}; compressor.pb(w); } int q; cin >> q; tuple<int, int, int> query[q]; for(int i = 0; i < q; i++){ int tt, s, w; cin >> tt >> s >> w; s--; query[i] = {tt, s, w}; compressor.pb(w); } sort(compressor.begin(), compressor.end()); for(int i = 0; i < compressor.size(); i++){ mp[compressor[i]] = i; } for(int i = 0; i < m; i++) get<0>(edge[i]) = mp[get<0>(edge[i])]; for(int i = 0; i < q; i++) get<2>(query[i]) = mp[get<2>(query[i])]; vector<int> ans(q, -1); bool ucng[m]; for(int i = 0; i < m; i++) ucng[i] = 1; tuple<int, int, int> edges[m]; tuple<int, int, int> calc[sq+5]; for(int ql = 0; ql < q; ql+=sq){ int qr = min(q-1, ql+sq-1); dsu ds(n); int in1 = 0, in2 = 0; for(int i = ql; i <= qr; i++){ auto [tt, s, w] = query[i]; if(tt == 1){ ucng[s] = 0; } else{ calc[in2++] = {w, s, i}; } } for(int i = 0; i < m; i++) if(ucng[i]) edges[in1++] = edge[i]; counting_sort(calc, calc+in2); reverse(calc, calc+in2); counting_sort(edges, edges+in1); int bc = in1-1; for(int j = 0; j < in2; j++){ auto [w, s, in] = calc[j]; while(bc >= 0 && get<0>(edges[bc]) >= w){ auto [ww, a, b] = edges[bc]; ds.unite(a, b); bc--; } int k = 0; for(int i = in-1; i >= ql; i--){ auto [tt, ss, ww] = query[i]; if(tt == 2) continue; if(ucng[ss]) continue; ucng[ss] = 1; if(ww >= w){ auto [www, a, b] = edge[ss]; k+=ds.unite(a, b); } } for(int i = in+1; i <= qr; i++){ auto [tt, ss, ww] = query[i]; if(tt == 2) continue; if(ucng[ss]) continue; auto [www, a, b] = edge[ss]; if(www >= w) k+=ds.unite(a, b); } ans[in] = ds.sz[ds.get(s)]; for(int i = ql; i <= qr; i++){ auto [tt, ss, ww] = query[i]; if(tt == 1) ucng[ss] = 0; } while(k--) ds.rollback(); } for(int i = ql; i <= qr; i++){ auto [tt, s, w] = query[i]; if(tt == 1) ucng[s] = 1; } } for(int x: ans) if(x != -1) cout << x << "\n"; }

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

bridges.cpp: In function 'void counting_sort(std::tuple<int, int, int>*, std::tuple<int, int, int>*)':
bridges.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < v.size(); i++) *(a+i) = v[i];
      |                    ~~^~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i = 0; i < compressor.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
#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...