답안 #771207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771207 2023-07-02T15:31:06 Z Trisanu_Das Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 488 KB
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define ff first
#define ss second
 
int x[N], now, rmx, lmx, ans[N];
vector<pair<int, int> > v;
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n,q,i,j,w;
	cin >> n >> q;
	x[0] = INT_MIN, x[n+1] = INT_MAX;
	for(i = 1;i <= n + 1; i++){
		if(i <= n) cin >> x[i];
		v.push_back({x[i] - x[i - 1], i - 1});
	}
	sort(v.begin(), v.end());
	i = 0;
	while(q--){
		cin >> w;
		now += w;
		rmx = max(now, rmx), lmx = min(now, lmx);
		while(rmx - lmx >= v[i].ff){
			if(w > 0) ans[v[i].ss] += v[i].ff + lmx, ans[v[i].ss+1] -= lmx;
			else ans[v[i].ss] += rmx, ans[v[i].ss + 1] += v[i].ff - rmx;
			i++;
		}
	}
	while(i < v.size()){
		ans[v[i].ss] += rmx, ans[v[i].ss + 1] -= lmx;
		i++;
	}
	for(i = 1; i <= n; i++) cout << ans[i] << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:30:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  while(i < v.size()){
      |        ~~^~~~~~~~~~
Main.cpp:11:12: warning: unused variable 'j' [-Wunused-variable]
   11 |  int n,q,i,j,w;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -