답안 #1099090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099090 2024-10-10T13:55:03 Z Fallout3691 Snowball (JOI21_ho_t2) C++17
100 / 100
2364 ms 21696 KB
#pragma once
#pragma GCC optimize("Ofast, no-stack-protector, unroll-loops, fast-math, 03")
#pragma GCC optimization("03, unroll-loops")
// #pragma GCC target("avx, avx2, fma, bmi, bmi2, popcnt, lzcnt")
// #pragma GCC target("sse, sse2, sse3, ssse3, sse4.1, sse4.2, tune=native")

#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];


    int mn = 0, mx = 0;
    int cur = 0;
    int x;
    map<int, int> mp;
    mp[0] = 0;
    for (int i = 1; i <= q; i++) {
        cin >> x;
        cur += x;
        if (cur < mn) {
            mp[cur] = i;
            mn = cur;
        }
        if (cur > mx) {
            mp[cur] = i;
            mx = cur;
        }
    }

    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;
}

Compilation message

Main.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
Main.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("03, unroll-loops")
      | 
Main.cpp:2:78: warning: bad option '-f no-stack-protector' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize("Ofast, no-stack-protector, unroll-loops, fast-math, 03")
      |                                                                              ^
Main.cpp:2:78: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
Main.cpp:2:78: warning: bad option '-f fast-math' to pragma 'optimize' [-Wpragmas]
Main.cpp:2:78: warning: bad option '-f 03' to pragma 'optimize' [-Wpragmas]
Main.cpp:12:13: warning: bad option '-f no-stack-protector' to attribute 'optimize' [-Wattributes]
   12 | signed main() {
      |             ^
Main.cpp:12:13: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
Main.cpp:12:13: warning: bad option '-f fast-math' to attribute 'optimize' [-Wattributes]
Main.cpp:12:13: warning: bad option '-f 03' to attribute 'optimize' [-Wattributes]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 548 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 13 ms 604 KB Output is correct
5 Correct 9 ms 620 KB Output is correct
6 Correct 9 ms 604 KB Output is correct
7 Correct 8 ms 612 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 6 ms 544 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 0 ms 440 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 11 ms 604 KB Output is correct
16 Correct 10 ms 628 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 6 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 548 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 13 ms 604 KB Output is correct
5 Correct 9 ms 620 KB Output is correct
6 Correct 9 ms 604 KB Output is correct
7 Correct 8 ms 612 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 6 ms 544 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 0 ms 440 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 11 ms 604 KB Output is correct
16 Correct 10 ms 628 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 6 ms 348 KB Output is correct
20 Correct 77 ms 14932 KB Output is correct
21 Correct 76 ms 14676 KB Output is correct
22 Correct 71 ms 14672 KB Output is correct
23 Correct 86 ms 14416 KB Output is correct
24 Correct 282 ms 14784 KB Output is correct
25 Correct 2271 ms 19020 KB Output is correct
26 Correct 2269 ms 18708 KB Output is correct
27 Correct 2220 ms 17748 KB Output is correct
28 Correct 2171 ms 16664 KB Output is correct
29 Correct 1712 ms 11600 KB Output is correct
30 Correct 611 ms 5460 KB Output is correct
31 Correct 309 ms 4912 KB Output is correct
32 Correct 280 ms 5200 KB Output is correct
33 Correct 143 ms 1968 KB Output is correct
34 Correct 1169 ms 7332 KB Output is correct
35 Correct 1420 ms 7468 KB Output is correct
36 Correct 2364 ms 18060 KB Output is correct
37 Correct 2017 ms 15700 KB Output is correct
38 Correct 2153 ms 18256 KB Output is correct
39 Correct 2273 ms 18608 KB Output is correct
40 Correct 775 ms 18356 KB Output is correct
41 Correct 103 ms 15440 KB Output is correct
42 Correct 318 ms 5580 KB Output is correct
43 Correct 1169 ms 21332 KB Output is correct
44 Correct 104 ms 15440 KB Output is correct
45 Correct 1052 ms 18384 KB Output is correct
46 Correct 1419 ms 21392 KB Output is correct
47 Correct 717 ms 13136 KB Output is correct
48 Correct 819 ms 21696 KB Output is correct