Submission #370615

#TimeUsernameProblemLanguageResultExecution timeMemory
370615Jarif_RahmanBridges (APIO19_bridges)C++17
Compilation error
0 ms0 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 N = 5e4, M = 1e5, Q = 1e5, SQ = 316, lim = 2e5;
vector<int> sorter[lim];
tuple<int, int, int> srt[lim];
void counting_sort(tuple<int, int, int> *a, tuple<int, int, int> *b){
	int mx = 0;
    for(int i = 0; a+i < b; i++){
        sorter[get<0>(*(a+i))].pb(i);
		mx = max(mx, *(a+i));
    }
	int inx = 0;
    for(int i = 0; i <= mx; i++){
        while(!sorter[i].empty()) srt[inx++] = *(a+sorter[i].back())), sorter[i].pop_back();
    }
    for(int i = 0; i < inx; i++) *(a+i) = srt[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;
    }
    int get(int x){
        if(p[x] != x) return 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, ss] = st.top(); st.pop();
        sz[a]-=ss;
        sz[b] = ss;
        p[b] = b;
    }
};
tuple<int, int, int> edge[M];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	vector<int> compressor;
    map<int, int> mp;
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b, w; cin >> a >> b >> w; a--, b--;
        edge[i] = make_tuple(w, a, b);
		compressor.pb(w);
    }
	int cmpr = 0;
    int q; cin >> q;
    tuple<ll, int, int> query[Q];
    for(int i = 0; i < q; i++){
        int tt, s; ll 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++){
		if(i != 0 && compressor[i] == compressor[i-1]) continue;
        mp[compressor[i]] = cmpr++;
    }
    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;
    dsu ds(N);
    vector<tuple<int, int, int>> calc;
    bool ucng[M];
    for(int i = 0; i < m; i++) ucng[i] = 1;
    tuple<int, int, int> edges[M];
    vector<int> cng;
    for(int ql = 0; ql < q; ql+=SQ){
        int qr = min(q-1, ql+SQ-1);
        int cnt = 0;
        for(int j = ql; j <= qr; j++){
            auto [tt, s, w] = query[j];
            if(tt == 1){
                ucng[s] = 0;
            }
            else{
                cnt++;
                calc.pb({w, s, cnt-1});
            }
        }
        int inx = 0;
        for(int i = 0; i < m; i++){
            if(ucng[i]) edges[inx++] = edge[i];
            else cng.pb(i);
        }
        vector<int> anss(cnt);
        vector<vector<pair<int, int>>> upd(cnt);
        cnt = 0;
        for(int j = ql; j <= qr; j++){
            auto [tt, s, w] = query[j];
            if(tt == 1){
                get<0>(edge[s]) = w;
            }
            else{
                for(int x: cng){
                    auto [ww, a, b] = edge[x];
                    if(ww >= w) upd[cnt].pb({a, b});
                }
                cnt++;
            }
        }
        counting_sort(edges, edges+inx);
        sort(calc.rbegin(), calc.rend());
        int bc = inx-1;
        for(auto [w, s, in]: calc){
            while(bc >= 0 && get<0>(edges[bc]) >= w){
                auto [ww, a, b] = edges[bc]; bc--;
                ds.unite(a, b);
            }
            int k = 0;
            for(auto [a, b]: upd[in]) k+=ds.unite(a, b);
            anss[in] = ds.sz[ds.get(s)];
            while(k--) ds.rollback();
        }
        ans.insert(ans.end(), anss.begin(), anss.end());
        calc.clear();
        for(int i = 0; i < m; i++) ucng[i] = 1;
        cng.clear();
        while(!ds.st.empty()) ds.rollback();
    }
    for(int x: ans) cout << x << "\n";
}

Compilation message (stderr)

bridges.cpp: In function 'void counting_sort(std::tuple<int, int, int>*, std::tuple<int, int, int>*)':
bridges.cpp:15:22: error: no matching function for call to 'max(int&, std::tuple<int, int, int>&)'
   15 |   mx = max(mx, *(a+i));
      |                      ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from bridges.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
bridges.cpp:15:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::tuple<int, int, int>')
   15 |   mx = max(mx, *(a+i));
      |                      ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from bridges.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
bridges.cpp:15:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::tuple<int, int, int>')
   15 |   mx = max(mx, *(a+i));
      |                      ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from bridges.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
bridges.cpp:15:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   15 |   mx = max(mx, *(a+i));
      |                      ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from bridges.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
bridges.cpp:15:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   15 |   mx = max(mx, *(a+i));
      |                      ^
bridges.cpp:19:69: error: expected ';' before ')' token
   19 |         while(!sorter[i].empty()) srt[inx++] = *(a+sorter[i].back())), sorter[i].pop_back();
      |                                                                     ^
      |                                                                     ;
bridges.cpp: In function 'int main()':
bridges.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i = 0; i < compressor.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~