답안 #532547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532547 2022-03-03T06:55:27 Z Nanashi_Panda Snowball (JOI21_ho_t2) C++14
0 / 100
1 ms 316 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define jizz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define ll long long
using namespace std;
ll n, q;
ll x[200005];
ll h[200005];
ll rag[200005][2];
ll ans[200005];
struct line{
	ll i, v;
};
vector <line> val;
vector <line>::iterator it;
bool operator <(line a, line b){
	return a.v<b.v;
}

int main() {
	scanf("%lld%lld", &n, &q);
	for(ll i = 0; i < n; i++) scanf("%lld", x+i);
	for(ll i = 0; i < q; i++) scanf("%lld", h+i);
	ll now = 0;
	for(ll i = 1; i <= q; i++){
		now+=h[i-1];
		rag[i][0] = min(rag[i-1][0], now);
		rag[i][1] = max(rag[i-1][1], now);
	}
	for(ll i = 0; i < n-1; i++){
		val.push_back({i,x[i+1]-x[i]});
	}
	sort(val.begin(), val.end());
	ll ind = 0;
	if(n>1){
		for(ll i = 1; i <= q; i++){
			while(val[ind].v<rag[i][1]-rag[i][0]){
				ans[val[ind].i]+=rag[i-1][1];
				ans[val[ind].i+1]-=rag[i-1][0];
				if(h[i-1]>0){
					ans[val[ind].i]+=val[ind].v-rag[i-1][1]+rag[i-1][0];
				}else{
					ans[val[ind].i+1]+=val[ind].v-rag[i-1][1]+rag[i-1][0];
				}
				ind++;
				if(ind>=n-1) break;
			}
		}
		for(ll i = ind; i < n-1; i++){
			ans[val[i].i]+=rag[q][1];
			ans[val[i].i+1]-=rag[q][0];
		}
	}
	ans[n-1]+=rag[q][1];
	ans[0]-=rag[q][0];
	for(ll i = 0; i < n; i++) printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%lld%lld", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:24:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  for(ll i = 0; i < n; i++) scanf("%lld", x+i);
      |                            ~~~~~^~~~~~~~~~~~~
Main.cpp:25:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  for(ll i = 0; i < q; i++) scanf("%lld", h+i);
      |                            ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -