// #cheat_when_I_was_young
// #cheatkhitacontre #khionhatoicheat
// #thaycuckythatvong
#include "bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
const int NM = 2e5 + 5;
int n, a[NM], b[NM], tmp1[NM], tmp2[NM], tree1[NM<<2], tree2[NM<<2], ans[NM];
pair<int,int> c[NM];
void build(int *tree, int *arr, int id = 1, int l = 1, int r = n) {
if (l == r) {
tree[id] = arr[l];
return;
}
int mid = (l+r) >> 1;
build(tree, arr, id<<1, l, mid);
build(tree, arr, id<<1|1, mid+1, r);
tree[id] = max(tree[id<<1], tree[id<<1|1]);
}
int get(int *tree, int u, int v, int id = 1, int l = 1, int r = n) {
if (v < l || r < u) return 0;
if (u <= l && r <= v) return tree[id];
int mid = (l+r) >> 1;
return max(get(tree, u, v, id<<1, l, mid), get(tree, u, v, id<<1|1, mid+1, r));
}
signed main() {
IOS;
cin >> n;
for (int i = 1; i <= n+1; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
for (int i = 1; i <= n+1; ++i) c[i] = {a[i], i};
sort(a+1, a+n+2);
sort(b+1, b+n+1);
sort(c+1, c+n+2);
for (int i = 1; i <= n; ++i) {
tmp1[i] = max(a[i] - b[i], 0);
tmp2[i] = max(a[i+1] - b[i], 0);
}
build(tree1, tmp1);
build(tree2, tmp2);
for (int i = 1; i <= n+1; ++i) {
int x = c[i].second;
if (i == 1) ans[x] = get(tree2, 1, n);
else if (i == n+1) ans[x] = get(tree1, 1, n);
else ans[x] = max(get(tree1, 1, i-1), get(tree2, i, n));
}
for (int i = 1; i <= n+1; ++i) cout << ans[i] << " \n"[i == n+1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
123 ms |
11112 KB |
Output is correct |
34 |
Correct |
128 ms |
11452 KB |
Output is correct |
35 |
Correct |
133 ms |
11252 KB |
Output is correct |
36 |
Correct |
125 ms |
11676 KB |
Output is correct |
37 |
Correct |
129 ms |
11888 KB |
Output is correct |
38 |
Correct |
129 ms |
11756 KB |
Output is correct |
39 |
Correct |
125 ms |
10916 KB |
Output is correct |
40 |
Correct |
125 ms |
10784 KB |
Output is correct |
41 |
Correct |
127 ms |
10940 KB |
Output is correct |
42 |
Correct |
126 ms |
10908 KB |
Output is correct |
43 |
Correct |
125 ms |
10828 KB |
Output is correct |
44 |
Correct |
125 ms |
10468 KB |
Output is correct |
45 |
Correct |
123 ms |
10572 KB |
Output is correct |
46 |
Correct |
126 ms |
10536 KB |
Output is correct |
47 |
Correct |
129 ms |
10444 KB |
Output is correct |
48 |
Correct |
119 ms |
10456 KB |
Output is correct |
49 |
Correct |
128 ms |
10992 KB |
Output is correct |
50 |
Correct |
130 ms |
11012 KB |
Output is correct |
51 |
Correct |
130 ms |
11084 KB |
Output is correct |
52 |
Correct |
129 ms |
11048 KB |
Output is correct |
53 |
Correct |
130 ms |
10992 KB |
Output is correct |