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 "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=5e5+5;
const int OFF=(1<<20);
int n, q, ma;
vector <int> sol;
vector <pii> saz;
int T[2*OFF];
int prop[2*OFF];
int F[2*N];
void propag(int pos) {
if (!prop[pos]) return;
T[pos]+=prop[pos];
if (pos<OFF) {
prop[pos*2]+=prop[pos];
prop[pos*2+1]+=prop[pos];
}
prop[pos]=0;
}
//fl=0 interval, fl=1-> postavi
void update(int a, int b, int val, int fl, int pos=1, int lo=0, int hi=OFF) {
propag(pos);
if (lo>=b || hi<=a) return;
if (lo>=a && hi<=b) {
if (fl) T[pos]=val;
else prop[pos]+=val;
propag(pos);
return;
}
int mid=(lo+hi)/2;
update(a, b, val, fl, pos*2, lo, mid);
update(a, b, val, fl, pos*2+1, mid, hi);
T[pos]=max(T[pos*2], T[pos*2+1]);
}
int query() {
propag(1);
return T[1];
}
void upd_f(int x, int val) {
for (; x<=ma; x+=x&-x) F[x]+=val;
}
int manji(int x) {
x--;
int ret=0;
for (; x>0; x-=x&-x) ret+=F[x];
return ret;
}
void postavi(int x, int val) {
update(x, x+1, val, 1);
}
#define DEBUG 0
vector<int> countScans(vector<int> A, vector<int> XX, vector<int> V){
n=A.size();
q=V.size();
for (int i=0; i<n; ++i) saz.pb(mp(A[i], i));
for (int i=0; i<q; ++i) saz.pb(mp(V[i], XX[i]));
sort(saz.begin(), saz.end());
saz.erase(unique(saz.begin(), saz.end()), saz.end());
for (int i=0; i<n; ++i) A[i]=lower_bound(saz.begin(), saz.end(), mp(A[i], i))-saz.begin()+1;
for (int i=0; i<q; ++i) V[i]=lower_bound(saz.begin(), saz.end(), mp(V[i], XX[i]))-saz.begin()+1;
#if DEBUG
printf("A: ");
for (int x:A) printf("%d ", x);
printf("\nV: ");
for (int x:V) printf("%d ", x);
printf("\n");
#endif // DEBUG
ma=(int)saz.size()+1;
for (int i=0; i<n; ++i) upd_f(A[i], 1);
fill(T, T+2*OFF, -INF);
for (int i=0; i<n; ++i) {
T[OFF+A[i]]=i-manji(A[i]);
#if DEBUG
printf("broj: %d, val: %d\n", A[i], i-manji(A[i]));
#endif
}
for (int i=OFF-1; i>0; --i) T[i]=max(T[i*2], T[i*2+1]);
for (int i=0; i<q; ++i) {
int x=A[XX[i]], y=V[i];
A[XX[i]]=y;
upd_f(x, -1);
upd_f(y, 1);
postavi(x, -INF);
postavi(y, XX[i]-manji(y));
#if DEBUG
printf("pos: %d, x: %d, y: %d\n", XX[i], x, y);
printf("nova vrijednost: %d\n", XX[i]-manji(y));
#endif // DEBUG
update(y+1, ma, -1, 0);
update(x+1, ma, 1, 0);
#if DEBUG
printf("interval [%d, %d] +1 \n", x+1, ma-1);
printf("interval [%d, %d] -1 \n", y+1, ma-1);
printf("\n\n");
#endif
sol.pb(query());
}
return sol;
}
# | 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... |