Submission #817773

# Submission time Handle Problem Language Result Execution time Memory
817773 2023-08-09T16:07:55 Z t6twotwo Measures (CEOI22_measures) C++17
76 / 100
309 ms 30556 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FFOR(i,a,b,c) for(int i=(a);(c)>0?i<=(b):i>=(b);i+=(c))
#define FOOR(i,a,b) FFOR(i,a,(b)-1,1)
#define ROOF(i,a,b) FFOR(i,(b)-1,a,-1)
#define FOR(i,n) FOOR(i,0,n)
#define ROF(i,n) ROOF(i,0,n)
#define FORR(x,v) for(auto &x:v)
#define vc vector
#define sz(v) (int)((v).size())
#define bg begin()
#define en end()
#define em empty()
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define ppb pop_back()
#define eb emplace_back
#define bk back()
#define fr front()
#define pp pop()
#define all(v) (v).begin(),(v).end()
#define lla(v) (v).rbegin(),(v).rend()
#define f first
#define s second
template <class T>
struct segtree {
    int n;
    vector<T> s;
    segtree(int n) : n(n), s(2 * n) {
    }
    segtree(vector<T> &a) : segtree(a.size()) {
        for (int i = 2 * n - 1; i; i--) {
            s[i] = i < n ? s[i * 2] + s[i * 2 + 1] : a[i - n];
        }
    }
    void update(int i, const T &v) {
        for (s[i += n] = v; i /= 2;) {
            s[i] = s[i * 2] + s[i * 2 + 1];
        }
    }
    T query(int l, int r) {
        T u, v;
        for (l += n, r += n; l < r; l /= 2, r /= 2) {
            if (l % 2 == 1) {
                u = u + s[l++];
            }
            if (r % 2 == 1) {
                v = s[--r] + v;
            }
        }
        return u + v;
    }
};
struct node {
    ll sum, pre, suf, ans;
    node() {
        sum = pre = suf = ans = 0;
    }
    node(int v) {
        sum = v;
        pre = suf = ans = max(0, v);
    }
};
node operator+(const node &a, const node &b) {
    node c;
    c.sum = a.sum + b.sum;
    c.pre = max(a.pre, a.sum + b.pre);
    c.suf = max(b.suf, b.sum + a.suf);
    c.ans = max({a.suf + b.pre, a.ans, b.ans});
    return c;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,D;
    cin>>N>>M>>D;
    if(M<=10&&0){
        vc<int> a(N);
        FORR(x,a)cin>>x;
        FOR(i,M){
            int b;
            cin>>b;
            a.pb(b);
            sort(all(a));
            ll s=0,ans=0;
            FOOR(j,1,sz(a)){
                ll k=a[j]-a[j-1]-D;
                s=min(k,s+k);
                ans=min(ans,s);
            }
            ans=-ans;
            if(ans%2==1){
                cout<<ans/2<<"."<<5<<" ";
            }else{
                cout<<ans/2<<" ";
            }
        }
        return 0;
    }
    vc<int> b(M);
    vc<pair<int,int>> p(M);
    FOR(i,M){
        cin>>b[i];
        p[i]={b[i],i};
    }
    sort(all(p));
    vc<int> pos(M);
    FOR(i,M) pos[p[i].s]=i;
    segtree<node> st(M);
    set<int> s;
    FOR(i,M){
        auto it=s.ub(pos[i]);
        if(it!=s.bg){
            st.update(pos[i],-(b[i]-p[*prev(it)].f-D));
        }
        if(it!=s.en){
            st.update(*it,-(p[*it].f-b[i]-D));
        }
        s.insert(pos[i]);
        ll ans=st.query(0,M).ans;
        if(ans%2==1){
            cout<<ans/2<<"."<<5<<" ";
        }else{
            cout<<ans/2<<" ";
        }
    }
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 26364 KB Output is correct
2 Correct 153 ms 28340 KB Output is correct
3 Correct 155 ms 28200 KB Output is correct
4 Correct 140 ms 26112 KB Output is correct
5 Correct 147 ms 27384 KB Output is correct
6 Correct 147 ms 28368 KB Output is correct
7 Correct 163 ms 29372 KB Output is correct
8 Correct 148 ms 28176 KB Output is correct
9 Correct 152 ms 27952 KB Output is correct
10 Correct 154 ms 30424 KB Output is correct
11 Correct 156 ms 28900 KB Output is correct
12 Correct 167 ms 29752 KB Output is correct
13 Correct 150 ms 28108 KB Output is correct
14 Correct 148 ms 30048 KB Output is correct
15 Correct 151 ms 29756 KB Output is correct
16 Correct 153 ms 27692 KB Output is correct
17 Correct 146 ms 29300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 26364 KB Output is correct
2 Correct 153 ms 28340 KB Output is correct
3 Correct 155 ms 28200 KB Output is correct
4 Correct 140 ms 26112 KB Output is correct
5 Correct 147 ms 27384 KB Output is correct
6 Correct 147 ms 28368 KB Output is correct
7 Correct 163 ms 29372 KB Output is correct
8 Correct 148 ms 28176 KB Output is correct
9 Correct 152 ms 27952 KB Output is correct
10 Correct 154 ms 30424 KB Output is correct
11 Correct 156 ms 28900 KB Output is correct
12 Correct 167 ms 29752 KB Output is correct
13 Correct 150 ms 28108 KB Output is correct
14 Correct 148 ms 30048 KB Output is correct
15 Correct 151 ms 29756 KB Output is correct
16 Correct 153 ms 27692 KB Output is correct
17 Correct 146 ms 29300 KB Output is correct
18 Correct 275 ms 28400 KB Output is correct
19 Correct 282 ms 30116 KB Output is correct
20 Correct 153 ms 30228 KB Output is correct
21 Correct 198 ms 28156 KB Output is correct
22 Correct 216 ms 28508 KB Output is correct
23 Correct 183 ms 28400 KB Output is correct
24 Correct 309 ms 28844 KB Output is correct
25 Correct 143 ms 28048 KB Output is correct
26 Correct 276 ms 27972 KB Output is correct
27 Correct 281 ms 30556 KB Output is correct
28 Correct 213 ms 28392 KB Output is correct
29 Correct 250 ms 29960 KB Output is correct
30 Correct 197 ms 28028 KB Output is correct
31 Correct 196 ms 30060 KB Output is correct
32 Correct 188 ms 29748 KB Output is correct
33 Correct 279 ms 27616 KB Output is correct
34 Correct 202 ms 29376 KB Output is correct