답안 #706141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706141 2023-03-06T01:17:12 Z becaido Snowball (JOI21_ho_t2) C++17
100 / 100
101 ms 17016 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define int long long
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2e5 + 5;

int n, q;
int x[SIZE], delta[SIZE], ans[SIZE];
int mxl, mxr;
vector<tuple<int, int, int>> v;

pair<int, int> cal(int len) {
    int pos = lower_bound(v.begin(), v.end(), make_tuple(len, LLONG_MIN, 0)) - v.begin();
    if (pos == v.size()) return {mxr, mxl};
    auto [tot, val, ty] = v[pos];
    if (ty == 0) return {val, len - val};
    else return {len - val, val};
}

void solve() {
    cin >> n >> q;
    FOR (i, 1, n) cin >> x[i];
    FOR (i, 1, q) {
        int w;
        cin >> w;
        delta[i] = delta[i - 1] + w;
    }
    FOR (i, 1, q) {
        if (delta[i] > 0) {
            if (delta[i] > mxr) {
                mxr = delta[i];
                v.pb(mxl + mxr, mxl, 1);
            }
        }
        if (delta[i] < 0) {
            if (-delta[i] > mxl) {
                mxl = -delta[i];
                v.pb(mxl + mxr, mxr, 0);
            }
        }
    }
    FOR (i, 1, n - 1) {
        auto [vl, vr] = cal(x[i + 1] - x[i]);
        ans[i] += vl;
        ans[i + 1] += vr;
    }
    ans[1] += mxl;
    ans[n] += mxr;
    FOR (i, 1, n) cout << ans[i] << '\n';
}

int32_t main() {
    Waimai;
    solve();
}

Compilation message

Main.cpp: In function 'std::pair<long long int, long long int> cal(long long int)':
Main.cpp:32:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if (pos == v.size()) return {mxr, mxl};
      |         ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 488 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 488 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 36 ms 10208 KB Output is correct
21 Correct 29 ms 10100 KB Output is correct
22 Correct 28 ms 9888 KB Output is correct
23 Correct 26 ms 9784 KB Output is correct
24 Correct 31 ms 9900 KB Output is correct
25 Correct 98 ms 15124 KB Output is correct
26 Correct 100 ms 15088 KB Output is correct
27 Correct 95 ms 14252 KB Output is correct
28 Correct 93 ms 14092 KB Output is correct
29 Correct 86 ms 11752 KB Output is correct
30 Correct 66 ms 9012 KB Output is correct
31 Correct 53 ms 8296 KB Output is correct
32 Correct 48 ms 8516 KB Output is correct
33 Correct 9 ms 1872 KB Output is correct
34 Correct 76 ms 10892 KB Output is correct
35 Correct 78 ms 10616 KB Output is correct
36 Correct 101 ms 14716 KB Output is correct
37 Correct 90 ms 13460 KB Output is correct
38 Correct 93 ms 14320 KB Output is correct
39 Correct 99 ms 14472 KB Output is correct
40 Correct 71 ms 14404 KB Output is correct
41 Correct 29 ms 10812 KB Output is correct
42 Correct 46 ms 8524 KB Output is correct
43 Correct 75 ms 16568 KB Output is correct
44 Correct 29 ms 10744 KB Output is correct
45 Correct 63 ms 14400 KB Output is correct
46 Correct 73 ms 16788 KB Output is correct
47 Correct 77 ms 13820 KB Output is correct
48 Correct 82 ms 17016 KB Output is correct