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>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e6 + 7;
const ll oo = 1e9 + 69;
int n, q;
vector<pa> val;
struct ST {
struct node {
int mx;
friend node operator + (node a, const node &b) {
maxi(a.mx, b.mx);
return a;
}
};
node st[4 * maxn];
int lz[4 * maxn];
void init(int n) {
for(int i = 0; i <= 4 * n; i++) st[i].mx = -oo;
}
void fix(int id, int l, int r) {
if(!lz[id]) return;
st[id].mx += lz[id];
if(l != r) {
lz[id << 1] += lz[id];
lz[id << 1 | 1] += lz[id];
}
lz[id] = 0;
}
void update2(int id, int l, int r, int pos, int val) {
fix(id, l, r);
if(pos < l || pos > r) return;
if(l == r) {
st[id].mx = val;
return;
}
int mid = l + r >> 1;
update2(id << 1, l, mid, pos, val);
update2(id << 1 | 1, mid + 1, r, pos, val);
st[id] = st[id << 1] + st[id << 1 | 1];
}
void update(int id, int l, int r, int u, int v, int val) {
fix(id, l, r);
if(r < u || l > v) return;
if(u <= l && r <= v) {
lz[id] += val;
fix(id, l, r);
return;
}
int mid = l + r >> 1;
update(id << 1, l, mid, u, v, val);
update(id << 1 | 1, mid + 1, r, u, v, val);
st[id] = st[id << 1] + st[id << 1 | 1];
}
int get() {
fix(1, 1, Size(val));
return st[1].mx;
}
} st;
struct BIT {
int bit[maxn];
void update(int x, int d) {
for(; x <= Size(val); x += x&-x) bit[x] += d;
}
int get(int x) {
int ans = 0;
for(; x; x -= x&-x) ans += bit[x];
return ans;
}
} bit;
int id(int v, int x) {
return lower_bound(all(val), make_pair(v, x)) - val.begin() + 1;
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
n = Size(a);
q = Size(x);
for(int i = 0; i < n; i++) val.pb({a[i], i});
for(int i = 0; i < q; i++) val.pb({v[i], x[i]});
sort(all(val));
val.erase(unique(all(val)), val.end());
st.init(Size(val));
for(int i = 0; i < n; i++) {
bit.update(id(a[i], i), 1);
}
for(int i = 0; i < n; i++) {
int idd = id(a[i], i);
st.update2(1, 1, Size(val), idd, i - bit.get(idd - 1));
}
vector<int> res;
for(int i = 0; i < q; i++) {
int idd = id(a[x[i]], x[i]);
st.update(1, 1, Size(val), idd + 1, Size(val), 1);
st.update2(1, 1, Size(val), idd, -oo);
bit.update(idd, -1);
a[x[i]] = v[i];
idd = id(a[x[i]], x[i]);
st.update(1, 1, Size(val), idd + 1, Size(val), -1);
st.update2(1, 1, Size(val), idd, x[i] - bit.get(idd - 1));
bit.update(idd, 1);
res.pb(st.get());
}
return res;
}
Compilation message (stderr)
bubblesort2.cpp: In member function 'void ST::update2(int, int, int, int, int)':
bubblesort2.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
59 | int mid = l + r >> 1;
| ~~^~~
bubblesort2.cpp: In member function 'void ST::update(int, int, int, int, int, int)':
bubblesort2.cpp:73:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |