답안 #988381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988381 2024-05-24T15:00:07 Z _callmelucian Snowball (JOI21_ho_t2) C++14
100 / 100
1652 ms 19776 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 2e5 + 5;
ll x[mn], pre[mn], ansLeft[mn], ansRight[mn];

int soon (vector<pl> &vec, ll targ) {
    auto it = upper_bound(all(vec), make_pair(targ, LLONG_MAX));
    if (it == vec.begin()) return INT_MAX;
    return prev(it)->second;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> x[i];

    vector<pl> lVec(1), rVec(1);
    for (int i = 1; i <= q; i++) {
        ll w; cin >> w;
        pre[i] = pre[i - 1] + w;
        lVec.push_back({pre[i], i});
        rVec.push_back({-pre[i], i});
    }
    sort(all(lVec)); sort(all(rVec));

    for (int i = 1; i < lVec.size(); i++) {
        lVec[i].second = min(lVec[i].second, lVec[i - 1].second);
        rVec[i].second = min(rVec[i].second, rVec[i - 1].second);
    }

    for (int i = 1; i <= n; i++) {
        if (i == 1) {
            ansLeft[i] = rVec.back().first;
            continue;
        }
        int lg = 63 - __builtin_clzll(x[i] - x[i - 1]);
        for (ll mask = (1LL << lg); mask; mask >>= 1) {
            ll tmp = ansLeft[i] | mask, dest = x[i] - tmp;
            ll need = dest - x[i - 1] + 1;
            if (soon(lVec, -tmp) < soon(rVec, -need)) ansLeft[i] |= mask;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (i == n) {
            ansRight[i] = lVec.back().first;
            continue;
        }
        int lg = 63 - __builtin_clzll(x[i + 1] - x[i]);
        for (ll mask = (1LL << lg); mask; mask >>= 1) {
            ll tmp = ansRight[i] | mask, dest = x[i] + tmp;
            ll need = dest - x[i + 1] - 1;
            if (soon(rVec, -tmp) < soon(lVec, need)) ansRight[i] |= mask;
        }
    }

    for (int i = 1; i <= n; i++) {
        //cout << ansLeft[i] << " " << ansRight[i] << " ";
        cout << ansLeft[i] + ansRight[i] << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 1; i < lVec.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2652 KB Output is correct
4 Correct 11 ms 2720 KB Output is correct
5 Correct 13 ms 2648 KB Output is correct
6 Correct 8 ms 2688 KB Output is correct
7 Correct 6 ms 2652 KB Output is correct
8 Correct 8 ms 2648 KB Output is correct
9 Correct 5 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 10 ms 2652 KB Output is correct
16 Correct 11 ms 2568 KB Output is correct
17 Correct 6 ms 2692 KB Output is correct
18 Correct 1 ms 2404 KB Output is correct
19 Correct 2 ms 2528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2652 KB Output is correct
4 Correct 11 ms 2720 KB Output is correct
5 Correct 13 ms 2648 KB Output is correct
6 Correct 8 ms 2688 KB Output is correct
7 Correct 6 ms 2652 KB Output is correct
8 Correct 8 ms 2648 KB Output is correct
9 Correct 5 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 10 ms 2652 KB Output is correct
16 Correct 11 ms 2568 KB Output is correct
17 Correct 6 ms 2692 KB Output is correct
18 Correct 1 ms 2404 KB Output is correct
19 Correct 2 ms 2528 KB Output is correct
20 Correct 51 ms 12704 KB Output is correct
21 Correct 48 ms 12588 KB Output is correct
22 Correct 62 ms 13184 KB Output is correct
23 Correct 65 ms 12188 KB Output is correct
24 Correct 218 ms 13220 KB Output is correct
25 Correct 1652 ms 18832 KB Output is correct
26 Correct 1565 ms 19032 KB Output is correct
27 Correct 1485 ms 18844 KB Output is correct
28 Correct 1449 ms 19136 KB Output is correct
29 Correct 1356 ms 18768 KB Output is correct
30 Correct 742 ms 17512 KB Output is correct
31 Correct 143 ms 16432 KB Output is correct
32 Correct 85 ms 15780 KB Output is correct
33 Correct 120 ms 4292 KB Output is correct
34 Correct 1637 ms 19776 KB Output is correct
35 Correct 1496 ms 18660 KB Output is correct
36 Correct 1611 ms 19092 KB Output is correct
37 Correct 1472 ms 18568 KB Output is correct
38 Correct 1467 ms 17996 KB Output is correct
39 Correct 1463 ms 18860 KB Output is correct
40 Correct 486 ms 18596 KB Output is correct
41 Correct 32 ms 14368 KB Output is correct
42 Correct 448 ms 13608 KB Output is correct
43 Correct 502 ms 18404 KB Output is correct
44 Correct 46 ms 12224 KB Output is correct
45 Correct 417 ms 18084 KB Output is correct
46 Correct 518 ms 18532 KB Output is correct
47 Correct 456 ms 19352 KB Output is correct
48 Correct 472 ms 19504 KB Output is correct