Submission #202100

# Submission time Handle Problem Language Result Execution time Memory
202100 2020-02-13T21:24:30 Z maruii Long Distance Coach (JOI17_coach) C++14
100 / 100
243 ms 129272 KB
#include <bits/stdc++.h>
using namespace std;using ll = long long;using pii = pair<ll, ll>;
#define ff first
#define ss second
int N, M;struct CHT {	struct Node {		pii L;		int l, r;		Node() : L(pii(0, 1e18)), l(-1), r(-1) {}	} A[5000005];	ll f(pii L, int x) { return L.ff * x + L.ss; }	int cnt;	void update(int nn, int s, int e, pii L2) {		pii &L1 = A[nn].L;		if (f(L1, s) > f(L2, s)) swap(L1, L2);		if (f(L1, e) <= f(L2, e)) return;		int m = s + e >> 1;		if (f(L1, m) >= f(L2, m)) {			swap(L1, L2);			if (A[nn].l < 0) A[nn].l = ++cnt, A[cnt].L = L1;			update(A[nn].l, s, m, L2);		}		else {			if (A[nn].r < 0) A[nn].r = ++cnt, A[cnt].L = L1;			update(A[nn].r, m + 1, e, L2);		}	}	void update(ll a, ll b) { update(0, 0, M, pii(a, b)); }	ll query(int nn, int s, int e, int x) {		if (nn < 0 || s > x || e < x) return 1e18;		ll ret = f(A[nn].L, x);		int m = s + e >> 1;		return min({ret, query(A[nn].l, s, m, x), query(A[nn].r, m + 1, e, x)});	}	ll query(int x) { return query(0, 0, M, x); }} cht;ll X, T, W;pii R[200005], P[200005];ll D[200005], H[200005], S[200005];int main() {	ios_base::sync_with_stdio(0), cin.tie(0);	cin >> X >> N >> M >> W >> T;	for (int i = 0; i < N; ++i) {		ll x; cin >> x;		R[i] = {x % T, x / T};	}	for (int i = 1; i <= M; ++i) cin >> P[i].ff >> P[i].ss;	R[N] = {X % T, X / T};	sort(R, R + N + 1);	sort(P + 1, P + M + 1);	for (int i = 1; i <= M; ++i) {		S[i] = S[i - 1] + P[i].ss;		H[i] = X / T + (X % T >= P[i].ff);	}	H[0] = X / T + 1;	for (int i = M, j = N; i; --i) {		while (j >= 0 && R[j].ff > P[i].ff) {			cht.update(-W * R[j].ss, D[i + 1] + S[i] + W * i * R[j].ss);			--j;		}		D[i] = min(cht.query(i - 1) - S[i - 1], D[i + 1] + H[i] * W);	}	cout << D[1] + H[0] * W;	return 0;}

Compilation message

coach.cpp: In member function 'void CHT::update(int, int, int, pii)':
coach.cpp:5:319: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 int N, M;struct CHT { struct Node {  pii L;  int l, r;  Node() : L(pii(0, 1e18)), l(-1), r(-1) {} } A[5000005]; ll f(pii L, int x) { return L.ff * x + L.ss; } int cnt; void update(int nn, int s, int e, pii L2) {  pii &L1 = A[nn].L;  if (f(L1, s) > f(L2, s)) swap(L1, L2);  if (f(L1, e) <= f(L2, e)) return;  int m = s + e >> 1;  if (f(L1, m) >= f(L2, m)) {   swap(L1, L2);   if (A[nn].l < 0) A[nn].l = ++cnt, A[cnt].L = L1;   update(A[nn].l, s, m, L2);  }  else {   if (A[nn].r < 0) A[nn].r = ++cnt, A[cnt].L = L1;   update(A[nn].r, m + 1, e, L2);  } } void update(ll a, ll b) { update(0, 0, M, pii(a, b)); } ll query(int nn, int s, int e, int x) {  if (nn < 0 || s > x || e < x) return 1e18;  ll ret = f(A[nn].L, x);  int m = s + e >> 1;  return min({ret, query(A[nn].l, s, m, x), query(A[nn].r, m + 1, e, x)}); } ll query(int x) { return query(0, 0, M, x); }} cht;ll X, T, W;pii R[200005], P[200005];ll D[200005], H[200005], S[200005];int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> X >> N >> M >> W >> T; for (int i = 0; i < N; ++i) {  ll x; cin >> x;  R[i] = {x % T, x / T}; } for (int i = 1; i <= M; ++i) cin >> P[i].ff >> P[i].ss; R[N] = {X % T, X / T}; sort(R, R + N + 1); sort(P + 1, P + M + 1); for (int i = 1; i <= M; ++i) {  S[i] = S[i - 1] + P[i].ss;  H[i] = X / T + (X % T >= P[i].ff); } H[0] = X / T + 1; for (int i = M, j = N; i; --i) {  while (j >= 0 && R[j].ff > P[i].ff) {   cht.update(-W * R[j].ss, D[i + 1] + S[i] + W * i * R[j].ss);   --j;  }  D[i] = min(cht.query(i - 1) - S[i - 1], D[i + 1] + H[i] * W); } cout << D[1] + H[0] * W; return 0;}
                                                                                                                                                                                                                                                                                                                             ~~^~~
