#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define si second
#define ll long long
#define int ll
typedef pair<int,int> pi;
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 69
#endif
template <typename Arg>
void __f(string name, Arg arg) {
cerr << name << " = " << arg << endl;
}
template <typename Head, typename... Tail>
void __f(string names, Head head, Tail... tail) {
string cur = "";
for (auto ch: names){if(ch==','){break;}else{cur+=ch;}}
string nxt = names.substr(cur.size()+2);
cerr << cur << " = " << head << ", ";
__f(nxt, tail...);
}
const int mxn = 200005;
int N, B[mxn], ans[mxn];
pi A[mxn];
struct node {
int s,e,m,v,lazy;
node *l,*r;
node (int _s, int _e) {
s = _s, e = _e, m = (s+e)>>1;
v = 0, lazy = 0;
if (s!=e) {
l = new node(s,m);
r = new node(m+1,e);
}
}
int prop() {
if (s==e) {
v += lazy;
lazy = 0;
return v;
}
v += lazy;
r->lazy += lazy, l->lazy += lazy;
lazy = 0;
return v;
}
void update(int qs, int qe, int nv) {
if (s==qs&&e==qe) lazy += nv;
else {
if (qe<=m) l->update(qs,qe,nv);
else if (qs>m) r->update(qs,qe,nv);
else l->update(qs,m,nv), r->update(m+1,qe,nv);
v = max(l->prop(),r->prop());
}
}
int query(int qs, int qe) {
prop();
if (qs==s&&qe==e) return prop();
if (qs>m) return r->query(qs,qe);
else if (qe<=m) return l->query(qs,qe);
else return max(l->query(qs,m),r->query(m+1,qe));
}
} *st[2];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
for (int i = 1; i <= N + 1; ++i) cin >> A[i].fi, A[i].si = i;
for (int i = 1; i <= N; ++i) cin >> B[i];
sort(A + 1, A + N + 2);
sort(B + 1, B + N + 1);
for (int i = 0; i < 2; ++i) st[i] = new node(1, N);
for (int i = 1; i <= N; ++i) {
st[0]->update(i, i, A[i].fi - B[i]);
st[1]->update(i, i, A[i + 1].fi - B[i]);
}
for (int i = 1; i <= N + 1; ++i) {
int idx = A[i].si, lx = 0, rx = 0;
if (i != 1) lx = st[0]->query(1, i - 1);
if (i != N + 1) rx = st[1]->query(i, N);
ans[idx] = max(lx, rx);
}
for (int i = 1; i <= N + 1; ++i) cout << ans[i] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
760 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
3 ms |
728 KB |
Output is correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
3 ms |
980 KB |
Output is correct |
26 |
Correct |
3 ms |
892 KB |
Output is correct |
27 |
Correct |
3 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
856 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
760 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
3 ms |
728 KB |
Output is correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
3 ms |
980 KB |
Output is correct |
26 |
Correct |
3 ms |
892 KB |
Output is correct |
27 |
Correct |
3 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
856 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
4 ms |
852 KB |
Output is correct |
33 |
Correct |
359 ms |
59100 KB |
Output is correct |
34 |
Correct |
381 ms |
61644 KB |
Output is correct |
35 |
Correct |
351 ms |
59596 KB |
Output is correct |
36 |
Correct |
351 ms |
60536 KB |
Output is correct |
37 |
Correct |
385 ms |
62268 KB |
Output is correct |
38 |
Correct |
382 ms |
61532 KB |
Output is correct |
39 |
Correct |
341 ms |
60036 KB |
Output is correct |
40 |
Correct |
378 ms |
59644 KB |
Output is correct |
41 |
Correct |
372 ms |
60420 KB |
Output is correct |
42 |
Correct |
356 ms |
60236 KB |
Output is correct |
43 |
Correct |
407 ms |
59708 KB |
Output is correct |
44 |
Correct |
341 ms |
58504 KB |
Output is correct |
45 |
Correct |
355 ms |
58968 KB |
Output is correct |
46 |
Correct |
361 ms |
58468 KB |
Output is correct |
47 |
Correct |
344 ms |
61180 KB |
Output is correct |
48 |
Correct |
379 ms |
61200 KB |
Output is correct |
49 |
Correct |
369 ms |
61640 KB |
Output is correct |
50 |
Correct |
357 ms |
61676 KB |
Output is correct |
51 |
Correct |
375 ms |
61676 KB |
Output is correct |
52 |
Correct |
374 ms |
61680 KB |
Output is correct |
53 |
Correct |
354 ms |
61680 KB |
Output is correct |