Submission #503734

# Submission time Handle Problem Language Result Execution time Memory
503734 2022-01-08T18:50:01 Z cig32 Snowball (JOI21_ho_t2) C++17
100 / 100
101 ms 18408 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define int long long

int rnd(int x, int y) { // random number generator
  int u= uniform_int_distribution<int>(x, y)(rng); return u;
}

void solve(int tc) {
  int N, Q;
  cin >> N >> Q;
  int X[N+1], L[N+1], R[N+1];
  for(int i=1; i<=N; i++) cin >> X[i];
  int W[Q+1], ps[Q+1], maxp[Q+1], minp[Q+1];
  minp[0] = 0;
  maxp[0] = 0;
  ps[0] = 0;
  for(int i=1; i<=Q; i++) {
    cin >> W[i];
    ps[i] = ps[i-1] + W[i];
    maxp[i] = max(maxp[i-1], ps[i]);
    minp[i] = min(minp[i-1], ps[i]);
  }
  L[1] = X[1] + minp[Q];
  R[N] = X[N] + maxp[Q];
  for(int i=1; i<N; i++) {
    int lb = 1, rb = Q;
    while(lb<rb) {
      int mid = (lb+rb) >> 1;
      if(X[i] + maxp[mid] > X[i+1] + minp[mid]) rb = mid;
      else lb = mid + 1;
    }
    if(X[i] + maxp[lb] > X[i+1] + minp[lb]) {
      if(W[lb] > 0) {
        R[i] = L[i+1] = X[i+1] + minp[lb];
      }
      else {
        R[i] = L[i+1] = X[i] + maxp[lb];
      }
    }
    else {
      R[i] = X[i] + maxp[Q];
      L[i+1] = X[i+1] + minp[Q];
    }
  }
  for(int i=1; i<=N; i++) cout << R[i] - L[i] << "\n";
}

int32_t main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 27 ms 8644 KB Output is correct
21 Correct 25 ms 8456 KB Output is correct
22 Correct 25 ms 8228 KB Output is correct
23 Correct 23 ms 8128 KB Output is correct
24 Correct 32 ms 8736 KB Output is correct
25 Correct 95 ms 16500 KB Output is correct
26 Correct 95 ms 16456 KB Output is correct
27 Correct 93 ms 16048 KB Output is correct
28 Correct 95 ms 16316 KB Output is correct
29 Correct 101 ms 15788 KB Output is correct
30 Correct 87 ms 15208 KB Output is correct
31 Correct 59 ms 14584 KB Output is correct
32 Correct 60 ms 14828 KB Output is correct
33 Correct 9 ms 1984 KB Output is correct
34 Correct 92 ms 16868 KB Output is correct
35 Correct 92 ms 16320 KB Output is correct
36 Correct 95 ms 16504 KB Output is correct
37 Correct 97 ms 16244 KB Output is correct
38 Correct 93 ms 16108 KB Output is correct
39 Correct 89 ms 16240 KB Output is correct
40 Correct 70 ms 16236 KB Output is correct
41 Correct 29 ms 9240 KB Output is correct
42 Correct 55 ms 14712 KB Output is correct
43 Correct 75 ms 18012 KB Output is correct
44 Correct 29 ms 9092 KB Output is correct
45 Correct 65 ms 16240 KB Output is correct
46 Correct 72 ms 18108 KB Output is correct
47 Correct 73 ms 18404 KB Output is correct
48 Correct 79 ms 18408 KB Output is correct