답안 #762915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762915 2023-06-22T01:23:12 Z cheat_when_I_was_young Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
158 ms 11848 KB
// #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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 2 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 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 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 1 ms 356 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 2 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 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 121 ms 11108 KB Output is correct
34 Correct 129 ms 11408 KB Output is correct
35 Correct 131 ms 11168 KB Output is correct
36 Correct 135 ms 11660 KB Output is correct
37 Correct 130 ms 11848 KB Output is correct
38 Correct 128 ms 11768 KB Output is correct
39 Correct 126 ms 10916 KB Output is correct
40 Correct 135 ms 10888 KB Output is correct
41 Correct 130 ms 10928 KB Output is correct
42 Correct 127 ms 10940 KB Output is correct
43 Correct 127 ms 10900 KB Output is correct
44 Correct 122 ms 10548 KB Output is correct
45 Correct 138 ms 10604 KB Output is correct
46 Correct 130 ms 10548 KB Output is correct
47 Correct 115 ms 10380 KB Output is correct
48 Correct 121 ms 10444 KB Output is correct
49 Correct 129 ms 11052 KB Output is correct
50 Correct 158 ms 11172 KB Output is correct
51 Correct 132 ms 11048 KB Output is correct
52 Correct 135 ms 10988 KB Output is correct
53 Correct 129 ms 10960 KB Output is correct