답안 #1110863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110863 2024-11-10T16:31:36 Z imarn Snowball (JOI21_ho_t2) C++14
100 / 100
103 ms 13808 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
bool cmp(pll a,pll b){
    if(a.f==b.f)return a.s>b.s;
    else return a.f<b.f;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,q;cin>>n>>q;ll ans[n+1]={0};
    ll x[n+1];for(int i=1;i<=n;i++)cin>>x[i];
    vector<ll> w(q+1),ww(q+1);w[0]=0,ww[0]=0;for(int i=1;i<=q;i++)cin>>w[i],w[i]+=w[i-1],ww[i]=-w[i];
    for(int i=1;i<=q;i++){
        w[i]=max(w[i],w[i-1]);
        ww[i]=max(ww[i],ww[i-1]);
    }
    for(int i=2;i<=n;i++){
        int l=1,r=q+1;
        while(l<r){
            int m=(l+r)>>1;
            if(x[i-1]+w[m]>x[i]-ww[m])r=m;
            else l=m+1;
        }
        if(r==q+1)ans[i-1]+=w[q],ans[i]+=ww[q];
        else {
            ans[i-1]+=w[l-1];
            ans[i]+=ww[l-1];
            if(w[l-1]!=w[l]){
                ans[i-1]+=(x[i]-ww[l-1])-(x[i-1]+w[l-1]);
            }
            else {
                ans[i]+=(x[i]-ww[l-1])-(x[i-1]+w[l-1]);
            }
        }
    }ans[1]+=ww[q],ans[n]+=w[q];
    for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 520 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 520 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 20 ms 3576 KB Output is correct
21 Correct 22 ms 4864 KB Output is correct
22 Correct 24 ms 3588 KB Output is correct
23 Correct 18 ms 3620 KB Output is correct
24 Correct 31 ms 3920 KB Output is correct
25 Correct 103 ms 9516 KB Output is correct
26 Correct 84 ms 10292 KB Output is correct
27 Correct 102 ms 8008 KB Output is correct
28 Correct 85 ms 11592 KB Output is correct
29 Correct 88 ms 11084 KB Output is correct
30 Correct 85 ms 10608 KB Output is correct
31 Correct 49 ms 10100 KB Output is correct
32 Correct 46 ms 10132 KB Output is correct
33 Correct 9 ms 1648 KB Output is correct
34 Correct 84 ms 12320 KB Output is correct
35 Correct 93 ms 11696 KB Output is correct
36 Correct 83 ms 11956 KB Output is correct
37 Correct 80 ms 11592 KB Output is correct
38 Correct 96 ms 11512 KB Output is correct
39 Correct 71 ms 11592 KB Output is correct
40 Correct 53 ms 11592 KB Output is correct
41 Correct 21 ms 6484 KB Output is correct
42 Correct 43 ms 10056 KB Output is correct
43 Correct 51 ms 13384 KB Output is correct
44 Correct 20 ms 5968 KB Output is correct
45 Correct 55 ms 11624 KB Output is correct
46 Correct 59 ms 13640 KB Output is correct
47 Correct 60 ms 13808 KB Output is correct
48 Correct 58 ms 13748 KB Output is correct