Submission #1099070

# Submission time Handle Problem Language Result Execution time Memory
1099070 2024-10-10T13:06:28 Z Fallout3691 Snowball (JOI21_ho_t2) C++17
100 / 100
2319 ms 24660 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n + 2);
    a[0] = -1e18, a[n + 1] = 1e18;
    for (int i = 1; i <= n; i++)
        cin >> a[i];


    vector<int> m(q + 1);
    vector<int> pref(q + 1);
    map<int, int> mp;
    mp[0] = 0;
    for (int i = 1; i <= q; i++) {
        cin >> m[i];
        pref[i] += pref[i - 1] + m[i];
        if (mp.find(pref[i]) != mp.end())
            continue;
        if (pref[i] > 0) {
            auto it = mp.upper_bound(pref[i]);
            if (it == mp.end())
                mp[pref[i]] = i;
        }
        else {
            auto it = mp.lower_bound(pref[i]);
            if (it == mp.begin())
                mp[pref[i]] = i;
        }
    }

    for (int i = 1; i <= n; i++) {
        int left = a[i], right = a[i];
        {
            int l = a[i - 1], r = a[i];
            while (r - l > 1) {
                int mid = (l + r) / 2;
                int x = mid - a[i];
                int y = mid - a[i - 1];
                auto it1 = mp.upper_bound(x);
                if (it1 == mp.begin()) {
                    l = mid;
                    continue;
                }
                --it1;
                auto it2 = mp.lower_bound(y);
                if (it2 == mp.end()) {
                    r = mid;
                    continue;
                }
                if ((it1 -> second) < (it2 -> second))
                    r = mid;
                else
                    l = mid;
            }
            auto it1 = mp.upper_bound(r - 1 - a[i]);
            auto it2 = mp.lower_bound(r - a[i - 1]);
            if ((it1 != mp.begin()) && ((it2 == mp.end()) ||((--it1) -> second < it2 -> second)))
                r--;
            left = r;
        }
        {
            int l = a[i], r = a[i + 1];
            while (r - l > 1) {
                int mid = (l + r) / 2;
                int x = mid - a[i];
                int y = mid - a[i + 1];
                auto it1 = mp.lower_bound(x);
                if (it1 == mp.end()) {
                    r = mid;
                    continue;
                }
                auto it2 = mp.upper_bound(y);
                if (it2 == mp.begin()) {
                    l = mid;
                    continue;
                }
                --it2;
                if ((it1 -> second) < (it2 -> second))
                    l = mid;
                else
                    r = mid;
            }
            auto it1 = mp.lower_bound(l + 1 - a[i]);
            auto it2 = mp.upper_bound(l - a[i + 1]);
            if ((it1 != mp.end()) && ((it2 == mp.begin() || (it1 -> second < (--it2) -> second))))
                l++;
            right = l;
        }
        cout << right - left << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 552 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 11 ms 604 KB Output is correct
5 Correct 10 ms 604 KB Output is correct
6 Correct 9 ms 644 KB Output is correct
7 Correct 8 ms 604 KB Output is correct
8 Correct 8 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 11 ms 660 KB Output is correct
16 Correct 10 ms 664 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 552 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 11 ms 604 KB Output is correct
5 Correct 10 ms 604 KB Output is correct
6 Correct 9 ms 644 KB Output is correct
7 Correct 8 ms 604 KB Output is correct
8 Correct 8 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 11 ms 660 KB Output is correct
16 Correct 10 ms 664 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 94 ms 18000 KB Output is correct
21 Correct 94 ms 17900 KB Output is correct
22 Correct 93 ms 17648 KB Output is correct
23 Correct 113 ms 17488 KB Output is correct
24 Correct 325 ms 18004 KB Output is correct
25 Correct 2319 ms 22864 KB Output is correct
26 Correct 2246 ms 22544 KB Output is correct
27 Correct 2168 ms 21328 KB Output is correct
28 Correct 2077 ms 20288 KB Output is correct
29 Correct 1726 ms 15040 KB Output is correct
30 Correct 624 ms 9028 KB Output is correct
31 Correct 331 ms 8372 KB Output is correct
32 Correct 281 ms 8532 KB Output is correct
33 Correct 150 ms 2392 KB Output is correct
34 Correct 1092 ms 11072 KB Output is correct
35 Correct 1318 ms 11092 KB Output is correct
36 Correct 2307 ms 21828 KB Output is correct
37 Correct 2065 ms 18736 KB Output is correct
38 Correct 2254 ms 21328 KB Output is correct
39 Correct 2148 ms 21552 KB Output is correct
40 Correct 750 ms 21452 KB Output is correct
41 Correct 145 ms 18768 KB Output is correct
42 Correct 361 ms 8532 KB Output is correct
43 Correct 1169 ms 24404 KB Output is correct
44 Correct 161 ms 18512 KB Output is correct
45 Correct 1154 ms 21496 KB Output is correct
46 Correct 1435 ms 24400 KB Output is correct
47 Correct 744 ms 16392 KB Output is correct
48 Correct 806 ms 24660 KB Output is correct