Submission #927222

# Submission time Handle Problem Language Result Execution time Memory
927222 2024-02-14T12:47:54 Z Craftless Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
195 ms 84964 KB
#include <bits/stdc++.h>

#define int long long int
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define INF 1e13

using namespace std;

int N, A[200010], B[200010], ans[200010];
pi as[200010];


struct node {
    int s, e, m, val;
    node *l, *r;
    node (int _s, int _e) {
        s = _s; e = _e;
        m = (s + e) / 2;
        val = 0;
        if (s != e) {
            l = new node(s, m);
            r = new node(m + 1, e);
        }
    }
    
    int query(int _s, int _e) {
        if (s == _s and e == _e) {
            return val;
        }
        else if (_e <= m) {
            return l -> query(_s, _e);
        }
        else if (_s > m) {
            return r-> query(_s, _e);
        }
        else {
            return max(l -> query(_s, m), r -> query(m + 1, _e));
        }
    }
    
    void update(int p, int v) {
        if (s == p and e == p) {
            val = v;
        }
        else {
            if (p <= m) l -> update(p, v);
            else r -> update(p, v);
            val = max(l -> val, r -> val);
        }
        
    }

    void children() {
        if (s != e) {
            l = new node(s, m);
            r = new node(m + 1, e);
        }
    }

} *l, *r, *m;


int32_t main() {

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> N;

	for (int i = 0; i < N + 1; i++) {
		cin >> A[i];
		as[i] = { A[i], i };
	}

	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	l = new node(0, N - 1);
	m = new node(0, N - 1);
	r = new node(0, N - 1);

	sort(A, A + N + 1);
	sort(as, as + N + 1);
	sort(B, B + N);

	for (int i = 0; i < N; i++) {
		m -> update(i, max(A[i] - B[i], 0ll));
		r -> update(i, max(A[i + 1] - B[i], 0ll));
	}

	for (int i = 0; i < N + 1; i++) {
		int a = -INF, b = -INF;
		if (i - 1 >= 0) a = m -> query(0, i - 1);
		if (i <= N - 1) b = r -> query(i, N - 1);
		ans[as[i].S] = max(a, b);
	}

	for (int i = 0; i < N + 1; i++) {
		cout << ans[i] << " ";
	}





	return 0;	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5180 KB Output is correct
21 Correct 2 ms 5208 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 5212 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5180 KB Output is correct
21 Correct 2 ms 5208 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 171 ms 81080 KB Output is correct
34 Correct 179 ms 84336 KB Output is correct
35 Correct 173 ms 81772 KB Output is correct
36 Correct 178 ms 82516 KB Output is correct
37 Correct 195 ms 84964 KB Output is correct
38 Correct 182 ms 84048 KB Output is correct
39 Correct 189 ms 82312 KB Output is correct
40 Correct 183 ms 81972 KB Output is correct
41 Correct 178 ms 82716 KB Output is correct
42 Correct 183 ms 82560 KB Output is correct
43 Correct 181 ms 82124 KB Output is correct
44 Correct 173 ms 80520 KB Output is correct
45 Correct 181 ms 81236 KB Output is correct
46 Correct 177 ms 80724 KB Output is correct
47 Correct 170 ms 83920 KB Output is correct
48 Correct 171 ms 83916 KB Output is correct
49 Correct 189 ms 84544 KB Output is correct
50 Correct 183 ms 84584 KB Output is correct
51 Correct 191 ms 84448 KB Output is correct
52 Correct 180 ms 84556 KB Output is correct
53 Correct 183 ms 84560 KB Output is correct