Submission #534331

# Submission time Handle Problem Language Result Execution time Memory
534331 2022-03-08T05:04:38 Z Biaz Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 16900 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define X first
#define Y second
#define ist insert
#define pii pair<int,int>
typedef long long ll;
//typedef pair<int,int> pii;
using namespace std;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
const int INF=1700000000000000;//2147483647;
const int MOD=998244353;//1000000007;
const int N=200005;
struct BIT{
    int n;
    vector<int> bit;
    void init(int _n){
        n=_n;
        bit.resize(n+5,0);
    }
    void add(int i,int v){
        while (i<=n){
            bit[i]+=v;
            i+=(i&-i);
        }
    }
    int que(int i){
        int res=0;
        while (i>0){
            res+=bit[i];
            i-=(i&-i);
        }
        return res;
    }
};
int n,Q;
int a[N],w[N],res[N];
pii d[N];
int mxL,mxR;
int search(int val){
    int l=1,r=n+1,res=0;
    while (r>=l){
        int mid=(l+r)/2;
        if (d[mid].fi>=val){
            res=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    return res;
}

void sol(){
    cin >>n>>Q;
    for (int i=1;i<=n;i++)
        cin >>a[i];
    a[0]=-INF;a[n+1]=INF;
    for (int i=1;i<=Q;i++)
        cin >>w[i];
    BIT tr[2];tr[0].init(n+5);tr[1].init(n+5);
    for (int i=1;i<=n+1;i++)
        d[i].fi=a[i]-a[i-1],d[i].se=i;
    sort(d+1,d+n+2,greater<pii>());
    /*for (int i=1;i<=n+1;i++)
        cout <<d[i].se<<' ';
    cout <<"\n";*/
    int cur=0,r=n+1;
    mxL=mxR=0;
    for (int xx=1;xx<=Q;xx++){
        cur+=w[xx];
        if (mxL<=cur&&cur<=mxR) continue;
        if (cur>0){
            int loc=search(cur-mxL);
            //cout <<loc<<'\n';
            tr[1].add(1,cur-mxR);
            tr[1].add(loc+1,mxR-cur);
            while (d[r].fi<cur-mxL){
                tr[1].add(r,d[r].fi-(mxR-mxL));
                tr[1].add(r+1,-(d[r].fi-(mxR-mxL)));
                r--;
            }
        }
        if (cur<0){
            int loc=search(mxR-cur);
            //cout <<loc<<'\n';
            tr[0].add(1,mxL-cur);
            tr[0].add(loc+1,cur-mxL);
            while (d[r].fi<mxR-cur){
                tr[0].add(r,d[r].fi-(mxR-mxL));
                tr[0].add(r+1,-(d[r].fi-(mxR-mxL)));
                r--;
            }
        }
        mxL=min(mxL,cur);
        mxR=max(mxR,cur);
        /*for (int i=0;i<=n+2;i++)
            cout <<tr[1].que(i)<<' ';
        cout <<"\n";
        for (int i=0;i<=n+2;i++)
            cout <<tr[0].que(i)<<' ';
        cout <<"\n";*/

    }
    for (int i=1;i<=n+1;i++)
        res[d[i].se]+=tr[0].que(i);
    for (int i=1;i<=n+1;i++)
        res[d[i].se-1]+=tr[1].que(i);
    for (int i=1;i<=n;i++)
        cout <<res[i]<<'\n';
}
/*
4 3
-2 3 5 8
2
-4
7
*/
signed main()
{
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 3 ms 480 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 3 ms 480 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 82 ms 3972 KB Output is correct
21 Correct 77 ms 3680 KB Output is correct
22 Correct 74 ms 3588 KB Output is correct
23 Correct 70 ms 3456 KB Output is correct
24 Correct 83 ms 4596 KB Output is correct
25 Correct 248 ms 16556 KB Output is correct
26 Correct 210 ms 16460 KB Output is correct
27 Correct 209 ms 16048 KB Output is correct
28 Correct 211 ms 16404 KB Output is correct
29 Correct 186 ms 15812 KB Output is correct
30 Correct 173 ms 15108 KB Output is correct
31 Correct 163 ms 14660 KB Output is correct
32 Correct 152 ms 14760 KB Output is correct
33 Correct 22 ms 1912 KB Output is correct
34 Correct 195 ms 16900 KB Output is correct
35 Correct 188 ms 16324 KB Output is correct
36 Correct 213 ms 16512 KB Output is correct
37 Correct 205 ms 16260 KB Output is correct
38 Correct 217 ms 16104 KB Output is correct
39 Correct 207 ms 16276 KB Output is correct
40 Correct 198 ms 16324 KB Output is correct
41 Execution timed out 2553 ms 4540 KB Time limit exceeded
42 Halted 0 ms 0 KB -