Submission #419528

#TimeUsernameProblemLanguageResultExecution timeMemory
419528codebuster_10Bridges (APIO19_bridges)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std ; #define int int64_t //be careful about this #define endl "\n" #define f(i,a,b) for(int i=int(a);i<int(b);++i) #define pr pair #define ar array #define fr first #define sc second #define vt vector #define pb push_back #define eb emplace_back #define LB lower_bound #define UB upper_bound #define PQ priority_queue #define sz(x) ((int)(x).size()) #define all(a) (a).begin(),(a).end() #define allr(a) (a).rbegin(),(a).rend() #define mem(a,b) memset(a, b, sizeof(a)) template<class A> void rd(vt<A>& v); template<class T> void rd(T& x){ cin >> x; } template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;} template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;} template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<typename T> void __p(T a) { cout<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cout<<"{"; __p(a.first); cout<<","; __p(a.second); cout<<"}\n"; } template<typename T> void __p(std::vector<T> a) { cout<<"{"; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cout<<",}\n"[it+1==a.end()]; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "; __p(arg1); cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(;; i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<" | "; __f(comma+1,args...); } void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); cout.precision(15); cout << fixed; #ifdef ONLINE_JUDGE if(sz(s)){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } #define __f(...) 0 #endif } // solution by :- https://usaco.guide/problems/apio-2019bridges/solution int n, m, q; const int BLOCK_SIZE = 1000; const int MAX_N = 5e4 + 1, MAX_M = 1e5 + 1; stack<int> st; int size[MAX_N], parent[MAX_N]; void reset(){ iota(parent + 1, parent + n + 1, 1); fill(size + 1, size + n + 1, 1); return; } int find(int a){ while(parent[a] != a) a = parent[a]; return a; } void join(int a,int b){ a = find(a), b = find(b); if(a == b) return; if(size[a] > size[b]) swap(a,b); // a is child of b now. st.push(a); size[b] += size[a], parent[a] = b; return; } void roll_back(int req_size){ while(int(st.size()) > req_size){ int x = st.top(); st.pop(); size[parent[x]] -= size[x]; parent[x] = x; } return; } int u[MAX_M], v[MAX_M], w[MAX_M]; int t[MAX_M], x[MAX_M], y[MAX_M]; bool changed[MAX_M]; vector<int> to_join[BLOCK_SIZE]; int ans[MAX_M]; signed main(){ setIO(); rd(n,m); f(i,1,m+1){ rd(u[i],v[i],w[i]); } rd(q); f(i,1,q+1) rd(t[i],x[i],y[i]); for(int l = 1; l <= q; l += BLOCK_SIZE){ int r = min(q + 1, l + BLOCK_SIZE); reset(); fill(changed + 1, changed + m + 1, false); vt<int> upd, ask, unchanged; f(i,l,r){ if(t[i] == 1){ changed[x[i]] = true; upd.pb(i); }else{ ask.pb(i); } } f(i,1,m+1) if(!changed[i]) unchanged.pb(i); f(i,l,r){ if(t[i] == 1){ w[x[i]] = y[i]; }else{ to_join[i-l].clear(); for(auto j : upd) if (w[x[j]] >= y[i]) to_join[i-l].push_back(x[j]); } } sort(all(ask),[&](auto A,auto B){ return y[A] > y[B]; }); sort(all(unchanged),[&](auto A, auto B){ return w[A] > w[B]; }); int ptr = 0; for(auto i : ask){ while(ptr < sz(unchanged) && w[unchanged[ptr]] >= y[i]) { join(u[unchanged[ptr]], v[unchanged[ptr]]); ptr++; } int prev_size = sz(st); for(auto j : to_join[i - l]) join(u[j], v[j]); ans[i] = size[find(x[i])]; roll_back(prev_size); } } f(i,1,q+1) if(t[i] == 2) cout << ans[i] << endl; }

Compilation message (stderr)

bridges.cpp: In function 'void reset()':
bridges.cpp:131:7: error: reference to 'size' is ambiguous
  131 |  fill(size + 1, size + n + 1, 1);
      |       ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp:131:17: error: reference to 'size' is ambiguous
  131 |  fill(size + 1, size + n + 1, 1);
      |                 ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp: In function 'void join(int64_t, int64_t)':
bridges.cpp:143:5: error: reference to 'size' is ambiguous
  143 |  if(size[a] > size[b]) swap(a,b);
      |     ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp:143:15: error: reference to 'size' is ambiguous
  143 |  if(size[a] > size[b]) swap(a,b);
      |               ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp:146:2: error: reference to 'size' is ambiguous
  146 |  size[b] += size[a], parent[a] = b;
      |  ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp:146:13: error: reference to 'size' is ambiguous
  146 |  size[b] += size[a], parent[a] = b;
      |             ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp: In function 'void roll_back(int64_t)':
bridges.cpp:153:3: error: reference to 'size' is ambiguous
  153 |   size[parent[x]] -= size[x];
      |   ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp:153:22: error: reference to 'size' is ambiguous
  153 |   size[parent[x]] -= size[x];
      |                      ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~
bridges.cpp: In function 'int main()':
bridges.cpp:218:13: error: reference to 'size' is ambiguous
  218 |    ans[i] = size[find(x[i])];
      |             ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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 bridges.cpp:1:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
bridges.cpp:126:5: note:                 'int64_t size [50001]'
  126 | int size[MAX_N], parent[MAX_N];
      |     ^~~~