Submission #810563

# Submission time Handle Problem Language Result Execution time Memory
810563 2023-08-06T11:16:27 Z winter0101 Snowball (JOI21_ho_t2) C++14
100 / 100
939 ms 16936 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define eb emplace_back
const int maxn=2e5+9;
long long x[maxn],w[maxn],a[maxn],b[maxn],c[maxn];
long long ans[maxn];
int n,q;
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    cin>>n>>q;
    for1(i,1,n)cin>>x[i];
    for1(i,1,q){
    cin>>w[i];
    a[i]=a[i-1]+w[i];
    b[i]=max(a[i],b[i-1]);
    c[i]=min(a[i],c[i-1]);
    }
    for1(i,1,n){
    if (i==n){
        if (b[q]>0)ans[i]+=b[q];
        continue;
    }
    long long l=x[i],r=x[i+1];
    while (l<=r){
        long long mid=(l+r)/2;
        //cerr<<mid<<'\n';
        if (b[q]+x[i]<mid){
            r=mid-1;
        }
        else {
            int l1=1,r1=q,c1=-1;
            while (l1<=r1){
                int mid1=(l1+r1)/2;
                if (x[i]+b[mid1]>=mid){
                    c1=mid1;
                    r1=mid1-1;
                }
                else l1=mid1+1;
            }
            if (x[i+1]+c[c1]<mid){
                r=mid-1;
            }
            else {
            l=mid+1;
            ans[i]=mid-x[i];
            }
        }
    }
    //cout<<ans[i]<<'\n';
    }
    //return 0;
    for1(i,1,n){
    if (i==1){
        if (c[q]<0)ans[i]-=c[q];
        continue;
    }
    long long l=x[i-1],r=x[i],s=x[i];
    while (l<=r){
        long long mid=(l+r)/2;
        if (x[i]+c[q]>mid){
            l=mid+1;
        }
        else {
            int l1=1,r1=q,c1=-1;
            while (l1<=r1){
                int mid1=(l1+r1)/2;
                if (x[i]+c[mid1]<=mid){
                    c1=mid1;
                    r1=mid1-1;
                }
                else l1=mid1+1;
            }
            if (x[i-1]+b[c1]>mid){
                l=mid+1;
            }
            else {
                r=mid-1;
                s=mid;
            }
        }
    }
    ans[i]+=x[i]-s;
    //ans[i]=s;
    //cout<<ans[i]<<'\n';
    }
    //cout<<ans[2];
    for1(i,1,n)cout<<ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 472 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 472 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 21 ms 8680 KB Output is correct
21 Correct 21 ms 8516 KB Output is correct
22 Correct 20 ms 8264 KB Output is correct
23 Correct 27 ms 8208 KB Output is correct
24 Correct 110 ms 8576 KB Output is correct
25 Correct 911 ms 14964 KB Output is correct
26 Correct 901 ms 14920 KB Output is correct
27 Correct 828 ms 14532 KB Output is correct
28 Correct 813 ms 14780 KB Output is correct
29 Correct 741 ms 14288 KB Output is correct
30 Correct 371 ms 13628 KB Output is correct
31 Correct 66 ms 13052 KB Output is correct
32 Correct 54 ms 13144 KB Output is correct
33 Correct 68 ms 1840 KB Output is correct
34 Correct 807 ms 15424 KB Output is correct
35 Correct 805 ms 14736 KB Output is correct
36 Correct 939 ms 14944 KB Output is correct
37 Correct 830 ms 14640 KB Output is correct
38 Correct 837 ms 14500 KB Output is correct
39 Correct 816 ms 14744 KB Output is correct
40 Correct 223 ms 14780 KB Output is correct
41 Correct 22 ms 9300 KB Output is correct
42 Correct 58 ms 13212 KB Output is correct
43 Correct 238 ms 16440 KB Output is correct
44 Correct 21 ms 9208 KB Output is correct
45 Correct 334 ms 14824 KB Output is correct
46 Correct 213 ms 16632 KB Output is correct
47 Correct 241 ms 16840 KB Output is correct
48 Correct 153 ms 16936 KB Output is correct