Submission #831944

# Submission time Handle Problem Language Result Execution time Memory
831944 2023-08-20T18:19:55 Z QwertyPi Measures (CEOI22_measures) C++14
100 / 100
336 ms 42964 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 2e5 + 11;

int n, m, d;

struct node{
    bool active; int _min, _max, _diff, lazy;
    node(): active(0), _min(0), _max(0), _diff(0), lazy(0){};
    node(int v) : active(1), _min(v), _max(v), _diff(0), lazy(0){};
    int get_diff(){ return _diff; }
};

node operator+ (const node& a, const node& b){
    node res;
    if(!a.active || !b.active){
        res = a.active ? a : b;
        res.lazy = 0;
        return res;
    }
    res.active = true;
    res._min = min(a._min, b._min);
    res._max = max(a._max, b._max);
    res._diff = max(max(a._diff, b._diff), a._max - b._min);
    res.lazy = 0;
    return res;
}

void operator+= (node& a, int x){
    a._min += x;
    a._max += x;
    a.lazy += x;
}

node t[MAXN << 2];

void st_push(int v){
    t[v * 2 + 1] += t[v].lazy;
    t[v * 2 + 2] += t[v].lazy;
    t[v].lazy = 0;
}

void st_range_add(int ql, int qr, int qv, int v = 0, int l = 0, int r = MAXN - 1){
    if(qr < l || r < ql) return;
    if(ql <= l && r <= qr) { t[v] += qv; }
    else {
        st_push(v);
        int m = (l + r) / 2;
        st_range_add(ql, qr, qv, v * 2 + 1, l, m);
        st_range_add(ql, qr, qv, v * 2 + 2, m + 1, r);
        t[v] = t[v * 2 + 1] + t[v * 2 + 2];
    }
}

void st_point_add(int qi, int qv, int v = 0, int l = 0, int r = MAXN - 1){
    if(l == r) { t[v] = node(t[v]._min + qv); }
    else {
        st_push(v);
        int m = (l + r) / 2;
        if(qi <= m) st_point_add(qi, qv, v * 2 + 1, l, m);
        else st_point_add(qi, qv, v * 2 + 2, m + 1, r);
        t[v] = t[v * 2 + 1] + t[v * 2 + 2];
    }
}

int st_point_qry(int qi, int v = 0, int l = 0, int r = MAXN - 1){
    if(l == r) return t[v]._max;
    st_push(v);
    int m = (l + r) / 2;
    if(qi <= m) return st_point_qry(qi, v * 2 + 1, l, m);
    else return st_point_qry(qi, v * 2 + 2, m + 1, r);
}

void add(int x, int v){
    st_range_add(x, MAXN - 1, -d);
    st_point_add(x, v);
}

int qry(){
    return t[0].get_diff();
}

int solve(vector<int>& a){
    vector<int> x;
    for(int i = 0; i < a.size(); i++){
        x.push_back(a[i] - i * d);
    }
    int mx = 0;
    for(int i = 0; i < x.size(); i++){
        for(int j = i; j < x.size(); j++){
            mx = max(mx, x[i] - x[j]);
        }
    }
    return mx;
}

int32_t main(){
    cin >> n >> m >> d;
    vector<int> a, b, ai, bi;
    for(int i = 0; i < n; i++) { 
        int v; cin >> v; a.push_back(v);
    }
    for(int i = 0; i < m; i++){
        int v; cin >> v; b.push_back(v);
    }
    vector<pair<int, int>> vp;
    for(int i = 0; i < n; i++){
        vp.push_back({a[i], i});
    }
    for(int i = 0; i < m; i++){
        vp.push_back({b[i], n + i});
    }
    sort(vp.begin(), vp.end());
    ai.resize(n); bi.resize(m);
    for(int i = 0; i < n + m; i++){
        if(vp[i].second < n){
            ai[vp[i].second] = i;
        }else{
            bi[vp[i].second - n] = i;
        }
    }
    for(int i = 0; i < n; i++){
        add(ai[i], a[i]);
    }
    for(int i = 0; i < m; i++){
        add(bi[i], b[i]);
        int ans = qry();
        cout << ans / 2 << (ans % 2 ? ".5" : "") << ' ';
    }
    cout << '\n';
}

Compilation message