coach.cpp: In member function 'll CHT::query(int, int, int, int)':
coach.cpp:5:730: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 int N, M;struct CHT { struct Node {  pii L;  int l, r;  Node() : L(pii(0, 1e18)), l(-1), r(-1) {} } A[5000005]; ll f(pii L, int x) { return L.ff * x + L.ss; } int cnt; void update(int nn, int s, int e, pii L2) {  pii &L1 = A[nn].L;  if (f(L1, s) > f(L2, s)) swap(L1, L2);  if (f(L1, e) <= f(L2, e)) return;  int m = s + e >> 1;  if (f(L1, m) >= f(L2, m)) {   swap(L1, L2);   if (A[nn].l < 0) A[nn].l = ++cnt, A[cnt].L = L1;   update(A[nn].l, s, m, L2);  }  else {   if (A[nn].r < 0) A[nn].r = ++cnt, A[cnt].L = L1;   update(A[nn].r, m + 1, e, L2);  } } void update(ll a, ll b) { update(0, 0, M, pii(a, b)); } ll query(int nn, int s, int e, int x) {  if (nn < 0 || s > x || e < x) return 1e18;  ll ret = f(A[nn].L, x);  int m = s + e >> 1;  return min({ret, query(A[nn].l, s, m, x), query(A[nn].r, m + 1, e, x)}); } ll query(int x) { return query(0, 0, M, x); }} cht;ll X, T, W;pii R[200005], P[200005];ll D[200005], H[200005], S[200005];int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> X >> N >> M >> W >> T; for (int i = 0; i < N; ++i) {  ll x; cin >> x;  R[i] = {x % T, x / T}; } for (int i = 1; i <= M; ++i) cin >> P[i].ff >> P[i].ss; R[N] = {X % T, X / T}; sort(R, R + N + 1); sort(P + 1, P + M + 1); for (int i = 1; i <= M; ++i) {  S[i] = S[i - 1] + P[i].ss;  H[i] = X / T + (X % T >= P[i].ff); } H[0] = X / T + 1; for (int i = M, j = N; i; --i) {  while (j >= 0 && R[j].ff > P[i].ff) {   cht.update(-W * R[j].ss, D[i + 1] + S[i] + W * i * R[j].ss);   --j;  }  D[i] = min(cht.query(i - 1) - S[i - 1], D[i + 1] + H[i] * W); } cout << D[1] + H[0] * W; return 0;}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 117752 KB Output is correct
2 Correct 70 ms 117752 KB Output is correct
3 Correct 70 ms 117880 KB Output is correct
4 Correct 70 ms 117760 KB Output is correct
5 Correct 72 ms 117752 KB Output is correct
6 Correct 67 ms 117816 KB Output is correct
7 Correct 72 ms 117756 KB Output is correct
8 Correct 77 ms 117752 KB Output is correct
9 Correct 69 ms 117752 KB Output is correct
10 Correct 70 ms 117752 KB Output is correct
11 Correct 69 ms 117752 KB Output is correct
12 Correct 70 ms 117752 KB Output is correct
13 Correct 71 ms 117752 KB Output is correct
14 Correct 69 ms 117752 KB Output is correct
15 Correct 71 ms 117752 KB Output is correct
16 Correct 68 ms 117752 KB Output is correct
17 Correct 70 ms 117752 KB Output is correct
18 Correct 70 ms 117752 KB Output is correct
19 Correct 71 ms 117752 KB Output is correct
20 Correct 72 ms 117880 KB Output is correct
21 Correct 72 ms 117752 KB Output is correct
22 Correct 69 ms 117752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 117752 KB Output is correct
2 Correct 70 ms 117752 KB Output is correct
3 Correct 70 ms 117880 KB Output is correct
4 Correct 70 ms 117760 KB Output is correct
5 Correct 72 ms 117752 KB Output is correct
6 Correct 67 ms 117816 KB Output is correct
7 Correct 72 ms 117756 KB Output is correct
8 Correct 77 ms 117752 KB Output is correct
9 Correct 69 ms 117752 KB Output is correct
10 Correct 70 ms 117752 KB Output is correct
11 Correct 69 ms 117752 KB Output is correct
12 Correct 70 ms 117752 KB Output is correct
13 Correct 71 ms 117752 KB Output is correct
14 Correct 69 ms 117752 KB Output is correct
15 Correct 71 ms 117752 KB Output is correct
16 Correct 68 ms 117752 KB Output is correct
17 Correct 70 ms 117752 KB Output is correct
18 Correct 70 ms 117752 KB Output is correct
19 Correct 71 ms 117752 KB Output is correct
20 Correct 72 ms 117880 KB Output is correct
21 Correct 72 ms 117752 KB Output is correct
22 Correct 69 ms 117752 KB Output is correct
23 Correct 68 ms 117752 KB Output is correct
24 Correct 70 ms 117752 KB Output is correct
25 Correct 72 ms 117752 KB Output is correct
26 Correct 73 ms 117880 KB Output is correct
27 Correct 69 ms 117880 KB Output is correct
28 Correct 69 ms 117752 KB Output is correct
29 Correct 66 ms 117752 KB Output is correct
30 Correct 70 ms 117752 KB Output is correct
31 Correct 68 ms 117752 KB Output is correct
32 Correct 68 ms 117752 KB Output is correct
33 Correct 69 ms 117880 KB Output is correct
34 Correct 69 ms 117752 KB Output is correct
35 Correct 71 ms 117880 KB Output is correct
36 Correct 72 ms 117752 KB Output is correct
37 Correct 70 ms 117880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 117752 KB Output is correct
2 Correct 70 ms 117752 KB Output is correct
3 Correct 70 ms 117880 KB Output is correct
4 Correct 70 ms 117760 KB Output is correct
5 Correct 72 ms 117752 KB Output is correct
6 Correct 67 ms 117816 KB Output is correct
7 Correct 72 ms 117756 KB Output is correct
8 Correct 77 ms 117752 KB Output is correct
9 Correct 69 ms 117752 KB Output is correct
10 Correct 70 ms 117752 KB Output is correct
11 Correct 69 ms 117752 KB Output is correct
12 Correct 70 ms 117752 KB Output is correct
13 Correct 71 ms 117752 KB Output is correct
14 Correct 69 ms 117752 KB Output is correct
15 Correct 71 ms 117752 KB Output is correct
16 Correct 68 ms 117752 KB Output is correct
17 Correct 70 ms 117752 KB Output is correct
18 Correct 70 ms 117752 KB Output is correct
19 Correct 71 ms 117752 KB Output is correct
20 Correct 72 ms 117880 KB Output is correct
21 Correct 72 ms 117752 KB Output is correct
22 Correct 69 ms 117752 KB Output is correct
23 Correct 68 ms 117752 KB Output is correct
24 Correct 70 ms 117752 KB Output is correct
25 Correct 72 ms 117752 KB Output is correct
26 Correct 73 ms 117880 KB Output is correct
27 Correct 69 ms 117880 KB Output is correct
28 Correct 69 ms 117752 KB Output is correct
29 Correct 66 ms 117752 KB Output is correct
30 Correct 70 ms 117752 KB Output is correct
31 Correct 68 ms 117752 KB Output is correct
32 Correct 68 ms 117752 KB Output is correct
33 Correct 69 ms 117880 KB Output is correct
34 Correct 69 ms 117752 KB Output is correct
35 Correct 71 ms 117880 KB Output is correct
36 Correct 72 ms 117752 KB Output is correct
37 Correct 70 ms 117880 KB Output is correct
38 Correct 70 ms 117880 KB Output is correct
39 Correct 72 ms 118008 KB Output is correct
40 Correct 75 ms 117880 KB Output is correct
41 Correct 72 ms 117880 KB Output is correct
42 Correct 69 ms 118008 KB Output is correct
43 Correct 69 ms 117880 KB Output is correct
44 Correct 70 ms 117880 KB Output is correct
45 Correct 71 ms 118008 KB Output is correct
46 Correct 71 ms 118008 KB Output is correct
47 Correct 72 ms 118008 KB Output is correct
48 Correct 70 ms 117880 KB Output is correct
49 Correct 70 ms 117880 KB Output is correct
50 Correct 72 ms 117880 KB Output is correct
51 Correct 71 ms 118008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 117752 KB Output is correct
2 Correct 70 ms 117752 KB Output is correct
3 Correct 70 ms 117880 KB Output is correct
4 Correct 70 ms 117760 KB Output is correct
5 Correct 72 ms 117752 KB Output is correct
6 Correct 67 ms 117816 KB Output is correct
7 Correct 72 ms 117756 KB Output is correct
8 Correct 77 ms 117752 KB Output is correct
9 Correct 69 ms 117752 KB Output is correct
10 Correct 70 ms 117752 KB Output is correct
11 Correct 69 ms 117752 KB Output is correct
12 Correct 70 ms 117752 KB Output is correct
13 Correct 71 ms 117752 KB Output is correct
14 Correct 69 ms 117752 KB Output is correct
15 Correct 71 ms 117752 KB Output is correct
16 Correct 68 ms 117752 KB Output is correct
17 Correct 70 ms 117752 KB Output is correct
18 Correct 70 ms 117752 KB Output is correct
19 Correct 71 ms 117752 KB Output is correct
20 Correct 72 ms 117880 KB Output is correct
21 Correct 72 ms 117752 KB Output is correct
22 Correct 69 ms 117752 KB Output is correct
23 Correct 68 ms 117752 KB Output is correct
24 Correct 70 ms 117752 KB Output is correct
25 Correct 72 ms 117752 KB Output is correct
26 Correct 73 ms 117880 KB Output is correct
27 Correct 69 ms 117880 KB Output is correct
28 Correct 69 ms 117752 KB Output is correct
29 Correct 66 ms 117752 KB Output is correct
30 Correct 70 ms 117752 KB Output is correct
31 Correct 68 ms 117752 KB Output is correct
32 Correct 68 ms 117752 KB Output is correct
33 Correct 69 ms 117880 KB Output is correct
34 Correct 69 ms 117752 KB Output is correct
35 Correct 71 ms 117880 KB Output is correct
36 Correct 72 ms 117752 KB Output is correct
37 Correct 70 ms 117880 KB Output is correct
38 Correct 70 ms 117880 KB Output is correct
39 Correct 72 ms 118008 KB Output is correct
40 Correct 75 ms 117880 KB Output is correct
41 Correct 72 ms 117880 KB Output is correct
42 Correct 69 ms 118008 KB Output is correct
43 Correct 69 ms 117880 KB Output is correct
44 Correct 70 ms 117880 KB Output is correct
45 Correct 71 ms 118008 KB Output is correct
46 Correct 71 ms 118008 KB Output is correct
47 Correct 72 ms 118008 KB Output is correct
48 Correct 70 ms 117880 KB Output is correct
49 Correct 70 ms 117880 KB Output is correct
50 Correct 72 ms 117880 KB Output is correct
51 Correct 71 ms 118008 KB Output is correct
52 Correct 234 ms 129144 KB Output is correct
53 Correct 207 ms 129084 KB Output is correct
54 Correct 219 ms 129016 KB Output is correct
55 Correct 207 ms 129144 KB Output is correct
56 Correct 203 ms 129144 KB Output is correct
57 Correct 210 ms 129144 KB Output is correct
58 Correct 205 ms 129272 KB Output is correct
59 Correct 200 ms 129144 KB Output is correct
60 Correct 196 ms 129016 KB Output is correct
61 Correct 201 ms 129016 KB Output is correct
62 Correct 205 ms 129016 KB Output is correct
63 Correct 197 ms 129016 KB Output is correct
64 Correct 162 ms 129016 KB Output is correct
65 Correct 216 ms 129016 KB Output is correct
66 Correct 218 ms 128888 KB Output is correct
67 Correct 223 ms 129016 KB Output is correct
68 Correct 212 ms 129016 KB Output is correct
69 Correct 238 ms 128888 KB Output is correct
70 Correct 235 ms 129016 KB Output is correct
71 Correct 243 ms 128888 KB Output is correct
72 Correct 238 ms 128888 KB Output is correct
73 Correct 233 ms 128760 KB Output is correct
74 Correct 236 ms 128888 KB Output is correct
75 Correct 230 ms 128888 KB Output is correct
76 Correct 234 ms 128888 KB Output is correct
77 Correct 189 ms 128888 KB Output is correct
78 Correct 193 ms 128888 KB Output is correct
79 Correct 230 ms 129016 KB Output is correct
80 Correct 232 ms 128672 KB Output is correct