답안 #878070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878070 2023-11-24T04:12:20 Z frostray8653 Snowball (JOI21_ho_t2) C++17
0 / 100
2 ms 8792 KB
// #pragma GCC optimize("Ofast,unroll-loops,O3")
#include <bits/stdc++.h>
#define int long long
// #define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
using namespace std;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) {cout << a << " "; dbg(b...);}
void ent() {cout << "\n";}

const int mod = 998244353;
// const int mod = 1e9 + 7;
// const int INF = 2e9;
const int INF = 9e17;

/// ------- Initialization End -------

const int N = 200005;
int a[N];
int dx[N];
int bestl[N], bestr[N];
int ansl[N], ansr[N];

signed main() {
    IO;
    int n, m;
    cin >> n >> m;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, m) cin >> dx[i];

    int now = 0;
    int lft = 0, rgt = 0;
    FOR(i, 1, m) {
        now += dx[i];
        lft = min(lft, now);
        rgt = max(rgt, now);
        bestl[i] = lft;
        bestr[i] = rgt;
    }
    ansl[1] = a[1] + bestl[m];
    FOR(i, 1, n) {
        if (i == n) {
            ansr[i] = a[i] + bestr[m];
        } else {
            int dif = a[i + 1] - a[i];
            int l = 1, r = m + 1;
            while (l + 1 < r) {
                int mid = (l + r) >> 1;
                if (bestr[mid] - bestl[mid] >= dif)
                    r = mid;
                else
                    l = mid;
            }
            int id = l;
            int len = bestr[id] - bestl[id];
            ansr[i + 0] = a[i + 0] + bestr[id];
            ansl[i + 1] = a[i + 1] + bestl[id];
            if (id < m) {
                if (bestr[id + 1] > bestr[id]) {
                    ansr[i + 0] += dif - len;
                } else {
                    ansl[i + 1] -= dif - len;
                }
            }
        }
    }
    FOR(i, 1, n)
        cout << ansr[i] - ansl[i] << "\n";

    return 0;
}
/*

4 3
-2 3 5 8
2
-4
7

*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:32:5: note: in expansion of macro 'FOR'
   32 |     FOR(i, 1, n) cin >> a[i];
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:33:5: note: in expansion of macro 'FOR'
   33 |     FOR(i, 1, m) cin >> dx[i];
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:37:5: note: in expansion of macro 'FOR'
   37 |     FOR(i, 1, m) {
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 1, n) {
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:71:5: note: in expansion of macro 'FOR'
   71 |     FOR(i, 1, n)
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8664 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8692 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Incorrect 1 ms 8540 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8664 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8692 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Incorrect 1 ms 8540 KB Output isn't correct
15 Halted 0 ms 0 KB -