답안 #602227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602227 2022-07-22T17:57:15 Z Tigryonochekk Snowball (JOI21_ho_t2) C++17
100 / 100
237 ms 13088 KB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define pll pair<long long, long long>
const int N = 2e5 + 2;
const long long inf = 1e18 + 49;

int n, q;
long long x[N];
long long w[N];
vector<pll> v;
long long /*dif[N],*/ lef[N], rig[N];
long long ans[N];

int main() {
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	long long mx = 0, mn = 0;
	for (int i = 1; i <= q; i++) {
		cin >> w[i];
		w[i] += w[i - 1];
		mn = min(w[i], mn);
		mx = max(w[i], mn);
	}
	for (int i = 1; i < n; i++) {
		v.push_back(pll(x[i + 1] - x[i], i));
	}
	sort(v.begin(), v.end());
	int pnt = 0;
	long long cmx = 0, cmn = 0;
	for (int i = 1; i <= q; i++) {
		cmx = max(cmx, w[i]);
		cmn = min(cmn, w[i]);
		long long cur = cmx - cmn;
		while (pnt < v.size() && cur >= v[pnt].first) {
			long long dif = v[pnt].first;
			int ind = v[pnt].second;
			if (w[i] < 0) {
				lef[ind] = cmx;
				rig[ind] = dif - cmx;
			}
			else {
				rig[ind] = -cmn;
				lef[ind] = dif + cmn;
			}
			pnt++;
		}
	}
	for (; pnt < v.size(); pnt++) {
		int ind = v[pnt].second;
		lef[ind] = cmx;
		rig[ind] = -cmn;
	}
	ans[1] += -cmn;
	ans[n] += cmx;
	for (int i = 1; i < n; i++) {
		ans[i] += lef[i];
		ans[i + 1] += rig[i];
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:42:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   while (pnt < v.size() && cur >= v[pnt].first) {
      |          ~~~~^~~~~~~~~~
Main.cpp:56:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (; pnt < v.size(); pnt++) {
      |         ~~~~^~~~~~~~~~
Main.cpp:25:12: warning: variable 'mx' set but not used [-Wunused-but-set-variable]
   25 |  long long mx = 0, mn = 0;
      |            ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 244 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 244 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 76 ms 1820 KB Output is correct
21 Correct 72 ms 1864 KB Output is correct
22 Correct 65 ms 1836 KB Output is correct
23 Correct 61 ms 1900 KB Output is correct
24 Correct 67 ms 3064 KB Output is correct
25 Correct 175 ms 12976 KB Output is correct
26 Correct 173 ms 12968 KB Output is correct
27 Correct 167 ms 12668 KB Output is correct
28 Correct 174 ms 12688 KB Output is correct
29 Correct 167 ms 12488 KB Output is correct
30 Correct 159 ms 12216 KB Output is correct
31 Correct 155 ms 11756 KB Output is correct
32 Correct 143 ms 11716 KB Output is correct
33 Correct 19 ms 1700 KB Output is correct
34 Correct 187 ms 12956 KB Output is correct
35 Correct 175 ms 12744 KB Output is correct
36 Correct 172 ms 12972 KB Output is correct
37 Correct 172 ms 12756 KB Output is correct
38 Correct 175 ms 12760 KB Output is correct
39 Correct 179 ms 12732 KB Output is correct
40 Correct 178 ms 12752 KB Output is correct
41 Correct 94 ms 1872 KB Output is correct
42 Correct 155 ms 11772 KB Output is correct
43 Correct 202 ms 12928 KB Output is correct
44 Correct 91 ms 1832 KB Output is correct
45 Correct 177 ms 12868 KB Output is correct
46 Correct 206 ms 13088 KB Output is correct
47 Correct 211 ms 12976 KB Output is correct
48 Correct 237 ms 13048 KB Output is correct