Submission #203198

# Submission time Handle Problem Language Result Execution time Memory
203198 2020-02-19T19:15:02 Z jovan_b Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
237 ms 9592 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

pair <int, int> a[200005];
int b[200005];
int res[200005];
struct str{
    int val, lazy;
} seg[1000005];

void propagate(int node, int l, int r){
    seg[node].val = max(seg[node].val, seg[node].lazy);
    if(l == r) return;
    seg[node*2].lazy = max(seg[node*2].lazy, seg[node].lazy);
    seg[node*2+1].lazy = max(seg[node*2+1].lazy, seg[node].lazy);
}

void upd(int node, int l, int r, int tl, int tr, int val){
    propagate(node, l, r);
    if(tl > r || l > tr) return;
    if(tl <= l && r <= tr){
        seg[node].lazy = max(seg[node].lazy, val);
        propagate(node, l, r);
        return;
    }
    int mid = (l+r)/2;
    upd(node*2, l, mid, tl, tr, val);
    upd(node*2+1, mid+1, r, tl, tr, val);
}

int getval(int node, int l, int r, int x){
    propagate(node, l, r);
    if(l == r) return seg[node].val;
    int mid = (l+r)/2;
    if(x <= mid) return getval(node*2, l, mid, x);
    return getval(node*2+1, mid+1, r, x);
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	int n;
	cin >> n;
	for(int i=1; i<=n+1; i++){
        cin >> a[i].first;
        a[i].second = i;
	}
	for(int i=1; i<=n; i++) cin >> b[i];
	sort(a+1, a+1+n+1);
	sort(b+1, b+1+n);
	for(int i=1; i<=n; i++){\
        upd(1, 1, n+1, 1, i, max(0, a[i+1].first-b[i]));
        upd(1, 1, n+1, i+1, n+1, max(0, a[i].first-b[i]));
	}
	for(int i=1; i<=n+1; i++){
        res[a[i].second] = getval(1, 1, n+1, i);
	}
	for(int i=1; i<=n+1; i++) cout << res[i] << " ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 7 ms 508 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 7 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 8 ms 376 KB Output is correct
32 Correct 6 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 7 ms 508 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 7 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 8 ms 376 KB Output is correct
32 Correct 6 ms 536 KB Output is correct
33 Correct 230 ms 8928 KB Output is correct
34 Correct 233 ms 9208 KB Output is correct
35 Correct 231 ms 8952 KB Output is correct
36 Correct 230 ms 9464 KB Output is correct
37 Correct 237 ms 9576 KB Output is correct
38 Correct 233 ms 9592 KB Output is correct
39 Correct 233 ms 8824 KB Output is correct
40 Correct 231 ms 8672 KB Output is correct
41 Correct 234 ms 8696 KB Output is correct
42 Correct 223 ms 8696 KB Output is correct
43 Correct 230 ms 8696 KB Output is correct
44 Correct 222 ms 8312 KB Output is correct
45 Correct 226 ms 8440 KB Output is correct
46 Correct 224 ms 8384 KB Output is correct
47 Correct 228 ms 8184 KB Output is correct
48 Correct 219 ms 8180 KB Output is correct
49 Correct 233 ms 8824 KB Output is correct
50 Correct 236 ms 8824 KB Output is correct
51 Correct 236 ms 8824 KB Output is correct
52 Correct 227 ms 8824 KB Output is correct
53 Correct 236 ms 8748 KB Output is correct