#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll seg[4000009];
ll lazy[4000009];
void push(ll v){
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
seg[2*v] += lazy[v];
seg[2*v+1] += lazy[v];
lazy[v] = 0;
}
void upd(ll v, ll tl, ll tr, ll l, ll r, ll val){
if(r < tl || tr < l) return;
if(l <= tl && tr <= r){
seg[v] += val;
lazy[v] += val;
}
else{
push(v);
upd(2*v, tl, (tl+tr)/2, l, r, val);
upd(2*v+1, (tl+tr)/2+1, tr, l, r, val);
seg[v] = max(seg[2*v], seg[2*v+1]);
}
}
vector<ll> mpp;
ll get(ll x){
return lower_bound(mpp.begin(), mpp.end(), x)-mpp.begin();
}
set<ll, greater<ll>> s[1000009];
ll n, N;
void erase(ll idx, vector<ll> &a){
if(*s[a[idx]].begin() == idx+1){
upd(1, 0, N, a[idx], a[idx], -(idx+1));
s[a[idx]].erase(idx+1);
if(s[a[idx]].size())
upd(1, 0, N, a[idx], a[idx], *s[a[idx]].begin());
}
else
s[a[idx]].erase(idx+1);
upd(1, 0, N, a[idx], N, 1);
}
void add(ll idx, vector<ll> &a){
if(idx+1 > *s[a[idx]].begin()){
upd(1, 0, N, a[idx], a[idx], -*s[a[idx]].begin());
upd(1, 0, N, a[idx], a[idx], (idx+1));
}
s[a[idx]].insert(idx+1);
upd(1, 0, N, a[idx], N, -1);
}
vector<ll> countScans(vector<ll> a, vector<ll> x, vector<ll> v){
n = a.size();
for(auto u : a)
mpp.pb(u);
for(auto u : v)
mpp.pb(u);
sort(mpp.begin(), mpp.end());
mpp.resize(unique(mpp.begin(), mpp.end())-mpp.begin());
N = mpp.size()-1;
for(auto &u : a)
u = get(u);
for(auto &u : v)
u = get(u);
for(ll i = 0; i < n; ++i){
s[a[i]].insert(i+1);
upd(1, 0, N, a[i], n, -1);
}
for(ll i = 0; i < n; ++i)
if(*s[a[i]].begin() == i+1){
upd(1, 0, N, a[i], a[i], i+1);
}
vector<ll> ans(x.size());
for(ll i = 0; i < x.size(); ++i){
erase(x[i], a);
a[x[i]] = v[i];
add(x[i], a);
ans[i] = max(seg[1], 0);
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<long long int> countScans(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
bubblesort2.cpp:84:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i = 0; i < x.size(); ++i){
~~^~~~~~~~~~
bubblesort2.cpp:88:31: error: no matching function for call to 'max(ll&, int)'
ans[i] = max(seg[1], 0);
^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/istream:38,
from /usr/include/c++/7/sstream:38,
from /usr/include/c++/7/complex:45,
from /usr/include/c++/7/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
from bubblesort2.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
max(const _Tp& __a, const _Tp& __b)
^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: template argument deduction/substitution failed:
bubblesort2.cpp:88:31: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
ans[i] = max(seg[1], 0);
^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/istream:38,
from /usr/include/c++/7/sstream:38,
from /usr/include/c++/7/complex:45,
from /usr/include/c++/7/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
from bubblesort2.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: template argument deduction/substitution failed:
bubblesort2.cpp:88:31: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
ans[i] = max(seg[1], 0);
^
In file included from /usr/include/c++/7/algorithm:62:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
from bubblesort2.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
max(initializer_list<_Tp> __l)
^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: template argument deduction/substitution failed:
bubblesort2.cpp:88:31: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
ans[i] = max(seg[1], 0);
^
In file included from /usr/include/c++/7/algorithm:62:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
from bubblesort2.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
max(initializer_list<_Tp> __l, _Compare __comp)
^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: template argument deduction/substitution failed:
bubblesort2.cpp:88:31: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
ans[i] = max(seg[1], 0);
^