Submission #624205

# Submission time Handle Problem Language Result Execution time Memory
624205 2022-08-07T12:52:08 Z Abrar_Al_Samit Snowball (JOI21_ho_t2) C++17
100 / 100
849 ms 15348 KB
#include<bits/stdc++.h>
using namespace std;

const long long oo = 1e18;

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;
}
# Verdict Execution time Memory 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 5 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
16 Correct 5 ms 388 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 5 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
16 Correct 5 ms 388 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 26 ms 4932 KB Output is correct
21 Correct 24 ms 4948 KB Output is correct
22 Correct 24 ms 4956 KB Output is correct
23 Correct 32 ms 4964 KB Output is correct
24 Correct 112 ms 5436 KB Output is correct
25 Correct 844 ms 9676 KB Output is correct
26 Correct 849 ms 9664 KB Output is correct
27 Correct 789 ms 9536 KB Output is correct
28 Correct 776 ms 9412 KB Output is correct
29 Correct 712 ms 9300 KB Output is correct
30 Correct 343 ms 8916 KB Output is correct
31 Correct 129 ms 8516 KB Output is correct
32 Correct 107 ms 8524 KB Output is correct
33 Correct 75 ms 1200 KB Output is correct
34 Correct 785 ms 9660 KB Output is correct
35 Correct 767 ms 9484 KB Output is correct
36 Correct 849 ms 9676 KB Output is correct
37 Correct 769 ms 9400 KB Output is correct
38 Correct 766 ms 9400 KB Output is correct
39 Correct 754 ms 9508 KB Output is correct
40 Correct 475 ms 9404 KB Output is correct
41 Correct 27 ms 4944 KB Output is correct
42 Correct 102 ms 11588 KB Output is correct
43 Correct 389 ms 14940 KB Output is correct
44 Correct 30 ms 7496 KB Output is correct
45 Correct 259 ms 13132 KB Output is correct
46 Correct 323 ms 15052 KB Output is correct
47 Correct 449 ms 15288 KB Output is correct
48 Correct 335 ms 15348 KB Output is correct