#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
template<typename T>
struct lazysegtree {
/*=======================================================*/
struct data {
ll mn,mx,res,active;
};
struct lazy {
ll a;
};
data d_neutral = {inf2,-inf2,0,0};
lazy l_neutral = {0};
void merge(data &curr, data &left, data &right) {
curr.mn = min(left.mn,right.mn);
curr.mx = max(left.mx,right.mx);
curr.res = max({left.res,right.res,left.mx-right.mn});
curr.active = left.active+right.active;
}
void create(int x, int lx, int rx, T v) {
}
void modify(int x, int lx, int rx, T v) {
if(v.ff == 1){
lz[x].a = v.ss;
}
else{
tr[x].mn = tr[x].mx = v.ss;
tr[x].res = 0;
tr[x].active = 1;
}
}
void propagate(int x, int lx, int rx) {
ll v = lz[x].a;
if(!v) return;
tr[x].mn += v;
tr[x].mx += v;
if(rx-lx > 1){
lz[2*x+1].a += v;
lz[2*x+2].a += v;
}
lz[x] = l_neutral;
}
/*=======================================================*/
int siz = 1;
vector<data> tr;
vector<lazy> lz;
lazysegtree() {
}
lazysegtree(int n) {
while (siz < n) siz *= 2;
tr.assign(2 * siz, d_neutral);
lz.assign(2 * siz, l_neutral);
}
void build(vector<T> &a, int n, int x, int lx, int rx) {
if (rx - lx == 1) {
if (lx < n) {
create(x, lx, rx, a[lx]);
}
return;
}
int mid = (lx + rx) / 2;
build(a, n, 2 * x + 1, lx, mid);
build(a, n, 2 * x + 2, mid, rx);
merge(tr[x], tr[2 * x + 1], tr[2 * x + 2]);
}
void build(vector<T> &a, int n) {
build(a, n, 0, 0, siz);
}
void rupd(int l, int r, T v, int x, int lx, int rx) {
propagate(x, lx, rx);
if (lx >= r or rx <= l) return;
if (lx >= l and rx <= r) {
modify(x, lx, rx, v);
propagate(x, lx, rx);
return;
}
int mid = (lx + rx) / 2;
rupd(l, r, v, 2 * x + 1, lx, mid);
rupd(l, r, v, 2 * x + 2, mid, rx);
merge(tr[x], tr[2 * x + 1], tr[2 * x + 2]);
}
void rupd(int l, int r, T v) {
rupd(l, r + 1, v, 0, 0, siz);
}
data query(int l, int r, int x, int lx, int rx) {
propagate(x, lx, rx);
if (lx >= r or rx <= l) return d_neutral;
if (lx >= l and rx <= r) return tr[x];
int mid = (lx + rx) / 2;
data curr;
data left = query(l, r, 2 * x + 1, lx, mid);
data right = query(l, r, 2 * x + 2, mid, rx);
merge(curr, left, right);
return curr;
}
data query(int l, int r) {
return query(l, r + 1, 0, 0, siz);
}
};
void solve(int test_case)
{
ll n,m,d; cin >> n >> m >> d;
d *= 2;
vector<ll> a(n+5), b(m+5);
rep1(i,n) cin >> a[i], a[i] *= 2;
rep1(i,m) cin >> b[i], b[i] *= 2;
vector<ll> c;
rep1(i,n) c.pb(a[i]);
rep1(i,m) c.pb(b[i]);
c.pb(0);
sort(all(c));
ll siz = sz(c)-1;
map<ll,ll> mp;
rep1(i,siz){
if(c[i] != c[i-1]){
mp[c[i]] = i;
}
}
lazysegtree<pll> st(siz+5);
auto upd = [&](ll x){
ll i = mp[x]++;
st.rupd(i+1,siz,{1,-d});
ll active = st.query(1,i-1).active;
st.rupd(i,i,{2,x-d*(active+1)});
};
rep1(i,n){
upd(a[i]);
}
rep1(i,m){
upd(b[i]);
ll ans = st.query(1,siz).res;
ans /= 2;
cout << ans/2;
if(ans&1) cout << ".5";
cout << " ";
}
cout << endl;
}
int main()
{
fastio;
int t = 1;
// cin >> t;
rep1(i, t) {
solve(i);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
656 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
656 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
493 ms |
36648 KB |
Output is correct |
10 |
Correct |
472 ms |
38696 KB |
Output is correct |
11 |
Correct |
245 ms |
26132 KB |
Output is correct |
12 |
Correct |
341 ms |
38764 KB |
Output is correct |
13 |
Correct |
309 ms |
38124 KB |
Output is correct |
14 |
Correct |
316 ms |
38360 KB |
Output is correct |
15 |
Correct |
480 ms |
37832 KB |
Output is correct |
16 |
Correct |
316 ms |
38348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
411 ms |
37580 KB |
Output is correct |
2 |
Correct |
422 ms |
39312 KB |
Output is correct |
3 |
Correct |
342 ms |
27084 KB |
Output is correct |
4 |
Correct |
410 ms |
37324 KB |
Output is correct |
5 |
Correct |
409 ms |
38608 KB |
Output is correct |
6 |
Correct |
424 ms |
37760 KB |
Output is correct |
7 |
Correct |
423 ms |
38964 KB |
Output is correct |
8 |
Correct |
423 ms |
37476 KB |
Output is correct |
9 |
Correct |
454 ms |
37252 KB |
Output is correct |
10 |
Correct |
422 ms |
39764 KB |
Output is correct |
11 |
Correct |
439 ms |
37984 KB |
Output is correct |
12 |
Correct |
438 ms |
38960 KB |
Output is correct |
13 |
Correct |
446 ms |
37324 KB |
Output is correct |
14 |
Correct |
414 ms |
39228 KB |
Output is correct |
15 |
Correct |
432 ms |
39060 KB |
Output is correct |
16 |
Correct |
421 ms |
37320 KB |
Output is correct |
17 |
Correct |
418 ms |
38780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
411 ms |
37580 KB |
Output is correct |
2 |
Correct |
422 ms |
39312 KB |
Output is correct |
3 |
Correct |
342 ms |
27084 KB |
Output is correct |
4 |
Correct |
410 ms |
37324 KB |
Output is correct |
5 |
Correct |
409 ms |
38608 KB |
Output is correct |
6 |
Correct |
424 ms |
37760 KB |
Output is correct |
7 |
Correct |
423 ms |
38964 KB |
Output is correct |
8 |
Correct |
423 ms |
37476 KB |
Output is correct |
9 |
Correct |
454 ms |
37252 KB |
Output is correct |
10 |
Correct |
422 ms |
39764 KB |
Output is correct |
11 |
Correct |
439 ms |
37984 KB |
Output is correct |
12 |
Correct |
438 ms |
38960 KB |
Output is correct |
13 |
Correct |
446 ms |
37324 KB |
Output is correct |
14 |
Correct |
414 ms |
39228 KB |
Output is correct |
15 |
Correct |
432 ms |
39060 KB |
Output is correct |
16 |
Correct |
421 ms |
37320 KB |
Output is correct |
17 |
Correct |
418 ms |
38780 KB |
Output is correct |
18 |
Correct |
605 ms |
37716 KB |
Output is correct |
19 |
Correct |
613 ms |
39876 KB |
Output is correct |
20 |
Correct |
361 ms |
26980 KB |
Output is correct |
21 |
Correct |
448 ms |
37916 KB |
Output is correct |
22 |
Correct |
500 ms |
37832 KB |
Output is correct |
23 |
Correct |
418 ms |
37472 KB |
Output is correct |
24 |
Correct |
604 ms |
38360 KB |
Output is correct |
25 |
Correct |
409 ms |
37324 KB |
Output is correct |
26 |
Correct |
596 ms |
37284 KB |
Output is correct |
27 |
Correct |
620 ms |
39880 KB |
Output is correct |
28 |
Correct |
542 ms |
38036 KB |
Output is correct |
29 |
Correct |
568 ms |
39632 KB |
Output is correct |
30 |
Correct |
440 ms |
37164 KB |
Output is correct |
31 |
Correct |
464 ms |
39332 KB |
Output is correct |
32 |
Correct |
426 ms |
39112 KB |
Output is correct |
33 |
Correct |
591 ms |
37212 KB |
Output is correct |
34 |
Correct |
439 ms |
38780 KB |
Output is correct |