답안 #862011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862011 2023-10-17T11:24:01 Z 8pete8 Snowball (JOI21_ho_t2) C++14
100 / 100
187 ms 13916 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
const int mxn=5e5+10,mx=5e6+10,minf=-1e9;
int32_t main(){
    int n,q;cin>>n>>q;
    vector<int>pos(n),ans(n,0);
    for(int i=0;i<n;i++)cin>>pos[i];
    vector<int>mn(q+1,0),mx(q+1,0);
    int cur=0;
    for(int i=1;i<=q;i++){
        int k;cin>>k;
        cur+=k;
        if(i)mn[i]=mn[i-1],mx[i]=mx[i-1];
        mn[i]=min(mn[i],cur);
        mx[i]=max(mx[i],cur);
    }
    ans[0]-=mn[q];
    ans[n-1]+=mx[q];
    for(int i=0;i<n-1;i++){
        int l=0,r=q,a=0;
        while(l<=r){
            int mid=l+(r-l)/2;
            if(pos[i+1]+mn[mid]>pos[i]+mx[mid]){
                a=max(a,mid);
                l=mid+1;
            }
            else r=mid-1;
        }
        ans[i]+=mx[a];
        ans[i+1]-=mn[a];
        if(a<q){
            int diff=(pos[i+1]+mn[a])-(pos[i]+mx[a]);
            if(mx[a+1]>mx[a])ans[i]+=diff;
            else ans[i+1]+=diff;
        }
    }
    for(auto i:ans)cout<<i<<'\n';
}
/*
4 5 3 100
2 80 100
5 125 130
4 75 150
3 120 110
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 61 ms 5596 KB Output is correct
21 Correct 61 ms 5472 KB Output is correct
22 Correct 53 ms 5084 KB Output is correct
23 Correct 50 ms 5108 KB Output is correct
24 Correct 57 ms 5456 KB Output is correct
25 Correct 151 ms 12000 KB Output is correct
26 Correct 157 ms 11932 KB Output is correct
27 Correct 148 ms 11476 KB Output is correct
28 Correct 149 ms 11656 KB Output is correct
29 Correct 144 ms 11092 KB Output is correct
30 Correct 140 ms 10580 KB Output is correct
31 Correct 111 ms 10068 KB Output is correct
32 Correct 117 ms 10576 KB Output is correct
33 Correct 15 ms 1624 KB Output is correct
34 Correct 159 ms 12368 KB Output is correct
35 Correct 154 ms 11660 KB Output is correct
36 Correct 161 ms 11984 KB Output is correct
37 Correct 149 ms 11600 KB Output is correct
38 Correct 145 ms 11548 KB Output is correct
39 Correct 156 ms 11928 KB Output is correct
40 Correct 130 ms 11748 KB Output is correct
41 Correct 71 ms 6096 KB Output is correct
42 Correct 111 ms 10088 KB Output is correct
43 Correct 158 ms 13532 KB Output is correct
44 Correct 98 ms 5972 KB Output is correct
45 Correct 143 ms 11692 KB Output is correct
46 Correct 187 ms 13652 KB Output is correct
47 Correct 177 ms 13648 KB Output is correct
48 Correct 174 ms 13916 KB Output is correct