Submission #1093743

#TimeUsernameProblemLanguageResultExecution timeMemory
1093743_8_8_Reconstruction Project (JOI22_reconstruction)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 12, MOD = (int)1e9 + 3; #define int ll int n, m, vis[N], timer = 0, p[N], f[N]; vector<array<int, 3>> e(N); vector<vector<int>> tr; vector<int> cur; int id(int v, int u) { vector<vector<pair<int,int>>> g(n + 1); for(int i:cur) { g[e[i][1]].push_back({e[i][2], i}); g[e[i][2]].push_back({e[i][1], i}); } queue<int> q; q.push(v); ++timer; vis[v] = timer; while(!q.empty()) { int x = q.front(); q.pop(); // cout << x << ' ' << p[x] << '\n'; for(auto [to, i]:g[x]) { // cout << to << "x\n"; if(vis[to] != timer) { vis[to] = timer; p[to] = x; f[to] = i; q.push(to); } } } int ret = 1e9; while(u != v) { ret = min(ret, f[u]); u = p[u]; // cerr << u << ' ' << v << '\n'; } return ret; } int P[N]; int get(int a) { if(P[a] == a) return a; return P[a] = get(P[a]); } bool merge(int a, int b) { a = get(a); b = get(b); if(a == b) return false; P[a] = b; return true; } ll cost(vector<int> &x, int val) { // cout << (int)x.size() << '\n'; ll ret = 0; for(int i:x) { ret += abs(val - e[i][0]); } return ret; } int l[N], r[N]; const int inf = (int)1e9; void test() { cin >> n >> m; for(int i = 0;i < m; i++) { cin >> e[i][1] >> e[i][2] >> e[i][0]; l[i] = 0, r[i] = inf; } iota(P + 1, P + n + 1, 1); sort(e.begin(), e.begin() + m); int lst = 0; for(int i = 0;i < m; i++) { if(merge(e[i][2], e[i][1])) { cur.push_back(i); continue; } int j = id(e[i][1], e[i][2]); ll val = (e[i][0] + e[j][0] + 1) / 2; l[i] = val; r[j] = val - 1; for(int k = 0; k < (int)cur.size(); k++) { if(cur[k] == j) { cur.erase(cur.begin() + k); break; } } cur.push_back(i); } vector<array<int, 3>> o; for(int i = 0; i < m; i++) { o.push_back({l[i], r[i], e[i][0]}); } sort(o.begin(), o.end()); multiset<int> L, R; multiset<pair<int, int>> st; ll _l = 0, _r = 0; int q; cin >> q; int it = 0; while(q--) { int x; cin >> x; ll res = 0; auto add = [&](int val) { if(val <= x) { _l += val; L.insert(val); } else { _r += val; R.insert(val); } }; auto del = [&](int val) { if(L.find(val) != L.end()) { L.erase(L.find(val)); _l -= val; } else { R.erase(R.find(val)); _r -= val; } }; auto f = [&](multiset<int> &t, ll s) { res += abs(s - x * 1ll * (int)t.size()); }; while(it < m && o[it][0] <= x) { st.insert(o[it][1], o[it][2]); add(o[it][2]); it++; } while(!st.empty()) { auto [d, e] = (*st.begin()); if(d < x) { del(e); st.erase(st.find({d,e})); } else { break; } } while(!R.empty()) { int val = (*R.begin()); // cerr << val << ' ' << x << '\n'; if(val <= x) { R.erase(R.find(val)); _r -= val; add(val); } else { break; } } f(L, _l); f(R, _r); cout << res << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while(t--) test(); return 0; }

Compilation message (stderr)

reconstruction.cpp: In function 'void test()':
reconstruction.cpp:75:9: warning: unused variable 'lst' [-Wunused-variable]
   75 |     int lst = 0;
      |         ^~~
In file included from /usr/include/c++/10/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from reconstruction.cpp:1:
/usr/include/c++/10/bits/stl_multiset.h: In instantiation of 'void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]':
reconstruction.cpp:130:41:   required from here
/usr/include/c++/10/bits/stl_multiset.h:552:30: error: no matching function for call to 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_insert_range_equal(long long int&, long long int&)'
  552 |  { _M_t._M_insert_range_equal(__first, __last); }
      |    ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from reconstruction.cpp:1:
/usr/include/c++/10/bits/stl_tree.h:1122:2: note: candidate: 'template<class _InputIterator> std::__enable_if_t<std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_equal(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1122 |  _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_tree.h:1122:2: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<std::is_same<std::pair<long long int, long long int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value, void> std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_insert_range_equal<_InputIterator>(_InputIterator, _InputIterator) [with _InputIterator = long long int]':
/usr/include/c++/10/bits/stl_multiset.h:552:30:   required from 'void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
reconstruction.cpp:130:41:   required from here
/usr/include/c++/10/bits/stl_tree.h:1122:2: error: no type named 'value_type' in 'struct std::iterator_traits<long long int>'
/usr/include/c++/10/bits/stl_multiset.h: In instantiation of 'void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]':
reconstruction.cpp:130:41:   required from here
/usr/include/c++/10/bits/stl_tree.h:1131:2: note: candidate: 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_equal(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<long long int, long long int>; _Val = std::pair<long long int, long long int>; _KeyOfValue = std::_Identity<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1131 |  _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_tree.h:1131:2: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<std::pair<long long int, long long int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::_M_insert_range_equal<_InputIterator>(_InputIterator, _InputIterator) [with _InputIterator = long long int]':
/usr/include/c++/10/bits/stl_multiset.h:552:30:   required from 'void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = long long int; _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
reconstruction.cpp:130:41:   required from here
/usr/include/c++/10/bits/stl_tree.h:1113:52: error: no type named 'value_type' in 'struct std::iterator_traits<long long int>'
 1113 |  __enable_if_t<!__same_value_type<_InputIterator>::value>
      |                                                    ^~~~~