Submission #711208

# Submission time Handle Problem Language Result Execution time Memory
711208 2023-03-16T10:02:39 Z yellowtoad Snowball (JOI21_ho_t2) C++17
0 / 100
6 ms 452 KB
#include <iostream>
#include <vector>
using namespace std;

long long n, test, a[200010], cur, x, minn, maxx, b[200010], l, r, mid, ans[200010];
vector<long long> v;

int main() {
	cin >> n >> test;
	for (int i = 1; i <= n; i++) cin >> a[i];
	v.push_back(0);
	while (test--) {
		cin >> x;
		cur += x;
		if (cur > maxx) {
			if (v.back() <= 0) v.push_back(cur);
			else v.back() = cur;
			maxx = cur;
		} else if (cur < minn) {
			if (v.back() >= 0) v.push_back(cur);
			else v.back() = cur;
			minn = cur;
		}
	}
	for (int i = 1; i < v.size(); i++) b[i] = abs(v[i-1]-v[i]);
	ans[1] -= minn;
	for (int i = 2; i <= n; i++) {
		l = 1; r = v.size()-1;
		while (l <= r) {
			int mid = (l+r)/2;
			if (a[i]-a[i-1] <= b[mid]) r = mid-1;
			else l = mid+1;
		}
		if (r < v.size()-1) {
			r++;
			if (v[r-1] < 0) ans[i] -= max(a[i-1]-a[i],v[r-1]);
			else ans[i-1] += min(a[i]-a[i-1],v[r-1]);
			if (v[r] < 0) ans[i] -= max(a[i-1]+min(a[i]-a[i-1],v[r-1])-a[i],v[r]);
			else ans[i-1] += min(a[i]+max(a[i-1]-a[i],v[r-1])-a[i-1],v[r]);
		} else {
			if (v[r-1] < 0) ans[i] -= max(a[i-1]-a[i],v[r-1]);
			else ans[i-1] += min(a[i]-a[i-1],v[r-1]);
			if (v[r] < 0) ans[i] -= max(a[i-1]+min(a[i]-a[i-1],v[r-1])-a[i],v[r]);
			else ans[i-1] += min(a[i]+max(a[i-1]-a[i],v[r-1])-a[i-1],v[r]);
		}
	}
	ans[n] += maxx;
	for (int i = 1; i <= n; i++) cout << ans[i] << endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = 1; i < v.size(); i++) b[i] = abs(v[i-1]-v[i]);
      |                  ~~^~~~~~~~~~
Main.cpp:34:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   if (r < v.size()-1) {
      |       ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 5 ms 324 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 5 ms 360 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 6 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 4 ms 452 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Incorrect 4 ms 340 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 5 ms 324 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 5 ms 360 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 6 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 4 ms 452 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Incorrect 4 ms 340 KB Output isn't correct
20 Halted 0 ms 0 KB -