#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
struct SegmentTree{
struct Node{
ll mi, ma, ans, lazy;
bool exist;
Node(){
mi = 0;
ma = 0;
ans = 0;
lazy = 0;
exist = false;
}
};
vector<Node> it;
int n;
SegmentTree(int _n = 0){
n = _n;
it.resize(n * 4 + 3);
}
void push(int i){
if(it[i].lazy == 0) return;
if(it[i * 2].exist){
it[i * 2].mi += it[i].lazy;
it[i * 2].ma += it[i].lazy;
it[i * 2].lazy += it[i].lazy;
}
if(it[i * 2 + 1].exist){
it[i * 2 + 1].mi += it[i].lazy;
it[i * 2 + 1].ma += it[i].lazy;
it[i * 2 + 1].lazy += it[i].lazy;
}
it[i].lazy = 0;
}
Node combine(Node a, Node b){
Node ans;
ans.mi = oo; ans.ma = -oo;
if(a.exist){
minimize(ans.mi, a.mi);
maximize(ans.ma, a.ma);
maximize(ans.ans, a.ans);
}
if(b.exist){
minimize(ans.mi, b.mi);
maximize(ans.ma, b.ma);
maximize(ans.ans, b.ans);
}
if(a.exist && b.exist){
maximize(ans.ans, a.ma - b.mi);
}
ans.exist = a.exist || b.exist;
return ans;
}
void update(int i, int l, int r, int u, int v, ll c, bool ok){
if(r < u || v < l) return;
if(ok && l == r){
it[i].mi += c;
it[i].ma += c;
it[i].exist = true;
return;
}
if(u <= l && r <= v){
if(it[i].exist){
it[i].mi += c;
it[i].ma += c;
it[i].lazy += c;
}
return;
}
push(i);
int m = (l + r) >> 1;
update(i * 2, l, m, u, v, c, ok);
update(i * 2 + 1, m + 1, r, u, v, c, ok);
it[i] = combine(it[i * 2], it[i * 2 + 1]);
}
void update(int u, int v, ll c, bool ok){
update(1, 1, n, u, v, c, ok);
}
};
struct FenwickTree{
vector<int> tree;
int n;
FenwickTree(int _n = 0){
n = _n;
tree.resize(n + 3, 0);
}
void update(int p, int c){
while(p <= n){
tree[p] += c;
p += p & -p;
}
}
int getVal(int p){
int ans = 0;
while(p > 0){
ans += tree[p];
p -= p & -p;
}
return ans;
}
};
void solve(){
// SegmentTree it(5);
// it.update(1, 1, -2);
// it.update(2, 5, -3);
// cout << it.it[1].ans << '\n';
// it.update(2, 2, -4);
// it.update(3, 5, -3);
// cout << it.it[1].ans << '\n';
// it.update(3, 3, -6);
// it.update(4, 5, -3);
// cout << it.it[1].ans << '\n';
int N, Q, D;
cin >> N >> Q >> D;
vector<int> a(N+Q), order(N+Q), pos(N+Q);
for(int i=0; i<N+Q; i++){
cin >> a[i];
order[i] = i;
}
sort(ALL(order), [&](int i, int j){return a[i] < a[j];});
for(int i=0; i<N+Q; i++){
pos[order[i]] = i + 1;
}
SegmentTree it(N+Q);
FenwickTree bit(N+Q);
for(int i=0; i<N+Q; i++){
bit.update(pos[i], 1);
int p = bit.getVal(pos[i]);
it.update(pos[i], pos[i], a[i] - 1LL * p * D, true);
// cout << p << ' ' << a[i] << '\n';
it.update(pos[i] + 1, N+Q, -D, false);
if(i + 1 > N){
int res = it.it[1].ans;
if(res & 1){
cout << res/2 << ".5 ";
}
else{
cout << res/2 << ' ';
}
}
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("task.inp", "r", stdin);
// freopen("task.out", "w", stdout);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
37712 KB |
Output is correct |
2 |
Incorrect |
124 ms |
38900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
37712 KB |
Output is correct |
2 |
Incorrect |
124 ms |
38900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |