답안 #701544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701544 2023-02-21T12:51:33 Z huomark1001 Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
#include<random>
using namespace std;

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

#define float double
#define ss(n) fixed<<setprecision(n) 
#define ll long long
#define int ll
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define rep(i,a) for(int i=1;i<=a;i++)
#define rep0(i,a) for(int i=0;i<a;i++)
#define F first
#define S second
#define uni(a) a.resize(distance(a.begin(),unique(a.begin(),a.end())));
#define unisort(a) sort(a.begin(),a.end()); uni(a);

ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}

const ld pi=3.14159265358979323846264338327950288419716939931;
const int lar=3e18;
const int mol1=1e9+7;
const int mol2=998244353;
const int MX=2e5+5;


void solve()
{
    int n,q;
    cin>>n>>q;
    int a[n+1];int ans[n+1]={0};
    rep(i,n) cin>>a[i];
    int now=0;
    int mx[q+1]={0},mn[q+1]={0};
    int xx=0,n1=0,n2=0;
    rep(i,q){
        int g;
        cin>>g;
        xx+=g;
        n1=min(n1,xx);
        n2=max(n2,xx);
        mx[i]=max(mx[i],n2);
        mn[i]=min(mn[i],n1);
    }
    rep(i,n){
        if(i==1){
            int hh=mn[q];ans[1]+=abs(hh);
        }
        else{
            int l=1,r=q;
            while(l<r){
                int mid=l+r+1>>1;
                if(max(0LL,mx[mid])+abs(min(0LL,mn[mid]))>a[i]-a[i-1]){
                    r=mid-1;
                }
                else l=mid;
            }
            ans[i-1]+=max(0LL,mx[l]);
            ans[i]+=abs(min(0LL,mn[l]));
            if(l!=q&&mx[l+1]>mx[l]) ans[i-1]+=(a[i]-a[i-1])-(mx[l]+abs(mn[l]));
            else ans[i]+=(a[i]-a[i-1])-(mx[l]+abs(mn[l]));
        }
    }
    ans[n]+=max(0LL,mx[q]);
    rep(i,n) cout<<ans[i]<<"\n";

}

signed main()
{
    IO
    solve();
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:58:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |                 int mid=l+r+1>>1;
      |                         ~~~^~
Main.cpp:39:9: warning: unused variable 'now' [-Wunused-variable]
   39 |     int now=0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -