Submission #336353

#TimeUsernameProblemLanguageResultExecution timeMemory
33635312tqianBridges (APIO19_bridges)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> struct DSU { std::vector<int> e; void init(int n) { e = std::vector<int>(n, -1); } int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } bool same_set(int a, int b) { return get(a) == get(b); } int size(int x) { return -e[get(x)]; } bool unite(int x, int y) { x = get(x), y = get(y); if (x == y) return false; if (e[x] > e[y]) std::swap(x, y); e[x] += e[y]; e[y] = x; return true; } }; inline char gc() { // like getchar() static char buf[1 << 16]; static size_t bc, be; if (bc >= be) { buf[0] = 0, bc = 0; be = fread(buf, 1, sizeof(buf), stdin); } return buf[bc++]; // returns 0 on EOF } int read_int() { int a, c; while ((a = gc()) < 40); if (a == '-') return -read_int(); while ((c = gc()) >= 48) a = a * 10 + c - 480; return a - 48; } int main() { const int B = 800; using namespace std; int n = read_int(); int m = read_int(); vector<vector<int>> adj(n); vector<array<int, 3>> ed; set<array<int, 2>> use; for (int i = 0; i < m; i++) { int u = read_int(); int v = read_int(); int w = read_int(); u--, v--; use.emplace(w, i); ed.push_back({u, v, w}); } vector<array<int, 3>> modify; vector<array<int, 3>> queries; vector<array<int, 2>> ans; vector<int> vis(n); vector<int> mod(m); vector<int> change(m, -1); vector<int> rem; vector<int> todo; DSU D; int q = read_int(); for (int i = 0; i < q; i++) { int x = read_int(); int y = read_int(); int z = read_int(); y--; if (x == 1) modify.push_back({y, z, i}); else queries.push_back({y, z, i}); if (i == q - 1 || int(modify.size()) + int(queries.size()) == B) { sort(queries.begin(), queries.end(), [](array<int, 3>& a, array<int, 3>& b) { return a[1] > b[1]; }); D.init(n); for (auto& mm : modify) mod[mm[0]] = 1; auto it = use.end(); for (auto& qq : queries) { int weight = qq[1]; int ti = qq[2]; if (it == use.begin()) break; auto ii = (*it)[1]; while (it != use.begin() && ed[ii][2] >= weight) { it--; if (!mod[ii]) D.unite(ed[ii][0], ed[ii][1]); } for (auto& mm : modify) { todo.push_back(mm[0]); if (mm[2] < ti) change[mm[0]] = mm[1]; } for (auto& t : todo) { if (change[t] == -1) { if (ed[t][2] >= weight) { int u = D.get(ed[t][0]); int v = D.get(ed[t][1]); adj[u].push_back(v); adj[v].push_back(u); } } else { if (change[t] >= weight) { int u = D.get(ed[t][0]); int v = D.get(ed[t][1]); adj[u].push_back(v); adj[v].push_back(u); } } } int res = 0; function<void(int)> dfs = [&](int src) { vis[src] = 1; res += D.size(src); rem.push_back(src); for (int nxt : adj[src]) { if (vis[nxt]) continue; dfs(nxt); } }; dfs(D.get(qq[0])); ans.push_back({ti, res}); for (auto& r : rem) vis[r] = 0; for (auto& t : todo) { change[t] = -1; int u = D.get(ed[t][0]); int v = D.get(ed[t][1]); adj[u].clear(); adj[v].clear(); } rem.clear(); todo.clear(); } for (auto& mm : modify) { mod[mm[0]] = 0; use.erase({ed[mm[0]][2], mm[0]}); ed[mm[0]][2] = mm[1]; use.insert({ed[mm[0]][2], mm[0]}); } queries.clear(); modify.clear(); } } sort(ans.begin(), ans.end()); for (auto& a : ans) cout << a[1] << '\n'; return 0; }

Compilation message (stderr)

In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                 from /usr/include/c++/9/bits/allocator.h:46,
                 from /usr/include/c++/9/string:41,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 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:1:
/usr/include/c++/9/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::array<int, 2>; _Args = {int&, int&}; _Tp = std::_Rb_tree_node<std::array<int, 2> >]':
/usr/include/c++/9/bits/alloc_traits.h:482:2:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = std::array<int, 2>; _Args = {int&, int&}; _Tp = std::_Rb_tree_node<std::array<int, 2> >; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<std::_Rb_tree_node<std::array<int, 2> > >]'
/usr/include/c++/9/bits/stl_tree.h:614:32:   required from 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type, _Args&& ...) [with _Args = {int&, int&}; _Key = std::array<int, 2>; _Val = std::array<int, 2>; _KeyOfValue = std::_Identity<std::array<int, 2> >; _Compare = std::less<std::array<int, 2> >; _Alloc = std::allocator<std::array<int, 2> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::array<int, 2> >*]'
/usr/include/c++/9/bits/stl_tree.h:631:4:   required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {int&, int&}; _Key = std::array<int, 2>; _Val = std::array<int, 2>; _KeyOfValue = std::_Identity<std::array<int, 2> >; _Compare = std::less<std::array<int, 2> >; _Alloc = std::allocator<std::array<int, 2> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::array<int, 2> >*]'
/usr/include/c++/9/bits/stl_tree.h:2408:13:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_unique(_Args&& ...) [with _Args = {int&, int&}; _Key = std::array<int, 2>; _Val = std::array<int, 2>; _KeyOfValue = std::_Identity<std::array<int, 2> >; _Compare = std::less<std::array<int, 2> >; _Alloc = std::allocator<std::array<int, 2> >]'
/usr/include/c++/9/bits/stl_set.h:463:64:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::emplace(_Args&& ...) [with _Args = {int&, int&}; _Key = std::array<int, 2>; _Compare = std::less<std::array<int, 2> >; _Alloc = std::allocator<std::array<int, 2> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::array<int, 2> >]'
bridges.cpp:61:25:   required from here
/usr/include/c++/9/ext/new_allocator.h:145:20: error: new initializer expression list treated as compound expression [-fpermissive]
  145 |  noexcept(noexcept(::new((void *)__p)
      |                    ^~~~~~~~~~~~~~~~~~
  146 |        _Up(std::forward<_Args>(__args)...)))
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/ext/new_allocator.h:145:20: error: no matching function for call to 'std::array<int, 2>::array(int&)'
In file included from /usr/include/c++/9/tuple:39,
                 from /usr/include/c++/9/functional:54,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from bridges.cpp:1:
/usr/include/c++/9/array:94:12: note: candidate: 'std::array<int, 2>::array()'
   94 |     struct array
      |            ^~~~~
/usr/include/c++/9/array:94:12: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/9/array:94:12: note: candidate: 'constexpr std::array<int, 2>::array(const std::array<int, 2>&)'
/usr/include/c++/9/array:94:12: note:   no known conversion for argument 1 from 'int' to 'const std::array<int, 2>&'
/usr/include/c++/9/array:94:12: note: candidate: 'constexpr std::array<int, 2>::array(std::array<int, 2>&&)'
/usr/include/c++/9/array:94:12: note:   no known conversion for argument 1 from 'int' to 'std::array<int, 2>&&'