제출 #1277659

#제출 시각아이디문제언어결과실행 시간메모리
1277659icebearSnowball (JOI21_ho_t2)C++20
33 / 100
2591 ms836 KiB
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class T>
    bool minimize(T &a, const T &b) {
        if (a > b) return a = b, true;
        return false;
    }

template<class T>
    bool maximize(T &a, const T &b) {
        if (a < b) return a = b, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/** END OF TEMPLATE. ICEBEAR AND CAT WILL WIN VOI26 **/

const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, q;
ll X[N], L[N], R[N], ans[N];

void init(void) {
    cin >> n >> q;
    FOR(i, 1, n) cin >> X[i], L[i] = R[i] = X[i];
}

void process(void) {
    R[0] = -INF;
    L[n + 1] = INF;
    while(q--) {
        ll W;
        cin >> W;
        if (W < 0) {
            FOR(i, 1, n) {
                ll nxt = X[i] + W;
                ans[i] += max(0ll, L[i] - max(R[i - 1], nxt));
                X[i] = nxt;
                minimize(L[i], X[i]);
            }
        } else {
            FOR(i, 1, n) {
                ll nxt = X[i] + W;
                ans[i] += max(0ll, min(L[i + 1], nxt) - R[i]);
                X[i] = nxt;
                maximize(R[i], X[i]);
            }
        }
//        FOR(i, 1, n) cout << X[i] << ' ' << L[i] << ' ' << R[i] << ' ' << ans[i] << '\n';
    }
    FOR(i, 1, n) cout << ans[i] << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while(tc--) {
        init();
        process();
    }
    return 0;
}

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

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