Submission #566966

# Submission time Handle Problem Language Result Execution time Memory
566966 2022-05-23T06:55:21 Z RealSnake Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
210 ms 9200 KB
#include "bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define mod 1000000007

ofstream fout(".out");
ifstream fin(".in");

int N, Left, Right;
int seg1[600000], seg2[600000];

int get_max1(int l = 1, int r = N, int ind = 1) {
    if(l > Right || r < Left)
        return 0;
    if(l >= Left && r <= Right)
        return seg1[ind];
    int mid = (l + r) / 2;
    return max(get_max1(l, mid, ind * 2), get_max1(mid + 1, r, ind * 2 + 1));
}

int get_max2(int l = 1, int r = N, int ind = 1) {
    if(l > Right || r < Left)
        return 0;
    if(l >= Left && r <= Right)
        return seg2[ind];
    int mid = (l + r) / 2;
    return max(get_max2(l, mid, ind * 2), get_max2(mid + 1, r, ind * 2 + 1));
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    N = exp2(ceil(log2(n)));
    int b[n];
    vector<pair<int, int>> a;
    for(int i = 0; i < n + 1; i++) {
        int x;
        cin >> x;
        a.push_back({x, i});
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++)
        cin >> b[i];
    sort(b, b + n);
    for(int i = 0; i < n; i++) {
        seg1[i + N] = max(0, a[i].first - b[i]);
        seg2[i + N] = max(0, a[i + 1].first - b[i]);
    }
    for(int i = N - 1; i >= 1; i--) {
        seg1[i] = max(seg1[i * 2], seg1[i * 2 + 1]);
        seg2[i] = max(seg2[i * 2], seg2[i * 2 + 1]);
    }
    int ans[n + 1] = {};
    for(int i = 0; i < n + 1; i++) {
        if(i) {
            Left = 1, Right = i;
            ans[a[i].second] = max(ans[a[i].second], get_max1());
        }
        Left = i + 1, Right = n;
        ans[a[i].second] = max(ans[a[i].second], get_max2());
    }
    for(int i = 0; i < n + 1; i++)
        cout << ans[i] << " ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 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 1 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 2 ms 400 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 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 1 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 2 ms 400 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 161 ms 8412 KB Output is correct
34 Correct 151 ms 8716 KB Output is correct
35 Correct 166 ms 8512 KB Output is correct
36 Correct 144 ms 8972 KB Output is correct
37 Correct 151 ms 9200 KB Output is correct
38 Correct 210 ms 9040 KB Output is correct
39 Correct 144 ms 8124 KB Output is correct
40 Correct 145 ms 8104 KB Output is correct
41 Correct 209 ms 8268 KB Output is correct
42 Correct 157 ms 8240 KB Output is correct
43 Correct 149 ms 8088 KB Output is correct
44 Correct 158 ms 7812 KB Output is correct
45 Correct 143 ms 7916 KB Output is correct
46 Correct 138 ms 7808 KB Output is correct
47 Correct 134 ms 7748 KB Output is correct
48 Correct 148 ms 7672 KB Output is correct
49 Correct 153 ms 8320 KB Output is correct
50 Correct 162 ms 8312 KB Output is correct
51 Correct 159 ms 8360 KB Output is correct
52 Correct 158 ms 8408 KB Output is correct
53 Correct 153 ms 8328 KB Output is correct