#include "bubblesort2.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
struct node
{
int l = 0;
int r = (1<<30)-1;
ll max_ = -1e9;
ll add = 0;
node* left = NULL;
node* right = NULL;
void push()
{
if(left == NULL)
{
left = new node;
left -> l = l;
left -> r = (l+r)/2;
right = new node;
right -> l = (l+r)/2+1;
right -> r = r;
}
right -> max_ += add;
right -> add += add;
left -> max_ += add;
left -> add += add;
add = 0;
}
void add_seg(int l2, int r2, ll w)
{
if(r < l2 || l > r2) return;
if(l >= l2 && r <= r2)
{
max_ += w;
add += w;
return;
}
push();
left -> add_seg(l2,r2,w);
right -> add_seg(l2,r2,w);
max_ = max(left -> max_, right -> max_);
}
};
node segtree;
map<int,set<int>> val_pos;
void add_num(int x, int p)
{
segtree.add_seg(0,x-1,1);
segtree.add_seg(x,x,(siz(val_pos[x]) != 0 ? *val_pos[x].begin() : 1e9));
val_pos[x].insert(p);
segtree.add_seg(x,x,-*val_pos[x].begin());
}
void del_num(int x, int p)
{
segtree.add_seg(0,x-1,-1);
segtree.add_seg(x,x,*val_pos[x].begin());
val_pos[x].erase(p);
segtree.add_seg(x,x,-(siz(val_pos[x]) != 0 ? *val_pos[x].begin() : 1e9));
}
vi countScans(vi A, vi X, vi V)
{
int n = siz(A);
rep(i,n) add_num(A[i],n-i-1);
vi ans;
rep(i,siz(X))
{
del_num(A[X[i]],n-X[i]-1);
A[X[i]] = V[i];
add_num(A[X[i]],n-X[i]-1);
ans.pb(segtree.max_);
}
return ans;
}
| # | 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... |