답안 #209179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209179 2020-03-13T10:31:11 Z Autoratch Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
287 ms 20920 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1 << 18;

int n;
int a[N],b[N],p[N];
struct node
{
    long long a,b;
    friend node operator+(const node &a,const node &b){ return {max(a.a,b.a),max(a.b,b.b)}; }
}tree[N << 1];
unordered_map<int,long long> ans;

void build(int l,int r,int idx)
{
    if(l==r) return void(tree[idx] = {a[l]-b[l],a[l+1]-b[l]});
    int m = (l+r)/2;
    build(l,m,idx*2),build(m+1,r,idx*2+1);
    tree[idx] = tree[idx*2]+tree[idx*2+1];
}

node read(int l,int r,int idx,int x,int y)
{
    if(x>r or y<l) return {0,0};
    if(x<=l and y>=r) return tree[idx];
    int m = (l+r)/2;
    return read(l,m,idx*2,x,y)+read(m+1,r,idx*2+1,x,y);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n;
    for(int i = 1;i <= n+1;i++) cin >> a[i],p[i] = a[i];
    for(int i = 1;i <= n;i++) cin >> b[i];
    sort(a+1,a+n+2),sort(b+1,b+n+1);
    build(1,n,1);
    for(int i = 1;i <= n+1;i++) 
    {
        long long l = 0,r = 0;
        if(i>1) l = read(1,n,1,1,i-1).a;
        if(i<=n) r = read(1,n,1,i,n).b;
        ans[a[i]] = max(l,r);
    }
    for(int i = 1;i <= n+1;i++) cout << ans[p[i]] << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 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 380 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
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 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 380 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 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 636 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 632 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 7 ms 792 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 7 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 8 ms 504 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 7 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 8 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 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 380 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 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 636 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 632 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 7 ms 792 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 7 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 8 ms 504 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 7 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 8 ms 504 KB Output is correct
33 Correct 278 ms 19988 KB Output is correct
34 Correct 262 ms 20536 KB Output is correct
35 Correct 263 ms 20152 KB Output is correct
36 Correct 270 ms 20664 KB Output is correct
37 Correct 287 ms 20920 KB Output is correct
38 Correct 277 ms 20792 KB Output is correct
39 Correct 273 ms 19768 KB Output is correct
40 Correct 269 ms 19768 KB Output is correct
41 Correct 255 ms 19896 KB Output is correct
42 Correct 271 ms 19900 KB Output is correct
43 Correct 253 ms 19896 KB Output is correct
44 Correct 268 ms 19384 KB Output is correct
45 Correct 265 ms 19516 KB Output is correct
46 Correct 255 ms 19540 KB Output is correct
47 Correct 167 ms 13096 KB Output is correct
48 Correct 171 ms 13096 KB Output is correct
49 Correct 262 ms 20156 KB Output is correct
50 Correct 274 ms 20156 KB Output is correct
51 Correct 268 ms 20152 KB Output is correct
52 Correct 285 ms 20152 KB Output is correct
53 Correct 279 ms 20188 KB Output is correct