Submission #493826

#TimeUsernameProblemLanguageResultExecution timeMemory
493826i_am_noobSnowball (JOI21_ho_t2)C++17
100 / 100
320 ms12852 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pii pair<int,int>
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define inf 1000'000'000'000'000'000
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ": " << #__VA_ARGS__ << "- ",_do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ... S> void _do(T x, S ...y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif

const int maxn=200005;

int n,m,a[maxn],b[maxn],maxx[maxn],minn[maxn],res[maxn];

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    rep(n) cin >> a[i];
    rep(m) cin >> b[i];
    maxx[0]=minn[0]=0;
    int cur=0;
    rep(m){
        cur+=b[i];
        maxx[i+1]=max(maxx[i],cur);
        minn[i+1]=min(minn[i],cur);
        bug(i+1,maxx[i+1],minn[i+1]);
    }
    res[n-1]+=maxx[m];
    res[0]-=minn[m];
    rep(n-1){
        if(maxx[m]-minn[m]<=a[i+1]-a[i]){
            res[i]+=maxx[m];
            res[i+1]-=minn[m];
            continue;
        }
        int l=0,r=m;
        while(l<r){
            int mid=l+r+1>>1;
            if(maxx[mid]-minn[mid]<=a[i+1]-a[i]) l=mid;
            else r=mid-1;
        }
        bug(l);
        if(b[l]>0){
            res[i+1]-=minn[l];
            res[i]+=a[i+1]-a[i]+minn[l];
        }
        else{
            res[i]+=maxx[l];
            res[i+1]+=a[i+1]-a[i]-maxx[l];
        }
    }
    rep(n) cout << res[i] << endl;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:21:18: warning: statement has no effect [-Wunused-value]
   21 | #define bug(...) 49
      |                  ^~
Main.cpp:39:9: note: in expansion of macro 'bug'
   39 |         bug(i+1,maxx[i+1],minn[i+1]);
      |         ^~~
Main.cpp:51:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |             int mid=l+r+1>>1;
      |                     ~~~^~
Main.cpp:21:18: warning: statement has no effect [-Wunused-value]
   21 | #define bug(...) 49
      |                  ^~
Main.cpp:55:9: note: in expansion of macro 'bug'
   55 |         bug(l);
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...