제출 #633023

#제출 시각아이디문제언어결과실행 시간메모리
633023erto다리 (APIO19_bridges)C++17
44 / 100
3088 ms247516 KiB
#include <bits/stdc++.h> typedef long long int ll; #define INF 1000000007 #define INF2 998244353 #define N (int)(1e5+ 5) using namespace std; //#define int ll #define lsb(x) (x & (-x)) const int K = 2000; int n, m, cur=0, g, h, q; int u[N], v[N], d[N]; int t[N], x[N], y[N], ans[N]; bool used[N]; vector<int> lis[N]; int p[N], sz[N]; vector<int> tb; int get(int x){ while(x != p[x])x = p[x]; return x; } void unite(int x, int y){ int a = get(x), b = get(y); if(a == b)return; if(sz[a] < sz[b]){ swap(a, b); } p[b] = a; sz[a] += sz[b]; tb.push_back(b); } void revert(int x){ while(tb.size() > x){ int t = tb.back(); sz[p[t]] -= sz[t]; p[t] = t; tb.pop_back(); } } bool c1(int x, int y){ return d[x] > d[y]; } bool c2(int a, int b){ return y[a] > y[b]; } void solve(){ cin >> n >> m; for(int i=1; i<=m; i++){ cin >> u[i] >> v[i] >> d[i]; } cin >> q; for(int i=1; i<=q; i++){ cin >> t[i] >> x[i] >> y[i]; } for(int i=0; i<= q / K; i++){ int l = max(1, i * K), r = min((i + 1) * K, q + 1); memset(used, 0, m + 1); fill(sz + 1, sz + n + 1, 1); iota(p + 1, p + n + 1, 1); vector<int> ch, ask, uch; for(int j=l; j<r; j++){ if(t[j] == 1){ used[x[j]] = 1; ch.push_back(j); } else{ ask.push_back(j); } } for(int j=l; j<r; j++){ if(t[j] == 2){ for(int u : ch){ if(d[x[u]] >= y[j]){ lis[j].push_back(x[u]); } } } else{ d[x[j]] = y[j]; } } for(int j=1; j<=m; j++){ if(!used[j])uch.push_back(j); } sort(uch.begin(), uch.end(), c1); sort(ask.begin(), ask.end(), c2); int p1 = 0; for(int j : ask){ while(p1 < uch.size() && y[j] <= d[uch[p1]]){ unite(u[uch[p1]], v[uch[p1]]); p1++; } int prev = tb.size(); for(int l : lis[j]){ unite(u[l], v[l]); } ans[j] = sz[get(x[j])]; revert(prev); } } for(int i=1; i<=q; i++){ if(t[i] == 2)cout << ans[i] << '\n'; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; //cin>>T; while (T--){ solve(); } }

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

bridges.cpp: In function 'void revert(int)':
bridges.cpp:37:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |     while(tb.size() > x){
      |           ~~~~~~~~~~^~~
bridges.cpp: In function 'void solve()':
bridges.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             while(p1 < uch.size() && y[j] <= d[uch[p1]]){
      |                   ~~~^~~~~~~~~~~~
#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...