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 pb emplace_back
#define get_pos(u,x) (lower_bound(begin(u),end(u),x) - begin(u))
using namespace std;
typedef long long ll;
const ll N = 500025, INF = 1e18;
struct Segtree {
ll mx[N<<1],lz[N];
void upd(int p, ll d) {
mx[p] += d;
if(p < N) lz[p] += d;
}
void pull(int p) {
for(; p>1; p>>=1) mx[p>>1] = max(mx[p],mx[p^1]) + lz[p>>1];
}
void push(int p) {
for(int h = __lg(N); h >= 0; h--) {
int i = p>>h;
if(!lz[i>>1]) continue;
upd(i,lz[i>>1]);
upd(i^1,lz[i>>1]);
lz[i>>1] = 0;
}
}
void add(int l, int r, ll d) {
int L = l, R = r;
for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
if(l&1) upd(l++, d);
if(r&1) upd(--r, d);
}
pull(L+N), pull(R-1+N);
}
ll query(int l, int r) {
ll res = -INF;
push(l+N), push(r-1+N);
for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
if(l&1) res = max(res, mx[l++]);
if(r&1) res = max(res, mx[--r]);
}
return res;
}
void dbg() {
cout << "-------\n";
for(int i = 0; i < 10; i++) {
push(i+N);
cout << mx[i+N] << ' ';
}
cout << '\n';
}
} sgt;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int n = A.size(), q = X.size();
vector<ll> a(n), v(q);
{
for(int i = 0; i < n; i++) a[i] = A[i] * N + i;
for(int i = 0; i < q; i++) v[i] = V[i] * N + X[i];
}
{
vector<ll> u;
for(int i = 0; i < n; i++) u.pb(a[i]);
for(int i = 0; i < q; i++) u.pb(v[i]);
sort(u.begin(), u.end());
u.erase(unique(u.begin(), u.end()), u.end());
for(int i = 0; i < n; i++) a[i] = get_pos(u, a[i]) + 1;
for(int i = 0; i < q; i++) v[i] = get_pos(u, v[i]) + 1;
}
vector<int> Q;
//sgt.init();
for(int i = 0; i < n; i++) {
sgt.add(a[i], a[i]+1, i);
sgt.add(a[i]+1, N, -1);
}
for(int i = 0; i < q; i++) {
int x = X[i], val = v[i];
sgt.add(a[x],a[x]+1, -x);
sgt.add(a[x]+1, N, 1);
a[x] = val;
sgt.add(a[x],a[x]+1, x);
sgt.add(a[x]+1, N, -1);
//sgt.dbg();
Q.pb(sgt.query(0,N));
}
return Q;
}
# | 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... |