답안 #586857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586857 2022-06-30T19:57:06 Z TheEvilBird Snowball (JOI21_ho_t2) C++17
33 / 100
819 ms 20852 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

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;
    }
    debug(go_left, go_right);
    debug(l);
    debug(r);
    vector<ll> ans(n + 2, 0);
    for (int i = 1; i < n + 2; ++i) {
        if (r[i - 1] <= l[i] || (r[i - 1] == x[i - 1] && l[i] <= x[i - 1])) {
            ans[i - 1] += go_right;
            ans[i] += abs(go_left);
        }
        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);
        }
    }
    debug(ans);
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << en;
    }
}

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

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:45:20: warning: statement has no effect [-Wunused-value]
   45 | #define debug(...) 42
      |                    ^~
Main.cpp:79:5: note: in expansion of macro 'debug'
   79 |     debug(go_left, go_right);
      |     ^~~~~
Main.cpp:45:20: warning: statement has no effect [-Wunused-value]
   45 | #define debug(...) 42
      |                    ^~
Main.cpp:80:5: note: in expansion of macro 'debug'
   80 |     debug(l);
      |     ^~~~~
Main.cpp:45:20: warning: statement has no effect [-Wunused-value]
   45 | #define debug(...) 42
      |                    ^~
Main.cpp:81:5: note: in expansion of macro 'debug'
   81 |     debug(r);
      |     ^~~~~
Main.cpp:45:20: warning: statement has no effect [-Wunused-value]
   45 | #define debug(...) 42
      |                    ^~
Main.cpp:107:5: note: in expansion of macro 'debug'
  107 |     debug(ans);
      |     ^~~~~
# 결과 실행 시간 메모리 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 6 ms 468 KB Output is correct
5 Correct 5 ms 476 KB Output is correct
6 Correct 4 ms 388 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 3 ms 468 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 1 ms 212 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 484 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 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 6 ms 468 KB Output is correct
5 Correct 5 ms 476 KB Output is correct
6 Correct 4 ms 388 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 3 ms 468 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 1 ms 212 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 484 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 30 ms 7092 KB Output is correct
21 Correct 27 ms 6700 KB Output is correct
22 Correct 27 ms 6396 KB Output is correct
23 Correct 31 ms 6360 KB Output is correct
24 Correct 107 ms 6796 KB Output is correct
25 Correct 810 ms 16540 KB Output is correct
26 Correct 807 ms 16380 KB Output is correct
27 Correct 723 ms 15652 KB Output is correct
28 Correct 680 ms 15752 KB Output is correct
29 Correct 560 ms 14112 KB Output is correct
30 Correct 211 ms 12108 KB Output is correct
31 Correct 59 ms 11504 KB Output is correct
32 Correct 51 ms 11644 KB Output is correct
33 Correct 62 ms 1916 KB Output is correct
34 Correct 464 ms 13892 KB Output is correct
35 Correct 531 ms 13520 KB Output is correct
36 Correct 819 ms 16508 KB Output is correct
37 Correct 708 ms 15476 KB Output is correct
38 Correct 764 ms 15936 KB Output is correct
39 Correct 759 ms 15840 KB Output is correct
40 Correct 369 ms 16068 KB Output is correct
41 Correct 35 ms 8000 KB Output is correct
42 Correct 56 ms 11632 KB Output is correct
43 Correct 338 ms 18000 KB Output is correct
44 Correct 34 ms 7472 KB Output is correct
45 Correct 64 ms 15972 KB Output is correct
46 Correct 335 ms 18156 KB Output is correct
47 Correct 303 ms 16616 KB Output is correct
48 Incorrect 117 ms 20852 KB Output isn't correct
49 Halted 0 ms 0 KB -