# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871558 | resting | Chorus (JOI23_chorus) | C++17 | Compilation error | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct segtree{
signed l, r, i; int m, b; signed cnt;
segtree* lc = 0, *rc = 0;
segtree* getmem();
segtree(int l, int r) : l(l), r(r), m(0), b(1e9), cnt(0){
i = (l + r) / 2;
if(l==r) return;
lc = getmem(); *lc = segtree(l, i);
rc = getmem(); *rc = segtree(i+1, r);
};
segtree() : segtree(-1, -1){};
void u(int qm, int qb, int qcnt){
if(qm * i + qb < m*i+b){
swap(m, qm); swap(b, qb); swap(cnt, qcnt);
}
if(l == r) return;
if(qm > m) lc->u(qm, qb, qcnt);
else rc->u(qm, qb, qcnt);
}
pair<int, int> q(int qi){
pair<int, int> cur = {m*qi+b, cnt};
if(i == qi) return cur;
if(qi < i) return min(cur, lc->q(qi));
else return min(cur, rc->q(qi));
}
} mem[(int)2e7]; int memsz = 0;
segtree* segtree::getmem(){return &mem[memsz++];}
int n, k;
int res = 0;
int cnt = 0;string s;
vector<int> b;
void solve(int m){
segtree ac(0, n);
int sl = 0;
ac.u(0, 0, 0);
int cnta = 0;
int cur = 0;
int funnynumber = 0;
int cntactive = 0;
for(int i = 0; i < 2 * n; i++){
if(s[i] == 'A'){
if(cntactive>0) funnynumber -= cntactive;
cntactive++;
if(cntactive>0) funnynumber += b[cnta] - i - cntactive;
cnta++;
cur += sl;
auto tmp = ac.q(cnta);
tmp.first += m; tmp.second++;
if(cnta == n) {
res = tmp.first + cur;
cnt = tmp.second;
}
ac.u(-cnta, tmp.first + (cnta)*cnta+funnynumber, tmp.second);
}
else{
cntactive--;
sl++;
}
}
}
signed main(){
cin >> n >> k;
cin >> s;
int l = -1, r = 1e12;
int m = 0;
for(int i = 0; i < 2*n; i++){
if(s[i] == 'B') b.push_back(i);
}
while(r - l > 1){
m = (l+r)/2;
solve(m);
if(cnt <= k) r = m;
else l = m;
}
solve(r);
cout<<res-k*r<<endl;
}
Compilation message (stderr)
chorus.cpp: In member function 'void segtree::u(long long int, long long int, long long int)': chorus.cpp:19:53: error: no matching function for call to 'swap(int&, long long int&)' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included 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 chorus.cpp:1: /usr/include/c++/10/sstream:849:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>&)' 849 | swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, | ^~~~ /usr/include/c++/10/sstream:849:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included 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 chorus.cpp:1: /usr/include/c++/10/sstream:856:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>&)' 856 | swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, | ^~~~ /usr/include/c++/10/sstream:856:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included 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 chorus.cpp:1: /usr/include/c++/10/sstream:863:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>&)' 863 | swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, | ^~~~ /usr/include/c++/10/sstream:863:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included 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 chorus.cpp:1: /usr/include/c++/10/sstream:870:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>&)' 870 | swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, | ^~~~ /usr/include/c++/10/sstream:870:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/regex:62, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110, from chorus.cpp:1: /usr/include/c++/10/bits/regex.h:849:5: note: candidate: 'template<class _Ch_type, class _Rx_traits> void std::__cxx11::swap(std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&)' 849 | swap(basic_regex<_Ch_type, _Rx_traits>& __lhs, | ^~~~ /usr/include/c++/10/bits/regex.h:849:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::basic_regex<_Ch_type, _Rx_traits>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/regex:62, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110, from chorus.cpp:1: /usr/include/c++/10/bits/regex.h:2141:5: note: candidate: 'template<class _Bi_iter, class _Alloc> void std::__cxx11::swap(std::__cxx11::match_results<_BiIter, _Alloc>&, std::__cxx11::match_results<_BiIter, _Alloc>&)' 2141 | swap(match_results<_Bi_iter, _Alloc>& __lhs, | ^~~~ /usr/include/c++/10/bits/regex.h:2141:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::match_results<_BiIter, _Alloc>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/bits/stl_pair.h:59, from /usr/include/c++/10/bits/stl_algobase.h:64, from /usr/include/c++/10/bits/specfun.h:45, from /usr/include/c++/10/cmath:1927, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41, from chorus.cpp:1: /usr/include/c++/10/bits/move.h:189:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)' 189 | swap(_Tp& __a, _Tp& __b) | ^~~~ /usr/include/c++/10/bits/move.h:189:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: deduced conflicting types for parameter '_Tp' ('int' and 'long long int') 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/bits/stl_pair.h:59, from /usr/include/c++/10/bits/stl_algobase.h:64, from /usr/include/c++/10/bits/specfun.h:45, from /usr/include/c++/10/cmath:1927, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41, from chorus.cpp:1: /usr/include/c++/10/bits/move.h:213:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<std::__is_swappable<_Tp>::value> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])' 213 | swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) | ^~~~ /usr/include/c++/10/bits/move.h:213:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types '_Tp [_Nm]' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:64, from /usr/include/c++/10/bits/specfun.h:45, from /usr/include/c++/10/cmath:1927, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41, from chorus.cpp:1: /usr/include/c++/10/bits/stl_pair.h:533:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)' 533 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) | ^~~~ /usr/include/c++/10/bits/stl_pair.h:533:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::pair<_T1, _T2>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/bits/stl_algobase.h:64, from /usr/include/c++/10/bits/specfun.h:45, from /usr/include/c++/10/cmath:1927, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41, from chorus.cpp:1: /usr/include/c++/10/bits/stl_pair.h:541:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)' (deleted) 541 | swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete; | ^~~~ /usr/include/c++/10/bits/stl_pair.h:541:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::pair<_T1, _T2>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/string:55, 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 chorus.cpp:1: /usr/include/c++/10/bits/basic_string.h:6420:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 6420 | swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~ /usr/include/c++/10/bits/basic_string.h:6420:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/tuple:39, from /usr/include/c++/10/functional:54, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/array:321:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> typename std::enable_if<typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value>::type std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)' 321 | swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) | ^~~~ /usr/include/c++/10/array:321:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::array<_Tp, _Nm>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/tuple:39, from /usr/include/c++/10/functional:54, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/array:329:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> typename std::enable_if<(! typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value)>::type std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)' (deleted) 329 | swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) = delete; | ^~~~ /usr/include/c++/10/array:329:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::array<_Tp, _Nm>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/functional:54, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/tuple:1629:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(std::tuple<_Tps ...>&, std::tuple<_Tps ...>&)' 1629 | swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y) | ^~~~ /usr/include/c++/10/tuple:1629:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::tuple<_Tps ...>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/functional:54, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/tuple:1637:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(std::tuple<_Tps ...>&, std::tuple<_Tps ...>&)' (deleted) 1637 | swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete; | ^~~~ /usr/include/c++/10/tuple:1637:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::tuple<_Tps ...>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/functional:59, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/bits/std_function.h:720:5: note: candidate: 'template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)' 720 | swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept | ^~~~ /usr/include/c++/10/bits/std_function.h:720:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::function<_Res(_ArgTypes ...)>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/bits/node_handle.h:39, from /usr/include/c++/10/bits/hashtable.h:37, from /usr/include/c++/10/unordered_map:46, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/optional:1196:5: note: candidate: 'template<class _Tp> std::enable_if_t<(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>)> std::swap(std::optional<_Tp>&, std::optional<_Tp>&)' 1196 | swap(optional<_Tp>& __lhs, optional<_Tp>& __rhs) | ^~~~ /usr/include/c++/10/optional:1196:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::optional<_Tp>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/bits/node_handle.h:39, from /usr/include/c++/10/bits/hashtable.h:37, from /usr/include/c++/10/unordered_map:46, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/optional:1202:5: note: candidate: 'template<class _Tp> std::enable_if_t<(!(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>))> std::swap(std::optional<_Tp>&, std::optional<_Tp>&)' (deleted) 1202 | swap(optional<_Tp>&, optional<_Tp>&) = delete; | ^~~~ /usr/include/c++/10/optional:1202:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::optional<_Tp>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/unordered_map:47, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/bits/unordered_map.h:2076:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)' 2076 | swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, | ^~~~ /usr/include/c++/10/bits/unordered_map.h:2076:5: note: template argument deduction/substitution failed: chorus.cpp:19:53: note: mismatched types 'std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>' and 'int' 19 | swap(m, qm); swap(b, qb); swap(cnt, qcnt); | ^ In file included from /usr/include/c++/10/unordered_map:47, from /usr/include/c++/10/functional:61, from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/10/algorithm:74, from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65, from chorus.cpp:1: /usr/include/c++/10/bits/unordered_map.h:2083:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, c