제출 #1252471

#제출 시각아이디문제언어결과실행 시간메모리
1252471minggaSnowball (JOI21_ho_t2)C++20
100 / 100
84 ms6824 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 2e5 + 7;
int n, q, a[N], lef[N], rig[N];

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int cur = 0;
	for(int i = 1; i <= q; i++) {
		int x; cin >> x;
		cur += x;
		lef[i] = min(lef[i - 1], cur);
		rig[i] = max(rig[i - 1], cur);
	}
	lef[q + 1] = lef[q];
	rig[q + 1] = rig[q];
	for(int i = 1; i <= n; i++) {
		int ans = 0;
		if(i != n) {
			int l = 0, r = q, lst = 0;
			while(l <= r) {
				int m = (l + r) >> 1;
				if(a[i] + rig[m] <= a[i + 1] + lef[m]) {
					l = m + 1;
					lst = m;
				} else r = m - 1;
			}
			if(lst == q) {
				ans += rig[lst];
			} else  ans += max(rig[lst], a[i + 1] + lef[lst + 1] - a[i]);
		} else ans += rig[q];
		if(i != 1) {
			int l = 0, r = q, lst = 0;
			while(l <= r) {
				int m = (l + r) >> 1;
				if(a[i] + lef[m] >= a[i - 1] + rig[m]) {
					l = m + 1;
					lst = m;
				} else r = m - 1;
			}
			if(lst == q) ans += abs(lef[lst]);
			else ans += max(abs(lef[lst]), a[i] - a[i - 1] - rig[lst + 1]);
		} else ans += abs(lef[q]);
		cout << ans << ln;
	}
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

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

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