답안 #452116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
452116 2021-08-03T19:36:50 Z JovanB Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
238 ms 13332 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 372 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 372 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 222 ms 12564 KB Output is correct
34 Correct 236 ms 12876 KB Output is correct
35 Correct 224 ms 12556 KB Output is correct
36 Correct 228 ms 13040 KB Output is correct
37 Correct 234 ms 13332 KB Output is correct
38 Correct 231 ms 13256 KB Output is correct
39 Correct 227 ms 12260 KB Output is correct
40 Correct 224 ms 12256 KB Output is correct
41 Correct 228 ms 12356 KB Output is correct
42 Correct 225 ms 12356 KB Output is correct
43 Correct 222 ms 12340 KB Output is correct
44 Correct 222 ms 11972 KB Output is correct
45 Correct 223 ms 11968 KB Output is correct
46 Correct 221 ms 11952 KB Output is correct
47 Correct 221 ms 11968 KB Output is correct
48 Correct 223 ms 12068 KB Output is correct
49 Correct 238 ms 12484 KB Output is correct
50 Correct 232 ms 12468 KB Output is correct
51 Correct 233 ms 12532 KB Output is correct
52 Correct 231 ms 12540 KB Output is correct
53 Correct 232 ms 12560 KB Output is correct