답안 #624202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624202 2022-08-07T12:46:57 Z Abrar_Al_Samit Snowball (JOI21_ho_t2) C++17
33 / 100
920 ms 13752 KB
#include<bits/stdc++.h>
using namespace std;

const long long oo = 1e13;

void PlayGround() {
  int n, q;
  cin>>n>>q;
  long long a[n];
  for(int i=0; i<n; ++i) {
    cin>>a[i];
  }

  long long pre[q+1] = {0};
  for(int i=1; i<=q; ++i) {
    cin>>pre[i];
  }
  for(int i=1; i<=q; ++i) {
    pre[i] += pre[i-1];
  }

  long long premn[q+1], premx[q+1];
  premx[0] = premn[0] = pre[0];
  for(int i=1; i<=q; ++i) {
    premx[i] = max(premx[i-1], pre[i]);
    premn[i] = min(premn[i-1], pre[i]);

  }

  long long ans[n] = {0};
  for(int i=0; i<n; ++i) {
    long long r = a[i];
    long long l = -oo;

    while(l<r) {
      long long mid;
      if(l<0 && r<=0) mid = (l+r-1)/2;
      else mid = (l+r)/2;

      if(premn[q]+a[i]>mid) {
        l = mid+1;
        continue;
      }
      int lid = 0, rid = q;
      while(lid<rid) {
        int midid = (lid+rid)/2;
        if(premn[midid]+a[i]<=mid) {
          rid = midid;
        } else {
          lid = midid+1;
        }
      }
      if(lid && i) {
        if(premx[lid-1]+a[i-1]>mid) {
          l = mid+1;
        } else {
          r = mid;
        }
      } else {
        r = mid;
      }
    }

    ans[i] += a[i]-l;


    l = a[i];
    r = oo;
    while(l<r) {
      long long mid = (1+l+r)/2;

      if(premx[q]+a[i]<mid) {
        r = mid-1;
        continue;
      }

      int lid = 0, rid = q;
      while(lid<rid) {
        int midid = (lid+rid)/2;

        if(a[i]+premx[midid]>=mid) {
          rid = midid;
        } else {
          lid = midid+1;
        }
      }
      if(lid && i<n-1) {
        if(premn[lid-1]+a[i+1]<mid) {
          r = mid-1;
        } else {
          l = mid;
        }
      } else {
        l = mid;
      }
    }
    ans[i] += l-a[i];
  }

  for(int i=0; i<n; ++i) {
    cout<<ans[i]<<'\n';
  }

}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 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 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 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 8 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 26 ms 7120 KB Output is correct
21 Correct 28 ms 6988 KB Output is correct
22 Correct 36 ms 6728 KB Output is correct
23 Correct 33 ms 6600 KB Output is correct
24 Correct 117 ms 7048 KB Output is correct
25 Correct 920 ms 13424 KB Output is correct
26 Correct 847 ms 13328 KB Output is correct
27 Correct 761 ms 13100 KB Output is correct
28 Correct 753 ms 13100 KB Output is correct
29 Correct 659 ms 12664 KB Output is correct
30 Correct 336 ms 11980 KB Output is correct
31 Correct 113 ms 11460 KB Output is correct
32 Correct 97 ms 11676 KB Output is correct
33 Correct 70 ms 1620 KB Output is correct
34 Correct 761 ms 13752 KB Output is correct
35 Correct 755 ms 13132 KB Output is correct
36 Correct 918 ms 13392 KB Output is correct
37 Correct 818 ms 13088 KB Output is correct
38 Correct 774 ms 12924 KB Output is correct
39 Correct 787 ms 13128 KB Output is correct
40 Correct 539 ms 13132 KB Output is correct
41 Incorrect 30 ms 7628 KB Output isn't correct
42 Halted 0 ms 0 KB -