이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int H=20;
const int N=(1<<H);
vi dif;
int seg[N*2], laz[N];
int width[N*2];
void fillW(int p=1, int w=N) {
width[p] = w;
if(w == 1) return;
fillW(p*2,w/2);
fillW(p*2+1,w/2);
}
void apply(int p, int v) {
seg[p] += v*width[p];
if(p < N) laz[p] += v;
}
void build(int p) {
while(p>1) p/=2, seg[p]=seg[p*2]+seg[p*2+1]+laz[p]*width[p];
}
void push(int p) {
REV(s,1,H+1) {
int i=p>>s;
apply(i*2 ,laz[i]);
apply(i*2+1,laz[i]);
laz[i] = 0;
}
}
void add(int l, int r, int v) {
int l0=l+=N, r0=r+=N;
for(; l<r; l/=2, r/=2) {
if(l&1) apply(l++,v);
if(r&1) apply(--r,v);
}
build(l0);
build(r0-1);
}
int get(int l, int r) {
l+=N; r+=N;
push(l);
push(r-1);
int res=0;
for(; l<r; l/=2, r/=2) {
if(l&1) res += seg[l++];
if(r&1) res += seg[--r];
}
return res;
}
vi countScans(vi A, vi X, vi V){
fillW();
int n=A.size();
int q=X.size();
vi ans(q);
RE(i,n) dif.pb(A[i]);
RE(i,q) dif.pb(V[i]);
sort(all(dif));
dif.erase(unique(all(dif)), dif.end());
RE(i,n) A[i] = lower_bound(all(dif), A[i])-dif.begin();
RE(i,q) V[i] = lower_bound(all(dif), V[i])-dif.begin();
RE(i,n) add(A[i],N,1);
RE(j,q) {
add(A[X[j]],N,-1);
A[X[j]] = V[j];
add(A[X[j]],N, 1);
int cAns = 0;
RE(i,n)
cAns = max(cAns, i-int(get(A[i],A[i]+1) - 1));
ans[j] = cAns;
}
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... |