제출 #1343746

#제출 시각아이디문제언어결과실행 시간메모리
1343746dex111222333444555Snowball (JOI21_ho_t2)C++20
100 / 100
97 ms13068 KiB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) ((int)(v).size())
#define all(v) begin((v)), end(v)
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define dbg(x) "[" #x " = " << x << "]"
#define lli pair<long long, int>
#define left __left
#define right __right

using namespace std;

const int MAXN = 2e5 + 5, MAXK = 16, LOG = 20, infINT = 1e9 + 23737;
const long long inf = 1e18 + 5;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}

int numPos, numQuery;
long long pos[MAXN], query[MAXN];

void input(){
    cin >> numPos >> numQuery;
    for(int i = 1; i <= numPos; i++) cin >> pos[i];
    for(int q = 1; q <= numQuery; q++) cin >> query[q];
}

namespace sub1{
    bool checkSub(){
        return max(numPos, numQuery) <= 2000;
    }

    long long left[MAXN], right[MAXN], cur[MAXN];

    void solve(){
        right[0] = -inf;
        left[numPos + 1] = inf;

        for(int i = 1; i <= numPos; i++){
            cur[i] = pos[i];
            left[i] = cur[i];
            right[i] = cur[i];
        }

        for(int q = 1; q <= numQuery; q++){
            if (query[q] == 0) continue;

            if (query[q] > 0){
                for(int i = 1; i <= numPos; i++){
                    right[i] = min(left[i + 1], cur[i] + query[q]);
                }
            }

            if (query[q] < 0){
                for(int i = 1; i <= numPos; i++){
                    left[i] = max(right[i - 1], cur[i] + query[q]);
                }
            }

            for(int i = 1; i <= numPos; i++){
                cur[i] += query[q];
            }
        }

        for(int i = 1; i <= numPos; i++){
            cout << right[i] - left[i] << '\n';
        }
    }
}

namespace sub2{
    bool checkSub(){
        return 1;
    }

    long long left[MAXN], right[MAXN], cur[MAXN], bestleft[MAXN], bestright[MAXN];

    void solve(){
        for(int i = 1; i <= numQuery + 1; i++){
            cur[i] = cur[i - 1] + query[i];
            bestleft[i] = min(bestleft[i - 1], cur[i]);
            bestright[i] = max(bestright[i - 1], cur[i]);
        }

        pos[0] = -inf;
        pos[numPos + 1] = inf;

        for(int i = 1; i <= numPos; i++){
            int l, m, r, best;

            l = 1, r = numQuery, best = 0;
            while(l <= r){
                m = (l + r) >> 1;
                if (pos[i] + bestright[m] <= pos[i + 1] + bestleft[m - 1]){
                    best = m;
                    l = m + 1;
                }else{
                    r = m - 1;
                }
            }

            right[i] = max(pos[i] + bestright[best],
                           min(pos[i] + bestright[best + 1], pos[i + 1] + bestleft[best]));

            l = 1, r = numQuery, best = 0;
            while(l <= r){
                m = (l + r) >> 1;
                if (pos[i] + bestleft[m] >= pos[i - 1] + bestright[m - 1]){
                    best = m;
                    l = m + 1;
                }else{
                    r = m - 1;
                }
            }

            left[i] = min(pos[i] + bestleft[best],
                          max(pos[i] + bestleft[best + 1], pos[i - 1] + bestright[best]));

            cout << right[i] - left[i] << '\n';
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while(t--){
        input();
//        if (sub1::checkSub()) sub1::solve();
        if (sub2::checkSub()) sub2::solve();
    }
    cerr << TIME << ".s\n";
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:136:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...