Submission #607397

# Submission time Handle Problem Language Result Execution time Memory
607397 2022-07-26T16:22:54 Z okaybody10 Snowball (JOI21_ho_t2) C++17
100 / 100
111 ms 13944 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
#define MAX LLONG_MAX/3
#define x first
#define y second

int p;
ll l, r, v;
vector<pli> co;
ll a[200006], ans[200006];

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    a[0] = -MAX, a[n+1] = MAX;
    for(int i = 1; i<=n;i++) scanf("%lld", &a[i]), co.push_back({a[i]-a[i-1], i-1}); // range
    co.push_back({a[n+1]-a[n], n});
    sort(co.begin(), co.end());
    while(q--) {
        ll t;
        scanf("%lld", &t);
        if(t>=0) {
            // if t > 0, wind is east direction
            // That means, snowball goes to right, so update right value
            // If |now wind value| > |before wind value|, update. else, not update => max operation
            v += t;
            r = max(r, v);
            // if l + r > (range) + wind east, so Left snowball will be moved
            // Right snowball's weight: L, Left snowball's weight: (range)-L
            // After that, doesn't remain weight => skip
            while(p<=n && co[p].x <= l+r) {
                ans[co[p].y+1] += l;
                ans[co[p].y] += co[p].x - l;
                ++p;
            }
        }
        else {
            // if t < 0, wind is west direction
            // That means, snowball goes to left, so update left value
            // If |now wind value| > |before wind value|, update. else, not update => max operation
            v += t;
            l = max(l, -v);
            while(p<=n && co[p].x <= l+r) {
                ans[co[p].y] += r;
                ans[co[p].y+1] += co[p].x - r;
                ++p;
            }
        }
    }
    while(p<=n) {
        ans[co[p].y] += r;
        ans[co[p].y + 1] += l;
        ++p;
    }
    for(int i=1; i<=n;i++) printf("%lld\n", ans[i]);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:18:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     for(int i = 1; i<=n;i++) scanf("%lld", &a[i]), co.push_back({a[i]-a[i-1], i-1}); // range
      |                              ~~~~~^~~~~~~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%lld", &t);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 448 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 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 1 ms 468 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 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 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 448 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 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 1 ms 468 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 30 ms 2328 KB Output is correct
21 Correct 28 ms 2208 KB Output is correct
22 Correct 26 ms 1952 KB Output is correct
23 Correct 27 ms 2000 KB Output is correct
24 Correct 39 ms 2800 KB Output is correct
25 Correct 107 ms 12016 KB Output is correct
26 Correct 100 ms 11952 KB Output is correct
27 Correct 111 ms 11552 KB Output is correct
28 Correct 93 ms 11668 KB Output is correct
29 Correct 89 ms 11228 KB Output is correct
30 Correct 91 ms 10616 KB Output is correct
31 Correct 81 ms 9952 KB Output is correct
32 Correct 62 ms 10168 KB Output is correct
33 Correct 9 ms 1616 KB Output is correct
34 Correct 88 ms 12336 KB Output is correct
35 Correct 105 ms 11680 KB Output is correct
36 Correct 96 ms 11940 KB Output is correct
37 Correct 86 ms 11848 KB Output is correct
38 Correct 88 ms 11548 KB Output is correct
39 Correct 89 ms 11800 KB Output is correct
40 Correct 89 ms 11776 KB Output is correct
41 Correct 28 ms 3000 KB Output is correct
42 Correct 76 ms 10104 KB Output is correct
43 Correct 100 ms 13436 KB Output is correct
44 Correct 29 ms 2852 KB Output is correct
45 Correct 104 ms 11672 KB Output is correct
46 Correct 103 ms 13732 KB Output is correct
47 Correct 93 ms 13772 KB Output is correct
48 Correct 94 ms 13944 KB Output is correct