제출 #632828

#제출 시각아이디문제언어결과실행 시간메모리
632828erto다리 (APIO19_bridges)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
typedef long long int ll;
#define INF 1000000007
#define INF2 998244353
#define N (ll)(1e5+ 5)
using namespace std;
//#define int ll
#define lsb(x) (x & (-x))
 
const int K = 320;
int n, m,  cur=0, g, h, q;
int u[N], v[N], d[N];
int x[N], y[N], ans[N];
bool used[N];
pair<int, int> upd[N], qu[N];
vector<int> lis[N];

int p[N], sz[N];
vector<int> tb;

int get(int x){
    return p[x] == x ? x : get(p[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 x, int y){
    return qu[x].second > qu[y].second;
}

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 >> g;
        if(g == 1){
            cin >> g >> h;
            upd[i] = {g, h};
        }
        else{
            cin >> g >> h;
            qu[i] = {g, h};
        }
    }

    for(int i=0; i<= q / K; i++){
        int l = max(1ll, 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(upd[j].first){
                used[upd[j].first] = 1;
                ch.push_back(j);
            }
            else{
                ask.push_back(j);
            }
        }

        for(int j=l; j<r; j++){
            if(qu[j].first){
                for(int u : ch){
                    if(d[upd[u].first] >= qu[j].second){
                      lis[j].push_back(upd[u].first);
                    }
                }
            }
            else{
                d[upd[j].first] = upd[j].second;
            }
        }

        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() && qu[j].second <= 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(qu[j].first)];
            revert(prev);
        }
    }
    for(int i=1; i<=q; i++){
        if(qu[i].first)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:73:31: error: no matching function for call to 'max(long long int, int)'
   73 |         int l = max(1ll, i * K), r = min((i + 1) * K, q + 1);
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from bridges.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
bridges.cpp:73:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   73 |         int l = max(1ll, i * K), r = min((i + 1) * K, q + 1);
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from bridges.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
bridges.cpp:73:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   73 |         int l = max(1ll, i * K), r = min((i + 1) * K, q + 1);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bridges.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
bridges.cpp:73:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   73 |         int l = max(1ll, i * K), r = min((i + 1) * K, q + 1);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bridges.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
bridges.cpp:73:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   73 |         int l = max(1ll, i * K), r = min((i + 1) * K, q + 1);
      |                               ^
bridges.cpp:79:24: error: 'r' was not declared in this scope
   79 |         for(int j=l; j<r; j++){
      |                        ^
bridges.cpp:89:24: error: 'r' was not declared in this scope
   89 |         for(int j=l; j<r; j++){
      |                        ^
bridges.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |             while(p1 < uch.size() && qu[j].second <= d[uch[p1]]){
      |                   ~~~^~~~~~~~~~~~