Submission #832671

# Submission time Handle Problem Language Result Execution time Memory
832671 2023-08-21T13:33:13 Z rainboy Fuel Station (NOI20_fuelstation) C
100 / 100
221 ms 31296 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]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 22524 KB Output is correct
2 Correct 100 ms 22456 KB Output is correct
3 Correct 101 ms 22460 KB Output is correct
4 Correct 96 ms 22476 KB Output is correct
5 Correct 127 ms 22464 KB Output is correct
6 Correct 100 ms 22476 KB Output is correct
7 Correct 100 ms 22544 KB Output is correct
8 Correct 100 ms 22436 KB Output is correct
9 Correct 129 ms 22504 KB Output is correct
10 Correct 103 ms 22428 KB Output is correct
11 Correct 100 ms 22544 KB Output is correct
12 Correct 91 ms 22544 KB Output is correct
13 Correct 101 ms 22444 KB Output is correct
14 Correct 100 ms 22504 KB Output is correct
15 Correct 96 ms 22504 KB Output is correct
16 Correct 105 ms 22520 KB Output is correct
17 Correct 96 ms 22508 KB Output is correct
18 Correct 100 ms 22472 KB Output is correct
19 Correct 93 ms 22452 KB Output is correct
20 Correct 100 ms 22504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 4 ms 992 KB Output is correct
6 Correct 4 ms 980 KB Output is correct
7 Correct 5 ms 980 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 5 ms 1108 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 5 ms 1076 KB Output is correct
18 Correct 5 ms 1108 KB Output is correct
19 Correct 3 ms 1076 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Correct 3 ms 1108 KB Output is correct
22 Correct 4 ms 1236 KB Output is correct
23 Correct 3 ms 1108 KB Output is correct
24 Correct 3 ms 1108 KB Output is correct
25 Correct 3 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 4 ms 992 KB Output is correct
6 Correct 4 ms 980 KB Output is correct
7 Correct 5 ms 980 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 5 ms 1108 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 5 ms 1076 KB Output is correct
18 Correct 5 ms 1108 KB Output is correct
19 Correct 3 ms 1076 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Correct 3 ms 1108 KB Output is correct
22 Correct 4 ms 1236 KB Output is correct
23 Correct 3 ms 1108 KB Output is correct
24 Correct 3 ms 1108 KB Output is correct
25 Correct 3 ms 1080 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 96 ms 26836 KB Output is correct
28 Correct 106 ms 26616 KB Output is correct
29 Correct 112 ms 26264 KB Output is correct
30 Correct 103 ms 26296 KB Output is correct
31 Correct 115 ms 26876 KB Output is correct
32 Correct 111 ms 26544 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 292 KB Output is correct
39 Correct 165 ms 26888 KB Output is correct
40 Correct 169 ms 26828 KB Output is correct
41 Correct 180 ms 26888 KB Output is correct
42 Correct 162 ms 26884 KB Output is correct
43 Correct 166 ms 26784 KB Output is correct
44 Correct 115 ms 26316 KB Output is correct
45 Correct 112 ms 25996 KB Output is correct
46 Correct 124 ms 26812 KB Output is correct
47 Correct 83 ms 28392 KB Output is correct
48 Correct 95 ms 28372 KB Output is correct
49 Correct 96 ms 26192 KB Output is correct
50 Correct 93 ms 26488 KB Output is correct
51 Correct 95 ms 26580 KB Output is correct
52 Correct 104 ms 26272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 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 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 280 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 4 ms 992 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 5 ms 980 KB Output is correct
23 Correct 1 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 296 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 296 KB Output is correct
29 Correct 5 ms 1108 KB Output is correct
30 Correct 5 ms 1108 KB Output is correct
31 Correct 5 ms 1108 KB Output is correct
32 Correct 5 ms 1076 KB Output is correct
33 Correct 5 ms 1108 KB Output is correct
34 Correct 3 ms 1076 KB Output is correct
35 Correct 3 ms 1108 KB Output is correct
36 Correct 3 ms 1108 KB Output is correct
37 Correct 4 ms 1236 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
39 Correct 3 ms 1108 KB Output is correct
40 Correct 3 ms 1080 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 4 ms 1236 KB Output is correct
43 Correct 5 ms 1196 KB Output is correct
44 Correct 5 ms 1236 KB Output is correct
45 Correct 5 ms 1284 KB Output is correct
46 Correct 6 ms 1236 KB Output is correct
47 Correct 5 ms 1288 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 296 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 292 KB Output is correct
54 Correct 6 ms 1236 KB Output is correct
55 Correct 5 ms 1316 KB Output is correct
56 Correct 6 ms 1268 KB Output is correct
57 Correct 5 ms 1312 KB Output is correct
58 Correct 5 ms 1204 KB Output is correct
59 Correct 4 ms 1200 KB Output is correct
60 Correct 4 ms 1304 KB Output is correct
61 Correct 5 ms 1236 KB Output is correct
62 Correct 4 ms 1200 KB Output is correct
63 Correct 5 ms 1200 KB Output is correct
64 Correct 5 ms 1236 KB Output is correct
65 Correct 4 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 101 ms 22524 KB Output is correct
17 Correct 100 ms 22456 KB Output is correct
18 Correct 101 ms 22460 KB Output is correct
19 Correct 96 ms 22476 KB Output is correct
20 Correct 127 ms 22464 KB Output is correct
21 Correct 100 ms 22476 KB Output is correct
22 Correct 100 ms 22544 KB Output is correct
23 Correct 100 ms 22436 KB Output is correct
24 Correct 129 ms 22504 KB Output is correct
25 Correct 103 ms 22428 KB Output is correct
26 Correct 100 ms 22544 KB Output is correct
27 Correct 91 ms 22544 KB Output is correct
28 Correct 101 ms 22444 KB Output is correct
29 Correct 100 ms 22504 KB Output is correct
30 Correct 96 ms 22504 KB Output is correct
31 Correct 105 ms 22520 KB Output is correct
32 Correct 96 ms 22508 KB Output is correct
33 Correct 100 ms 22472 KB Output is correct
34 Correct 93 ms 22452 KB Output is correct
35 Correct 100 ms 22504 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 3 ms 980 KB Output is correct
38 Correct 4 ms 980 KB Output is correct
39 Correct 4 ms 980 KB Output is correct
40 Correct 4 ms 992 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 5 ms 980 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 296 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 296 KB Output is correct
49 Correct 5 ms 1108 KB Output is correct
50 Correct 5 ms 1108 KB Output is correct
51 Correct 5 ms 1108 KB Output is correct
52 Correct 5 ms 1076 KB Output is correct
53 Correct 5 ms 1108 KB Output is correct
54 Correct 3 ms 1076 KB Output is correct
55 Correct 3 ms 1108 KB Output is correct
56 Correct 3 ms 1108 KB Output is correct
57 Correct 4 ms 1236 KB Output is correct
58 Correct 3 ms 1108 KB Output is correct
59 Correct 3 ms 1108 KB Output is correct
60 Correct 3 ms 1080 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 96 ms 26836 KB Output is correct
63 Correct 106 ms 26616 KB Output is correct
64 Correct 112 ms 26264 KB Output is correct
65 Correct 103 ms 26296 KB Output is correct
66 Correct 115 ms 26876 KB Output is correct
67 Correct 111 ms 26544 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 292 KB Output is correct
74 Correct 165 ms 26888 KB Output is correct
75 Correct 169 ms 26828 KB Output is correct
76 Correct 180 ms 26888 KB Output is correct
77 Correct 162 ms 26884 KB Output is correct
78 Correct 166 ms 26784 KB Output is correct
79 Correct 115 ms 26316 KB Output is correct
80 Correct 112 ms 25996 KB Output is correct
81 Correct 124 ms 26812 KB Output is correct
82 Correct 83 ms 28392 KB Output is correct
83 Correct 95 ms 28372 KB Output is correct
84 Correct 96 ms 26192 KB Output is correct
85 Correct 93 ms 26488 KB Output is correct
86 Correct 95 ms 26580 KB Output is correct
87 Correct 104 ms 26272 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 0 ms 212 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 280 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 0 ms 212 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 0 ms 212 KB Output is correct
101 Correct 0 ms 212 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Correct 0 ms 212 KB Output is correct
104 Correct 4 ms 1236 KB Output is correct
105 Correct 5 ms 1196 KB Output is correct
106 Correct 5 ms 1236 KB Output is correct
107 Correct 5 ms 1284 KB Output is correct
108 Correct 6 ms 1236 KB Output is correct
109 Correct 5 ms 1288 KB Output is correct
110 Correct 0 ms 212 KB Output is correct
111 Correct 0 ms 212 KB Output is correct
112 Correct 0 ms 296 KB Output is correct
113 Correct 0 ms 212 KB Output is correct
114 Correct 0 ms 212 KB Output is correct
115 Correct 1 ms 292 KB Output is correct
116 Correct 6 ms 1236 KB Output is correct
117 Correct 5 ms 1316 KB Output is correct
118 Correct 6 ms 1268 KB Output is correct
119 Correct 5 ms 1312 KB Output is correct
120 Correct 5 ms 1204 KB Output is correct
121 Correct 4 ms 1200 KB Output is correct
122 Correct 4 ms 1304 KB Output is correct
123 Correct 5 ms 1236 KB Output is correct
124 Correct 4 ms 1200 KB Output is correct
125 Correct 5 ms 1200 KB Output is correct
126 Correct 5 ms 1236 KB Output is correct
127 Correct 4 ms 1236 KB Output is correct
128 Correct 1 ms 340 KB Output is correct
129 Correct 135 ms 30012 KB Output is correct
130 Correct 170 ms 30536 KB Output is correct
131 Correct 193 ms 31228 KB Output is correct
132 Correct 157 ms 30616 KB Output is correct
133 Correct 164 ms 30680 KB Output is correct
134 Correct 162 ms 31228 KB Output is correct
135 Correct 1 ms 212 KB Output is correct
136 Correct 1 ms 212 KB Output is correct
137 Correct 1 ms 212 KB Output is correct
138 Correct 0 ms 212 KB Output is correct
139 Correct 0 ms 212 KB Output is correct
140 Correct 1 ms 212 KB Output is correct
141 Correct 207 ms 31280 KB Output is correct
142 Correct 217 ms 30976 KB Output is correct
143 Correct 201 ms 31284 KB Output is correct
144 Correct 221 ms 31236 KB Output is correct
145 Correct 213 ms 31296 KB Output is correct
146 Correct 202 ms 29520 KB Output is correct
147 Correct 170 ms 30412 KB Output is correct
148 Correct 199 ms 29768 KB Output is correct
149 Correct 130 ms 30536 KB Output is correct
150 Correct 92 ms 30800 KB Output is correct
151 Correct 92 ms 30948 KB Output is correct
152 Correct 132 ms 30720 KB Output is correct
153 Correct 119 ms 30596 KB Output is correct
154 Correct 110 ms 30532 KB Output is correct
155 Correct 132 ms 30532 KB Output is correct