답안 #445242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445242 2021-07-17T04:50:42 Z maomao90 Snowball (JOI21_ho_t2) C++17
100 / 100
136 ms 18500 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
	va_list args;
	va_start(args, format);
	vprintf(format, args);
	va_end(args);
}
#else
#define debug(args...)
#endif

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005

int n, q;
ll x[MAXN], w[MAXN];
ll psum[MAXN], pmx[MAXN], pmn[MAXN], l[MAXN], r[MAXN];

int main() {
	scanf("%d%d", &n, &q);
	REP (i, 1, n + 1) {
		scanf("%lld", &x[i]);
	}
	x[0] = -LINF;
	x[n + 1] = LINF;
	REP (i, 1, q + 1) {
		scanf("%lld", &w[i]);
		psum[i] = psum[i - 1] + w[i];
		pmx[i] = max(pmx[i - 1], psum[i]);
		pmn[i] = min(pmn[i - 1], psum[i]);
		debug("%d: %lld %lld %lld\n", i, psum[i], pmx[i], pmn[i]);
	}
	REP (i, 1, n + 2) {
		ll gp = x[i] - x[i - 1];
		int res = -1;
		int lo = 1, hi = q, mid;
		while (lo <= hi) {
			mid = lo + hi >> 1;
			if (pmx[mid] - pmn[mid] > gp) {
				res = mid;
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		debug("%d\n", res);
		if (res == -1) {
			r[i - 1] = pmx[q];
			l[i] = pmn[q];
		} else {
			assert(w[res] != 0);
			if (w[res] > 0) {
				l[i] = pmn[res - 1];
				r[i - 1] = gp + l[i];
			} else {
				r[i - 1] = pmx[res - 1];
				l[i] = r[i - 1] - gp;
			}
		}
	}
	REP (i, 1, n + 1) {
		printf("%lld\n", r[i] - l[i]);
	}
	return 0;
}

/*
4 3
-2 3 5 8
2
-4
7

10 10
-56 -43 -39 -31 -22 -5 0 12 18 22
-3
0
5
-4
-2
10
-13
-1
9
6
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:65:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |    mid = lo + hi >> 1;
      |          ~~~^~~~
Main.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%lld", &x[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
Main.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%lld", &w[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 1 ms 480 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 1 ms 480 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 36 ms 8688 KB Output is correct
21 Correct 37 ms 8388 KB Output is correct
22 Correct 34 ms 8260 KB Output is correct
23 Correct 32 ms 8208 KB Output is correct
24 Correct 42 ms 8812 KB Output is correct
25 Correct 130 ms 16504 KB Output is correct
26 Correct 128 ms 16372 KB Output is correct
27 Correct 135 ms 16336 KB Output is correct
28 Correct 130 ms 16296 KB Output is correct
29 Correct 128 ms 15744 KB Output is correct
30 Correct 117 ms 15172 KB Output is correct
31 Correct 92 ms 14596 KB Output is correct
32 Correct 84 ms 14660 KB Output is correct
33 Correct 12 ms 1996 KB Output is correct
34 Correct 133 ms 16880 KB Output is correct
35 Correct 135 ms 16324 KB Output is correct
36 Correct 136 ms 16484 KB Output is correct
37 Correct 134 ms 16212 KB Output is correct
38 Correct 130 ms 16132 KB Output is correct
39 Correct 127 ms 16452 KB Output is correct
40 Correct 97 ms 16428 KB Output is correct
41 Correct 40 ms 9308 KB Output is correct
42 Correct 82 ms 14664 KB Output is correct
43 Correct 102 ms 18000 KB Output is correct
44 Correct 40 ms 9136 KB Output is correct
45 Correct 90 ms 16228 KB Output is correct
46 Correct 100 ms 18080 KB Output is correct
47 Correct 110 ms 18500 KB Output is correct
48 Correct 113 ms 18488 KB Output is correct