Submission #318751

#TimeUsernameProblemLanguageResultExecution timeMemory
318751BeanZBridges (APIO19_bridges)C++14
Compilation error
0 ms0 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 1e5 + 5; vector<pair<ll, ll>> rb; vector<ll> join[N]; ll u[N], v[N], d[N], t[N], a[N], b[N], ch[N], p[N], ans[N]; void rollback(ll u){ while (rb.size() > u){ p[rb.back().first] = rb.back().second; rb.pop_back(); } } ll find_set(ll u){ if (p[u] < 0) return u; return find_set(p[u]); } void dsu(ll u, ll v){ u = find_set(u); v = find_set(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); rb.push_back({u, p[u]}); rb.push_back({v, p[v]}); p[u] += p[v]; p[v] = u; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n, m; cin >> n >> m; for (int i = 1; i <= m; i++){ cin >> u[i] >> v[i] >> d[i]; } ll q; cin >> q; for (int i = 1; i <= q; i++){ cin >> t[i] >> a[i] >> b[i]; } const int base = 400; for (int l = 1; l <= q; l += base){ for (int i = 1; i <= n; i++) p[i] = -1; ll r = min(1ll * l + base - 1, q); for (int i = 1; i <= m; i++) ch[i] = 0; rb.clear(); vector<ll> memupd, memres, un; for (int i = l; i <= r; i++){ if (t[i] == 1) memupd.push_back(a[i]); } for (int i = l; i <= r; i++){ if (t[i] == 1){ d[a[i]] = b[i]; ch[a[i]] = 1; } else { for (auto j : memupd){ if (d[j] >= b[i]){ join[i].push_back(j); } } memres.push_back(i); } } for (int i = 1; i <= m; i++){ if (ch[i] == 0) un.push_back(i); } sort(un.begin(), un.end(), [&](ll g, ll h){return d[g] > d[h];}); sort(memres.begin(), memres.end(), [&](ll g, ll h){return b[g] > b[h];}); ll now = 0; //for (auto j : memres) cout << j << " "; //cout << endl; for (auto j : memres){ while (now < un.size() && d[un[now]] >= b[j]){ dsu(u[un[now]], v[un[now]]); //cout << u[un[now]] << " " << v[un[now]] << " " << now << " " << a[j] << " " << j << endl; now++; } ll tmp = rb.size(); for (auto o : join[j]){ dsu(u[o], v[o]); } //cout << b[j] << endl; //cout << j << endl; ans[j] = -p[find_set(a[j])]; //cout << j << " " << ans[j] << endl; rollback(tmp); } } for (int i = 1; i <= q; i++){ if (t[i] == 2) cout << ans[i] << endl; } } /* 3 4 1 2 5 2 3 2 3 1 4 2 3 8 1 2 1 5 */

Compilation message (stderr)

bridges.cpp: In function 'void rollback(int)':
bridges.cpp:11:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |     while (rb.size() > u){
      |            ~~~~~~~~~~^~~
bridges.cpp: In function 'int main()':
bridges.cpp:50:41: error: no matching function for call to 'min(long long int, int&)'
   50 |         ll r = min(1ll * l + base - 1, q);
      |                                         ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from bridges.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
bridges.cpp:50:41: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   50 |         ll r = min(1ll * l + base - 1, q);
      |                                         ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from bridges.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
bridges.cpp:50:41: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   50 |         ll r = min(1ll * l + base - 1, q);
      |                                         ^
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:2:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
bridges.cpp:50:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |         ll r = min(1ll * l + base - 1, q);
      |                                         ^
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:2:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
bridges.cpp:50:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   50 |         ll r = min(1ll * l + base - 1, q);
      |                                         ^
bridges.cpp:79:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             while (now < un.size() && d[un[now]] >= b[j]){
      |                    ~~~~^~~~~~~~~~~
bridges.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~