/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
struct node {
ll mnl, mxr, res, lazy, num;
node() {
res = lazy = num = 0;
mxr = (ll)-1e18;
mnl = (ll)1e18;
}
} seg[2*N];
ll n, m, d, a[N], b[N];
vector<pll> comp;
int get(ll x, ll y) {
int ptr = lower_bound(all(comp), Mp(x, y)) - comp.begin() + 1;
return ptr;
}
void pushdown(int ind) {
seg[ind].num += seg[ind].lazy;
seg[ind].mxr += (d*seg[ind].lazy);
seg[ind].mnl += (d*seg[ind].lazy);
(ind < (1<<lg)) && (seg[2*ind].lazy += seg[ind].lazy);
(ind < (1<<lg)) && (seg[2*ind+1].lazy += seg[ind].lazy);
seg[ind].lazy = 0;
}
void pushup(int ind) {
seg[ind].res = max({seg[2*ind].res, seg[2*ind+1].res, seg[2*ind+1].mxr - seg[2*ind].mnl});
seg[ind].mxr = max(seg[2*ind].mxr, seg[2*ind+1].mxr);
seg[ind].mnl = min(seg[2*ind].mnl, seg[2*ind+1].mnl);
}
void update1(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(l>=rc || lc>=r) return;
if(lc>=l && rc<=r) {
seg[ind].lazy ++;
pushdown(ind);
return;
}
int mid = (lc+rc)/2;
update1(l, r, 2*ind, lc, mid);
update1(l, r, 2*ind+1, mid, rc);
pushup(ind);
}
void update2(ll pos, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(ind >= (1<<lg)) {
seg[ind].mnl = seg[ind].mxr = seg[ind].num*d - comp[pos-1].F;
return;
}
int mid=(lc+rc)/2;
if(pos<mid) {update2(pos, 2*ind, lc, mid); pushdown(2*ind+1);}
else {update2(pos, 2*ind+1, mid, rc); pushdown(2*ind);}
pushup(ind);
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m>>d;
for(int i=1; i<=n+m; i++) cin>>a[i], comp.pb({a[i], i});
sort(all(comp));
for(int i=1; i<=n+m; i++) {
int ptr = get(a[i], i);
update1(ptr, n+m+1);
update2(ptr);
ll ans = max(seg[1].res, 0ll);
if(i>n) {
cout<<ans/2;
if(ans%2==1) cout<<".5 ";
else cout<<" ";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
26460 KB |
Output is correct |
2 |
Correct |
6 ms |
26296 KB |
Output is correct |
3 |
Correct |
7 ms |
26460 KB |
Output is correct |
4 |
Correct |
6 ms |
26500 KB |
Output is correct |
5 |
Correct |
6 ms |
26460 KB |
Output is correct |
6 |
Correct |
6 ms |
26460 KB |
Output is correct |
7 |
Correct |
6 ms |
26460 KB |
Output is correct |
8 |
Correct |
6 ms |
26460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
26460 KB |
Output is correct |
2 |
Correct |
6 ms |
26296 KB |
Output is correct |
3 |
Correct |
7 ms |
26460 KB |
Output is correct |
4 |
Correct |
6 ms |
26500 KB |
Output is correct |
5 |
Correct |
6 ms |
26460 KB |
Output is correct |
6 |
Correct |
6 ms |
26460 KB |
Output is correct |
7 |
Correct |
6 ms |
26460 KB |
Output is correct |
8 |
Correct |
6 ms |
26460 KB |
Output is correct |
9 |
Correct |
254 ms |
33740 KB |
Output is correct |
10 |
Correct |
239 ms |
32968 KB |
Output is correct |
11 |
Correct |
175 ms |
33488 KB |
Output is correct |
12 |
Correct |
217 ms |
33488 KB |
Output is correct |
13 |
Correct |
169 ms |
33776 KB |
Output is correct |
14 |
Correct |
179 ms |
32964 KB |
Output is correct |
15 |
Correct |
265 ms |
32464 KB |
Output is correct |
16 |
Correct |
171 ms |
31948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
33236 KB |
Output is correct |
2 |
Correct |
184 ms |
34800 KB |
Output is correct |
3 |
Correct |
192 ms |
35148 KB |
Output is correct |
4 |
Correct |
168 ms |
33764 KB |
Output is correct |
5 |
Correct |
182 ms |
34500 KB |
Output is correct |
6 |
Correct |
169 ms |
32716 KB |
Output is correct |
7 |
Correct |
190 ms |
34496 KB |
Output is correct |
8 |
Correct |
169 ms |
32464 KB |
Output is correct |
9 |
Correct |
169 ms |
32724 KB |
Output is correct |
10 |
Correct |
182 ms |
35468 KB |
Output is correct |
11 |
Correct |
171 ms |
33688 KB |
Output is correct |
12 |
Correct |
173 ms |
34064 KB |
Output is correct |
13 |
Correct |
173 ms |
32248 KB |
Output is correct |
14 |
Correct |
175 ms |
34328 KB |
Output is correct |
15 |
Correct |
174 ms |
33992 KB |
Output is correct |
16 |
Correct |
170 ms |
31912 KB |
Output is correct |
17 |
Correct |
172 ms |
33660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
33236 KB |
Output is correct |
2 |
Correct |
184 ms |
34800 KB |
Output is correct |
3 |
Correct |
192 ms |
35148 KB |
Output is correct |
4 |
Correct |
168 ms |
33764 KB |
Output is correct |
5 |
Correct |
182 ms |
34500 KB |
Output is correct |
6 |
Correct |
169 ms |
32716 KB |
Output is correct |
7 |
Correct |
190 ms |
34496 KB |
Output is correct |
8 |
Correct |
169 ms |
32464 KB |
Output is correct |
9 |
Correct |
169 ms |
32724 KB |
Output is correct |
10 |
Correct |
182 ms |
35468 KB |
Output is correct |
11 |
Correct |
171 ms |
33688 KB |
Output is correct |
12 |
Correct |
173 ms |
34064 KB |
Output is correct |
13 |
Correct |
173 ms |
32248 KB |
Output is correct |
14 |
Correct |
175 ms |
34328 KB |
Output is correct |
15 |
Correct |
174 ms |
33992 KB |
Output is correct |
16 |
Correct |
170 ms |
31912 KB |
Output is correct |
17 |
Correct |
172 ms |
33660 KB |
Output is correct |
18 |
Correct |
262 ms |
33748 KB |
Output is correct |
19 |
Correct |
269 ms |
34240 KB |
Output is correct |
20 |
Correct |
175 ms |
34496 KB |
Output is correct |
21 |
Correct |
251 ms |
33136 KB |
Output is correct |
22 |
Correct |
214 ms |
32820 KB |
Output is correct |
23 |
Correct |
181 ms |
32980 KB |
Output is correct |
24 |
Correct |
257 ms |
33180 KB |
Output is correct |
25 |
Correct |
185 ms |
33236 KB |
Output is correct |
26 |
Correct |
261 ms |
32980 KB |
Output is correct |
27 |
Correct |
260 ms |
35196 KB |
Output is correct |
28 |
Correct |
227 ms |
33992 KB |
Output is correct |
29 |
Correct |
223 ms |
34456 KB |
Output is correct |
30 |
Correct |
198 ms |
32980 KB |
Output is correct |
31 |
Correct |
203 ms |
34964 KB |
Output is correct |
32 |
Correct |
185 ms |
34492 KB |
Output is correct |
33 |
Correct |
255 ms |
31956 KB |
Output is correct |
34 |
Correct |
204 ms |
34500 KB |
Output is correct |