Main.cpp: In function 'long long int solve(std::vector<long long int>&)':
Main.cpp:87:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
Main.cpp:91:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i = 0; i < x.size(); i++){
      |                    ~~^~~~~~~~~~
Main.cpp:92:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         for(int j = i; j < x.size(); j++){
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31664 KB Output is correct
2 Correct 13 ms 31628 KB Output is correct
3 Correct 17 ms 31692 KB Output is correct
4 Correct 18 ms 31700 KB Output is correct
5 Correct 17 ms 31704 KB Output is correct
6 Correct 18 ms 31612 KB Output is correct
7 Correct 16 ms 31700 KB Output is correct
8 Correct 14 ms 31656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31664 KB Output is correct
2 Correct 13 ms 31628 KB Output is correct
3 Correct 17 ms 31692 KB Output is correct
4 Correct 18 ms 31700 KB Output is correct
5 Correct 17 ms 31704 KB Output is correct
6 Correct 18 ms 31612 KB Output is correct
7 Correct 16 ms 31700 KB Output is correct
8 Correct 14 ms 31656 KB Output is correct
9 Correct 322 ms 39808 KB Output is correct
10 Correct 336 ms 39808 KB Output is correct
11 Correct 228 ms 39836 KB Output is correct
12 Correct 211 ms 39732 KB Output is correct
13 Correct 166 ms 39280 KB Output is correct
14 Correct 267 ms 39736 KB Output is correct
15 Correct 268 ms 39140 KB Output is correct
16 Correct 173 ms 39816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 40752 KB Output is correct
2 Correct 226 ms 42744 KB Output is correct
3 Correct 201 ms 42756 KB Output is correct
4 Correct 207 ms 40520 KB Output is correct
5 Correct 206 ms 41964 KB Output is correct
6 Correct 192 ms 40944 KB Output is correct
7 Correct 195 ms 41872 KB Output is correct
8 Correct 194 ms 40584 KB Output is correct
9 Correct 190 ms 40528 KB Output is correct
10 Correct 237 ms 42904 KB Output is correct
11 Correct 194 ms 41336 KB Output is correct
12 Correct 193 ms 42348 KB Output is correct
13 Correct 190 ms 40524 KB Output is correct
14 Correct 193 ms 42448 KB Output is correct
15 Correct 193 ms 42372 KB Output is correct
16 Correct 186 ms 40112 KB Output is correct
17 Correct 194 ms 41872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 40752 KB Output is correct
2 Correct 226 ms 42744 KB Output is correct
3 Correct 201 ms 42756 KB Output is correct
4 Correct 207 ms 40520 KB Output is correct
5 Correct 206 ms 41964 KB Output is correct
6 Correct 192 ms 40944 KB Output is correct
7 Correct 195 ms 41872 KB Output is correct
8 Correct 194 ms 40584 KB Output is correct
9 Correct 190 ms 40528 KB Output is correct
10 Correct 237 ms 42904 KB Output is correct
11 Correct 194 ms 41336 KB Output is correct
12 Correct 193 ms 42348 KB Output is correct
13 Correct 190 ms 40524 KB Output is correct
14 Correct 193 ms 42448 KB Output is correct
15 Correct 193 ms 42372 KB Output is correct
16 Correct 186 ms 40112 KB Output is correct
17 Correct 194 ms 41872 KB Output is correct
18 Correct 276 ms 40940 KB Output is correct
19 Correct 307 ms 42640 KB Output is correct
20 Correct 234 ms 42728 KB Output is correct
21 Correct 251 ms 40660 KB Output is correct
22 Correct 254 ms 41008 KB Output is correct
23 Correct 201 ms 40880 KB Output is correct
24 Correct 284 ms 41496 KB Output is correct
25 Correct 189 ms 40476 KB Output is correct
26 Correct 289 ms 40484 KB Output is correct
27 Correct 311 ms 42964 KB Output is correct
28 Correct 269 ms 40916 KB Output is correct
29 Correct 264 ms 42340 KB Output is correct
30 Correct 236 ms 40552 KB Output is correct
31 Correct 231 ms 42500 KB Output is correct
32 Correct 206 ms 42332 KB Output is correct
33 Correct 267 ms 40188 KB Output is correct
34 Correct 229 ms 41864 KB Output is correct