Submission #766168

#TimeUsernameProblemLanguageResultExecution timeMemory
766168keta_tsimakuridzeJoker (BOI20_joker)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define f first #define s second //#define int long long #define pii pair<int,int> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; // ! int t, p[N], up[N], sz[N], ans[N], odd = 0; vector<int> V[N]; pair<int,int> e[N]; stack<int> st; pair<int,int> find(int u) { if(p[u] == u) return {u, 0}; pii P = find(p[u]); P.s ^= up[u]; return P; } void merge(int u, int v) { pii U = find(u), V = find(v); if(sz[U.f] < sz[V.f]) swap(U, V); if(U.f != V.f) { st.push(V.f); p[V.f] = U.f; sz[U.f] += sz[V.f]; up[V.f] = (U.s != V.s ? 0 : 1); return; } if(U.s == V.s) ++odd, st.push(-1); } void rollback(int X) { while(st.size() > X) { int x = st.top(); st.pop(); if(x == -1) --odd; else sz[p[x]] -= sz[x], p[x] = x, up[x] = 0; } } void solve(int l, int r, int L, int R) { int mid = (l + r) / 2; int I = st.size(); for(int i = l; i <= mid; i++) { merge(e[i].f, e[i].s); } int I2 = st.size(); int opt = R; while(opt && !odd) { --opt; if(!opt) break; merge(e[opt].f, e[opt].s); } ans[mid] = opt; rollback(I2); if(mid + 1 <= r) solve(mid + 1, r, opt, R); rollback(I); for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s); if(l < mid) solve(l, mid - 1, L, opt); rollback(I); } main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); int n, m, q; cin >> n >> m >> q; for(int i = 1; i <= n; i++) p[i] = i, sz[i] = 1; for(int i = 1; i <= m; i++) cin >> e[i].f >> e[i].s; e[0] = {0, 1}; solve(0, m, 0, m + 1); // for(int i = 1; i <= m; i++) cout << ans[i] << " "; cout << endl; for(int i = 1; i <= q; i++) { int l, r; cin >> l >> r; cout << (ans[l - 1] > r ? "YES\n" : "NO\n"); } }

Compilation message (stderr)

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     while(st.size() > X) {
      |           ~~~~~~~~~~^~~
Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:57:29: error: no matching function for call to 'max(long long int, int&)'
   57 |     for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s);
      |                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Joker.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:
Joker.cpp:57:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   57 |     for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s);
      |                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Joker.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:
Joker.cpp:57:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   57 |     for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Joker.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:
Joker.cpp:57:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   57 |     for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s);
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Joker.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:
Joker.cpp:57:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   57 |     for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s);
      |                             ^
Joker.cpp: At global scope:
Joker.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main(){
      | ^~~~