Submission #890465

# Submission time Handle Problem Language Result Execution time Memory
890465 2023-12-21T09:50:18 Z hafo Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
90 ms 12368 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e18 + 69;

int n, b[maxn], res[maxn];
pa a[maxn];

struct ST {
    struct node {
        int mx;
        friend node operator + (node a, const node &b) {
            maxi(a.mx, b.mx);
            return a;
        }
    };

    node st[4 * maxn];

    void build(int id, int l, int r) {
        if(l == r) {
            st[id].mx = max(0, a[l + 1].fi - b[l]);
            return;
        }
        int mid = l + r >> 1;
        build(id << 1, l, mid);
        build(id << 1 | 1, mid + 1, r);
        st[id] = st[id << 1] + st[id << 1 | 1];
    }

    void update(int id, int l, int r, int pos, int val) {
        if(pos < l || pos > r) return;
        if(l == r) {
            st[id].mx = val;
            return;
        }
        int mid = l + r >> 1;
        update(id << 1, l, mid, pos, val);
        update(id << 1 | 1, mid + 1, r, pos, val);
        st[id] = st[id << 1] + st[id << 1 | 1];
    }


} st;

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

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n;
    for(int i = 1; i <= n + 1; i++) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    for(int i = 1; i <= n; i++) cin>>b[i];

    sort(a + 1, a + 1 + n + 1);
    sort(b + 1, b + 1 + n);

    st.build(1, 1, n);
    res[a[1].se] = st.st[1].mx;
    for(int i = 1; i <= n; i++) {
        st.update(1, 1, n, i, max(0, a[i].fi - b[i]));
        res[a[i + 1].se] = st.st[1].mx;
    }
    for(int i = 1; i <= n + 1; i++) cout<<res[i]<<" ";
    return 0;
}

Compilation message

ho_t1.cpp: In member function 'void ST::build(int, int, int)':
ho_t1.cpp:41:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |         int mid = l + r >> 1;
      |                   ~~^~~
ho_t1.cpp: In member function 'void ST::update(int, int, int, int, int)':
ho_t1.cpp:53:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2516 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2516 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 81 ms 11604 KB Output is correct
34 Correct 87 ms 12068 KB Output is correct
35 Correct 90 ms 11856 KB Output is correct
36 Correct 88 ms 12116 KB Output is correct
37 Correct 87 ms 12368 KB Output is correct
38 Correct 90 ms 12328 KB Output is correct
39 Correct 83 ms 11480 KB Output is correct
40 Correct 83 ms 11344 KB Output is correct
41 Correct 83 ms 11348 KB Output is correct
42 Correct 84 ms 11500 KB Output is correct
43 Correct 90 ms 11348 KB Output is correct
44 Correct 81 ms 11088 KB Output is correct
45 Correct 82 ms 11092 KB Output is correct
46 Correct 82 ms 11088 KB Output is correct
47 Correct 79 ms 11092 KB Output is correct
48 Correct 86 ms 11092 KB Output is correct
49 Correct 85 ms 11580 KB Output is correct
50 Correct 87 ms 11556 KB Output is correct
51 Correct 85 ms 11600 KB Output is correct
52 Correct 85 ms 11732 KB Output is correct
53 Correct 84 ms 11656 KB Output is correct