#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int NMAX=1e6;
int sz;
struct SegTree
{
public:
struct node
{
int val, lazy=0;
} t[6*NMAX+5];
void lazy (int nod)
{
t[nod].val+=t[nod].lazy;
t[nod*2].lazy+=t[nod].lazy;
t[nod*2+1].lazy+=t[nod].lazy;
t[nod].lazy=0;
}
void actupdate (int nod, int st, int dr, int stq, int drq, int val)
{
lazy (nod);
if (stq<=st && dr<=drq)
{
t[nod].lazy+=val;
lazy (nod);
}
else
{
lazy (nod*2);
lazy (nod*2+1);
int mij = (st+dr) >> 1;
if (drq<=mij)
actupdate (nod*2, st, mij, stq, drq, val);
else if (stq>mij)
actupdate (nod*2+1, mij+1, dr, stq, drq, val);
else actupdate (nod*2, st, mij, stq, drq, val), actupdate (nod*2+1, mij+1, dr, stq, drq, val);
t[nod].val=max (t[nod*2].val, t[nod*2+1].val);
}
}
void update (int l, int r, int val)
{
if (l>r)
return;
actupdate (1, 1, sz, l, r, val);
}
int actquery (int nod, int st, int dr, int stq, int drq)
{
lazy (nod);
if (stq<=st && dr<=drq)
{
return t[nod].val;
}
else
{
int mij = (st+dr) >> 1;
if (drq<=mij)
return actquery (nod*2, st, mij, stq, drq);
if (stq>mij)
return actquery (nod*2+1, mij+1, dr, stq, drq);
return max (actquery (nod*2, st, mij, stq, drq), actquery (nod*2+1, mij+1, dr, stq, drq));
}
}
int query (int st, int dr)
{
return actquery (1, 1, sz, st, dr);
}
};
SegTree aint;
vector <int> countScans (vector <int> a, vector <int> x, vector <int> y)
{
vector <int> rez (x.size());
vector <pair <int, int>> vec;
int n=a.size();
int q=x.size();
for (int i=0;i<n;i++)
{
vec.push_back ({a[i], i});
}
for (int i=0;i<q;i++)
{
vec.push_back ({y[i], x[i]});
}
sort (vec.begin(), vec.end());
vec.erase (unique (vec.begin(), vec.end()), vec.end());
sz=vec.size();
auto findPoz = [&] (int val)
{
return (lower_bound (vec.begin(), vec.end(), make_pair (a[val], val))-vec.begin()+1);
};
for (int i=0;i<n;i++)
{
int poz=findPoz (i);
aint.update (poz, poz, i);
aint.update (poz+1, sz, -1);
}
for (int i=0;i<q;i++)
{
int poz=findPoz (x[i]);
aint.update (poz, poz, -x[i]);
aint.update (poz+1, sz, 1);
a[x[i]]=y[i];
poz=findPoz (x[i]);
aint.update (poz, poz, x[i]);
aint.update (poz+1, sz, -1);
rez[i]=aint.query (1, sz);
}
return rez;
}
# | 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... |