This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#pragma GCC target("sse4,tune=native")
#pragma GCC optimize("O3","unroll-loops")
#include "bubblesort2.h"
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>
using namespace std;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
const string FILENAME = "input";
const int MAXN = 500228;
int n;
vector<int> mod;
vector<int> d;
int ss;
int where[MAXN * 2];
inline void push(const int &v) {
if (mod[v]) {
d[v] += mod[v];
if (v < ss) {
mod[v << 1] += mod[v];
mod[(v << 1) + 1] += mod[v];
}
mod[v] = 0;
}
}
void add(int v, int vl, int vr, const int &l, const int &r, const int &x) {
if (vl > r || vr < l) {
push(v);
return;
}
if (l <= vl && vr <= r) {
mod[v] += x;
push(v);
return;
}
push(v);
int vn = v << 1;
int vm = (vl + vr) >> 1;
add(vn, vl, vm, l, r, x);
add(vn + 1, vm + 1, vr, l, r, x);
d[v] = max(d[vn], d[vn + 1]);
}
int border[MAXN * 2];
int a[MAXN * 2];
vector<pair<int, int> > st;
void add(int val) {
add(1, 1, ss, where[val], where[val], 1000000000);
add(1, 1, ss, border[where[val] - 1] + 1, sz(st), -1);
}
void del(int val) {
add(1, 1, ss, where[val], where[val], -1000000000);
add(1, 1, ss, border[where[val] - 1] + 1, sz(st), 1);
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
n = sz(A);
for (int i = 0; i < n; i++) {
st.pb({A[i], i});
a[i] = i;
}
for (int i = 0; i < sz(X); i++) {
st.pb({V[i], n + i});
}
sort(all(st));
ss = 1;
while (ss < sz(st)) {
ss <<= 1;
}
d.resize(2 * ss);
mod.resize(2 * ss);
for (int i = 0; i < sz(st); i++) {
where[st[i].second] = i + 1;
add(1, 1, ss, i + 1, i + 1, -1000000000 + (st[i].second >= n ? X[st[i].second - n]: st[i].second) + 1);
}
int uk = sz(st);
for (int i = sz(st) - 1; i >= 0; i--) {
while (uk - 1 >= 0 && st[uk - 1].first >= st[i].first) {
uk--;
}
border[i] = uk;
}
for (int i = 0; i < n; i++) {
add(a[i]);
}
vector<int> answer;
for (int i = 0; i < sz(X); i++) {
del(a[X[i]]);
a[X[i]] = n + i;
add(a[X[i]]);
answer.pb(d[1] + mod[1]);
}
return answer;
}
# | 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... |