#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
int n;
int b[N], odd[N], ans[N];
vector<pair<int, int>> a;
void read() {
cin >> n;
for(int i = 0; i <= n; i++) {
int x; cin >> x;
a.push_back({x, i});
}
sort(a.begin(), a.end());
for(int i = 0; i < n; i++)
cin >> b[i];
sort(b, b+n);
}
//segment tree
int st[4*N];
void update(int idx, int l, int r, int x, int val) {
if(r < x || x < l) return;
if(l == r && l == x) {
st[idx] = val;
return;
}
int lc = idx<<1, rc = lc|1;
update(lc, l, (l+r)/2, x, val);
update(rc, (l+r)/2+1, r, x, val);
st[idx] = max(st[lc], st[rc]);
}
int query(int idx, int l, int r, int x, int y) {
if(r < x || y < l) return 0;
else if(x <= l && r <= y) return st[idx];
int lc = idx<<1, rc = lc|1;
int lq = query(lc, l, (l+r)/2, x, y);
int rq = query(rc, (l+r)/2+1, r, x, y);
return max(lq, rq);
}
void solve() {
memset(st, 0, sizeof st);
for(int i = 0; i < n; i++)
update(1, 0, n-1, i, max(0, a[i+1].first - b[i]));
for(int i = 0; i < n; i++) {
ans[a[i].second] = query(1, 0, n-1, 0, n-1);
update(1, 0, n-1, i, max(0, a[i].first - b[i]));
}
ans[a[n].second] = query(1, 0, n-1, 0, n-1);
for(int i = 0; i < n+1; i++)
cout << ans[i] << " \n"[i==n];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
7 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3456 KB |
Output is correct |
4 |
Correct |
6 ms |
3456 KB |
Output is correct |
5 |
Correct |
7 ms |
3456 KB |
Output is correct |
6 |
Correct |
7 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
7 ms |
3456 KB |
Output is correct |
9 |
Correct |
7 ms |
3456 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
6 ms |
3456 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
7 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3456 KB |
Output is correct |
4 |
Correct |
6 ms |
3456 KB |
Output is correct |
5 |
Correct |
7 ms |
3456 KB |
Output is correct |
6 |
Correct |
7 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
7 ms |
3456 KB |
Output is correct |
9 |
Correct |
7 ms |
3456 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
6 ms |
3456 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
13 |
Correct |
9 ms |
3456 KB |
Output is correct |
14 |
Correct |
7 ms |
3584 KB |
Output is correct |
15 |
Correct |
12 ms |
3584 KB |
Output is correct |
16 |
Correct |
9 ms |
3456 KB |
Output is correct |
17 |
Correct |
7 ms |
3584 KB |
Output is correct |
18 |
Correct |
7 ms |
3584 KB |
Output is correct |
19 |
Correct |
10 ms |
3584 KB |
Output is correct |
20 |
Correct |
7 ms |
3584 KB |
Output is correct |
21 |
Correct |
7 ms |
3584 KB |
Output is correct |
22 |
Correct |
7 ms |
3584 KB |
Output is correct |
23 |
Correct |
7 ms |
3584 KB |
Output is correct |
24 |
Correct |
7 ms |
3584 KB |
Output is correct |
25 |
Correct |
7 ms |
3584 KB |
Output is correct |
26 |
Correct |
7 ms |
3584 KB |
Output is correct |
27 |
Correct |
7 ms |
3712 KB |
Output is correct |
28 |
Correct |
9 ms |
3584 KB |
Output is correct |
29 |
Correct |
7 ms |
3584 KB |
Output is correct |
30 |
Correct |
8 ms |
3584 KB |
Output is correct |
31 |
Correct |
8 ms |
3584 KB |
Output is correct |
32 |
Correct |
7 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
7 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3456 KB |
Output is correct |
4 |
Correct |
6 ms |
3456 KB |
Output is correct |
5 |
Correct |
7 ms |
3456 KB |
Output is correct |
6 |
Correct |
7 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
7 ms |
3456 KB |
Output is correct |
9 |
Correct |
7 ms |
3456 KB |
Output is correct |
10 |
Correct |
8 ms |
3456 KB |
Output is correct |
11 |
Correct |
6 ms |
3456 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
13 |
Correct |
9 ms |
3456 KB |
Output is correct |
14 |
Correct |
7 ms |
3584 KB |
Output is correct |
15 |
Correct |
12 ms |
3584 KB |
Output is correct |
16 |
Correct |
9 ms |
3456 KB |
Output is correct |
17 |
Correct |
7 ms |
3584 KB |
Output is correct |
18 |
Correct |
7 ms |
3584 KB |
Output is correct |
19 |
Correct |
10 ms |
3584 KB |
Output is correct |
20 |
Correct |
7 ms |
3584 KB |
Output is correct |
21 |
Correct |
7 ms |
3584 KB |
Output is correct |
22 |
Correct |
7 ms |
3584 KB |
Output is correct |
23 |
Correct |
7 ms |
3584 KB |
Output is correct |
24 |
Correct |
7 ms |
3584 KB |
Output is correct |
25 |
Correct |
7 ms |
3584 KB |
Output is correct |
26 |
Correct |
7 ms |
3584 KB |
Output is correct |
27 |
Correct |
7 ms |
3712 KB |
Output is correct |
28 |
Correct |
9 ms |
3584 KB |
Output is correct |
29 |
Correct |
7 ms |
3584 KB |
Output is correct |
30 |
Correct |
8 ms |
3584 KB |
Output is correct |
31 |
Correct |
8 ms |
3584 KB |
Output is correct |
32 |
Correct |
7 ms |
3584 KB |
Output is correct |
33 |
Correct |
185 ms |
8088 KB |
Output is correct |
34 |
Correct |
208 ms |
8316 KB |
Output is correct |
35 |
Correct |
196 ms |
8168 KB |
Output is correct |
36 |
Correct |
189 ms |
8680 KB |
Output is correct |
37 |
Correct |
189 ms |
8804 KB |
Output is correct |
38 |
Correct |
195 ms |
8808 KB |
Output is correct |
39 |
Correct |
180 ms |
7856 KB |
Output is correct |
40 |
Correct |
181 ms |
7788 KB |
Output is correct |
41 |
Correct |
178 ms |
7784 KB |
Output is correct |
42 |
Correct |
180 ms |
7784 KB |
Output is correct |
43 |
Correct |
201 ms |
7892 KB |
Output is correct |
44 |
Correct |
195 ms |
7528 KB |
Output is correct |
45 |
Correct |
173 ms |
7568 KB |
Output is correct |
46 |
Correct |
216 ms |
7672 KB |
Output is correct |
47 |
Correct |
174 ms |
7304 KB |
Output is correct |
48 |
Correct |
181 ms |
7272 KB |
Output is correct |
49 |
Correct |
196 ms |
7888 KB |
Output is correct |
50 |
Correct |
189 ms |
7884 KB |
Output is correct |
51 |
Correct |
189 ms |
7912 KB |
Output is correct |
52 |
Correct |
188 ms |
8084 KB |
Output is correct |
53 |
Correct |
180 ms |
7912 KB |
Output is correct |