답안 #774092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774092 2023-07-05T12:00:15 Z RecursiveCo Snowball (JOI21_ho_t2) C++14
100 / 100
979 ms 14004 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long int

signed main() {
    improvePerformance;
    get(n);
    get(q);
    getList(n, pos);
    getList(q, days);
    vector<pair<int, int>> segs;
    int pref = 0;
    forto(q, i) {
        pref += days[i];
        if (i == 0) {
            if (days[i] > 0) segs.push_back({0, days[i]});
            else segs.push_back({days[i], 0});
        } else {
            if (days[i] > 0) segs.push_back({segs.back().first, max(segs.back().second, pref)});
            else segs.push_back({min(segs.back().first, pref), segs.back().second});
        }
    }
    forto(n, i) pos[i] += 1e12;
    forto(n, i) {
        int left = 0;
        int right = 0;
        if (i == 0) {
            left = -segs.back().first;
        } else {
            int l = pos[i - 1];
            int r = pos[i];
            while (r - l >= 1) {
                int middle = (l + r) / 2;
                // was middle already taken by the time we wanted to take it?
                int l1 = 0;
                int r1 = q;
                while (r1 - l1 >= 1) {
                    int middle1 = (l1 + r1) / 2;
                    if (segs[middle1].first + pos[i] <= middle) r1 = middle1;
                    else l1 = middle1 + 1;
                }
                if (r1 == q) {
                    l = middle + 1;
                    continue;
                }
                if (segs[r1].second + pos[i - 1] > middle) l = middle + 1;
                else r = middle;
            }
            left = pos[i] - l;
        }
        if (i == n - 1) {
            right = segs.back().second;
        } else {
            int l = pos[i];
            int r = pos[i + 1] + 1;
            while (r - l > 1) {
                int middle = (l + r) / 2;
                // was middle already taken by the time we wanted to take it?
                int l1 = 0;
                int r1 = q;
                while (r1 - l1 >= 1) {
                    int middle1 = (l1 + r1) / 2;
                    if (middle <= pos[i] + segs[middle1].second) r1 = middle1;
                    else l1 = middle1 + 1;
                }
                if (r1 == q) {
                    r = middle;
                    continue;
                }
                if (segs[r1].first + pos[i + 1] < middle) r = middle;
                else l = middle;
            }
            right = l - pos[i];
        }
        out(left + right);
        out("\n");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:22:5: note: in expansion of macro 'get'
   22 |     get(n);
      |     ^~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'q' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:23:5: note: in expansion of macro 'get'
   23 |     get(q);
      |     ^~~
Main.cpp:12:40: warning: unnecessary parentheses in declaration of 'pos' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
Main.cpp:24:5: note: in expansion of macro 'getList'
   24 |     getList(n, pos);
      |     ^~~~~~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
Main.cpp:24:5: note: in expansion of macro 'getList'
   24 |     getList(n, pos);
      |     ^~~~~~~
Main.cpp:12:40: warning: unnecessary parentheses in declaration of 'days' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
Main.cpp:25:5: note: in expansion of macro 'getList'
   25 |     getList(q, days);
      |     ^~~~~~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
Main.cpp:25:5: note: in expansion of macro 'getList'
   25 |     getList(q, days);
      |     ^~~~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:28:5: note: in expansion of macro 'forto'
   28 |     forto(q, i) {
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:38:5: note: in expansion of macro 'forto'
   38 |     forto(n, i) pos[i] += 1e12;
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:39:5: note: in expansion of macro 'forto'
   39 |     forto(n, i) {
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 460 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 7 ms 456 KB Output is correct
16 Correct 6 ms 476 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 460 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 7 ms 456 KB Output is correct
16 Correct 6 ms 476 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 24 ms 8264 KB Output is correct
21 Correct 23 ms 8000 KB Output is correct
22 Correct 23 ms 7864 KB Output is correct
23 Correct 31 ms 7612 KB Output is correct
24 Correct 116 ms 7808 KB Output is correct
25 Correct 979 ms 11972 KB Output is correct
26 Correct 958 ms 12076 KB Output is correct
27 Correct 868 ms 11632 KB Output is correct
28 Correct 863 ms 11796 KB Output is correct
29 Correct 780 ms 11376 KB Output is correct
30 Correct 530 ms 10828 KB Output is correct
31 Correct 86 ms 10584 KB Output is correct
32 Correct 54 ms 10812 KB Output is correct
33 Correct 79 ms 1616 KB Output is correct
34 Correct 845 ms 12344 KB Output is correct
35 Correct 839 ms 11704 KB Output is correct
36 Correct 959 ms 11956 KB Output is correct
37 Correct 886 ms 11772 KB Output is correct
38 Correct 896 ms 11636 KB Output is correct
39 Correct 865 ms 11788 KB Output is correct
40 Correct 291 ms 11880 KB Output is correct
41 Correct 25 ms 8776 KB Output is correct
42 Correct 245 ms 10820 KB Output is correct
43 Correct 321 ms 13468 KB Output is correct
44 Correct 24 ms 8744 KB Output is correct
45 Correct 530 ms 11752 KB Output is correct
46 Correct 322 ms 13676 KB Output is correct
47 Correct 316 ms 13904 KB Output is correct
48 Correct 329 ms 14004 KB Output is correct