#define _CRT_SECURE_NO_WARNINGS
#include "bubblesort2.h"
#include <bits/stdc++.h>
#include <array>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/***************************JOI Open 18 - bubblesort***********************************/
const int inf = 1 << 20;
struct LazySegTree {
int sz;
v<int> data, lazy;
void init(int n, int val) {
data = v<int>(4 * n, val), lazy = v<int>(4 * n, val);
sz = n;
}
void prop(int ind, int L, int R) {
if (lazy[ind] != 0) {
data[ind] += lazy[ind];
if (L != R) {
lazy[2 * ind] += lazy[ind];
lazy[2 * ind + 1] += lazy[ind];
}
lazy[ind] = 0;
}
}
void combine(int ind) {
data[ind] = max(data[2 * ind], data[2 * ind + 1]);
}
int query() {
return query(0, sz - 1, 1, 0, sz - 1);
}
void update(int lo, int hi, int val) {
update(lo, hi, val, 1, 0, sz - 1);
}
void update(int lo, int hi, int val, int ind, int L, int R) {
prop(ind, L, R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] += val;
prop(ind, L, R);
return;
}
int M = (L + R) / 2;
update(lo, hi, val, 2 * ind, L, M); update(lo, hi, val, 2 * ind + 1, M + 1, R);
combine(ind);
}
int query(int lo, int hi, int ind, int L, int R) {
prop(ind, L, R);
if (lo > R || L > hi) return -inf;
if (lo <= L && R <= hi) return data[ind];
int M = (L + R) / 2;
return max(query(lo, hi, 2 * ind, L, M), query(lo, hi, 2 * ind + 1, M + 1, R));
}
};
v<int> countScans(v<int> A, v<int> X, v<int> V) {
int n = A.size(), q = X.size();
// compress
v<pii> dat;
dat.reserve(n + q);
FOR(i, 0, n) dat.push_back({ A[i], i });
FOR(i, 0, q) dat.push_back({ V[i], X[i] });
sort(all(dat));
dat.resize(unique(all(dat)) - dat.begin());
FOR(i, 0, n) A[i] = lower_bound(all(dat), mp(A[i], i)) - dat.begin();
FOR(i, 0, q) V[i] = lower_bound(all(dat), mp(V[i], X[i])) - dat.begin();
// init
LazySegTree tree;
tree.init(dat.size(), -inf);
FOR(i, 0, n) {
tree.update(A[i] + 1, tree.sz - 1, -1);
tree.update(A[i], A[i], inf+i);
}
// process q
v<int> ans(q);
FOR(i, 0, q) {
int pos = X[i];
int _new = V[i];
int _old = A[pos];
tree.update(_old, _old, -inf - pos);
tree.update(_new, _new, inf + pos);
if (_new < _old)
tree.update(_new + 1, _old, -1);
else if (_new > _old)
tree.update(_old + 1, _new, +1);
A[pos] = _new;
ans[i] = tree.query();
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
1792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |