답안 #832667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832667 2023-08-21T13:29:25 Z rainboy Fuel Station (NOI20_fuelstation) C
39 / 100
120 ms 31592 KB
#include <stdio.h>

#define N	300001
#define N_	(1 << 19)	/* N_ = pow2(ceil(log2(N))) */

long long max(long long a, long long b) { return a > b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int xx[N], aa[N], bb[N], ii[N], idx[N], n;

int *vv;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (vv[ii[j]] == vv[i_])
				j++;
			else if (vv[ii[j]] < vv[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

long long ss[N_ * 2], pp[N_ * 2]; int n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	ss[i] = ss[l] + ss[r];
	pp[i] = max(pp[l], pp[r] - ss[l]);
}

void build() {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 0; i < n_; i++)
		if (i < n)
			ss[n_ + i] = aa[ii[i]], pp[n_ + i] = xx[ii[i]];
		else
			ss[n_ + i] = 0, pp[n_ + i] = 0;
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void update(int i) {
	ss[i += n_] = 0;
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	int x_, i;

	scanf("%d%d", &n, &x_);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &aa[i], &bb[i]);
	xx[n] = x_, aa[n] = 0, bb[n] = 0;
	n++;
	for (i = 0; i < n; i++)
		ii[i] = i;
	vv = xx, sort(ii, 0, n);
	for (i = 0; i < n; i++)
		idx[ii[i]] = i;
	build();
	vv = bb, sort(ii, 0, n);
	for (i = 0; i < n; i++) {
		if (pp[1] < bb[ii[i]]) {
			printf("%lld\n", pp[1]);
			return 0;
		}
		update(idx[ii[i]]);
	}
	printf("%lld\n", pp[1]);
	return 0;
}

Compilation message

FuelStation.c: In function 'main':
FuelStation.c:70:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  scanf("%d%d", &n, &x_);
      |  ^~~~~~~~~~~~~~~~~~~~~~
FuelStation.c:72:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf("%d%d%d", &xx[i], &aa[i], &bb[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 296 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 288 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 30928 KB Output is correct
2 Correct 110 ms 30980 KB Output is correct
3 Correct 112 ms 30876 KB Output is correct
4 Correct 92 ms 30924 KB Output is correct
5 Correct 97 ms 31492 KB Output is correct
6 Correct 102 ms 30236 KB Output is correct
7 Correct 103 ms 30284 KB Output is correct
8 Correct 93 ms 30912 KB Output is correct
9 Correct 108 ms 31468 KB Output is correct
10 Correct 92 ms 30304 KB Output is correct
11 Correct 101 ms 30256 KB Output is correct
12 Correct 91 ms 30956 KB Output is correct
13 Correct 103 ms 30336 KB Output is correct
14 Correct 105 ms 30924 KB Output is correct
15 Correct 91 ms 30944 KB Output is correct
16 Correct 120 ms 31552 KB Output is correct
17 Correct 98 ms 31592 KB Output is correct
18 Correct 102 ms 30924 KB Output is correct
19 Correct 98 ms 30948 KB Output is correct
20 Correct 111 ms 30924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 1156 KB Output is correct
3 Correct 4 ms 1076 KB Output is correct
4 Correct 4 ms 1072 KB Output is correct
5 Correct 5 ms 1132 KB Output is correct
6 Correct 5 ms 1140 KB Output is correct
7 Correct 5 ms 1076 KB Output is correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 1156 KB Output is correct
3 Correct 4 ms 1076 KB Output is correct
4 Correct 4 ms 1072 KB Output is correct
5 Correct 5 ms 1132 KB Output is correct
6 Correct 5 ms 1140 KB Output is correct
7 Correct 5 ms 1076 KB Output is correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 296 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 288 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 296 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 288 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 3 ms 1156 KB Output is correct
18 Correct 4 ms 1076 KB Output is correct
19 Correct 4 ms 1072 KB Output is correct
20 Correct 5 ms 1132 KB Output is correct
21 Correct 5 ms 1140 KB Output is correct
22 Correct 5 ms 1076 KB Output is correct
23 Incorrect 1 ms 212 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 296 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 288 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 102 ms 30928 KB Output is correct
17 Correct 110 ms 30980 KB Output is correct
18 Correct 112 ms 30876 KB Output is correct
19 Correct 92 ms 30924 KB Output is correct
20 Correct 97 ms 31492 KB Output is correct
21 Correct 102 ms 30236 KB Output is correct
22 Correct 103 ms 30284 KB Output is correct
23 Correct 93 ms 30912 KB Output is correct
24 Correct 108 ms 31468 KB Output is correct
25 Correct 92 ms 30304 KB Output is correct
26 Correct 101 ms 30256 KB Output is correct
27 Correct 91 ms 30956 KB Output is correct
28 Correct 103 ms 30336 KB Output is correct
29 Correct 105 ms 30924 KB Output is correct
30 Correct 91 ms 30944 KB Output is correct
31 Correct 120 ms 31552 KB Output is correct
32 Correct 98 ms 31592 KB Output is correct
33 Correct 102 ms 30924 KB Output is correct
34 Correct 98 ms 30948 KB Output is correct
35 Correct 111 ms 30924 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 3 ms 1156 KB Output is correct
38 Correct 4 ms 1076 KB Output is correct
39 Correct 4 ms 1072 KB Output is correct
40 Correct 5 ms 1132 KB Output is correct
41 Correct 5 ms 1140 KB Output is correct
42 Correct 5 ms 1076 KB Output is correct
43 Incorrect 1 ms 212 KB Output isn't correct
44 Halted 0 ms 0 KB -