답안 #586871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586871 2022-06-30T20:54:31 Z TheEvilBird Snowball (JOI21_ho_t2) C++17
100 / 100
830 ms 13188 KB
#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <numeric>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <chrono>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128_t int128;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const char en = '\n';
const int INF = 1e9 + 7;
const ll INFLL = 1e18;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

#ifdef __APPLE__
#include "debug.h"
//#define debug(...) 42
#else
#define debug(...) 42
#endif

//#define int ll

void solve() {
    int n, q;
    cin >> n >> q;
    vector<ll> x(n + 2), qs(q);
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    x[0] = -INFLL;
    x[n + 1] = INFLL;
    ll go_left = 0, go_right = 0, d = 0;
    vector<ll> jumps_left(1, 0), jumps_right(1, 0);
    vector<int> id_left(1, -1), id_right(1, -1);
    for (int i = 0; i < q; ++i) {
        cin >> qs[i];
        d += qs[i];
        if (d < go_left) {
            go_left = d;
            jumps_left.emplace_back(abs(d));
            id_left.emplace_back(i);
        }
        if (d > go_right) {
            go_right = d;
            jumps_right.emplace_back(d);
            id_right.emplace_back(i);
        }
    }
    vector<ll> l(n + 2), r(n + 2);
    for (int i = 0; i < n + 2; ++i) {
        l[i] = x[i] + go_left;
        r[i] = x[i] + go_right;
    }
    vector<ll> ans(n + 2, 0);
    ans[1] += abs(go_left);
    ans[n] += go_right;
    for (int i = 2; i <= n; ++i) {
        if (i == 984) {
            int lfasdf = 0;
        }
        if (r[i - 1] <= l[i]) {
            ans[i - 1] += go_right;
            ans[i] += abs(go_left);
        }
        else if (r[i - 1] == x[i - 1] && l[i] <= x[i - 1]) {
            ans[i - 1] += go_right;
            ans[i] += (x[i] - x[i - 1]);
        }
        else {
            ll lx = l[i], rx = min(r[i - 1], x[i]) + 1;
            ans[i - 1] += (lx - x[i - 1]);
            while (rx - lx > 1) {
                ll mx = lx + (rx - lx) / 2;
                int id1 = (int)(lower_bound(all(jumps_right), mx - x[i - 1]) - jumps_right.begin());
                int id2 = (int)(lower_bound(all(jumps_left), x[i] - mx + 1) - jumps_left.begin());
                int ev1 = id_right[id1], ev2 = id_left[id2];
                if (ev1 < ev2) {
                    lx = mx;
                }
                else {
                    rx = mx;
                }
            }
            ans[i - 1] += (lx - l[i]);
            ans[i] += (x[i] - lx);
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << en;
    }
}

int32_t main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:86:17: warning: unused variable 'lfasdf' [-Wunused-variable]
   86 |             int lfasdf = 0;
      |                 ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 4 ms 420 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 4 ms 432 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 4 ms 420 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 4 ms 432 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 26 ms 4928 KB Output is correct
21 Correct 25 ms 4812 KB Output is correct
22 Correct 26 ms 4736 KB Output is correct
23 Correct 31 ms 4776 KB Output is correct
24 Correct 123 ms 5116 KB Output is correct
25 Correct 830 ms 12796 KB Output is correct
26 Correct 760 ms 12704 KB Output is correct
27 Correct 699 ms 12108 KB Output is correct
28 Correct 668 ms 12084 KB Output is correct
29 Correct 558 ms 10720 KB Output is correct
30 Correct 192 ms 9064 KB Output is correct
31 Correct 56 ms 8524 KB Output is correct
32 Correct 63 ms 8444 KB Output is correct
33 Correct 57 ms 1512 KB Output is correct
34 Correct 440 ms 9808 KB Output is correct
35 Correct 521 ms 9932 KB Output is correct
36 Correct 784 ms 12792 KB Output is correct
37 Correct 690 ms 11912 KB Output is correct
38 Correct 735 ms 12348 KB Output is correct
39 Correct 711 ms 12112 KB Output is correct
40 Correct 337 ms 12344 KB Output is correct
41 Correct 30 ms 5220 KB Output is correct
42 Correct 48 ms 8424 KB Output is correct
43 Correct 322 ms 12764 KB Output is correct
44 Correct 28 ms 4928 KB Output is correct
45 Correct 60 ms 12396 KB Output is correct
46 Correct 328 ms 12860 KB Output is correct
47 Correct 265 ms 11100 KB Output is correct
48 Correct 71 ms 13188 KB Output is correct