답안 #395242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395242 2021-04-28T03:49:59 Z ChrisT Bulldozer (JOI17_bulldozer) C++17
100 / 100
1184 ms 59832 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = 2e3 + 5;
#define lc ind<<1
#define rc ind<<1|1
struct Node {
	long long mn,mx;
} tree[MN<<1];
void update (int i, long long v) {
	i+=MN-1;
	for (tree[i].mn=tree[i].mx=v;i>1;i>>=1) {
		tree[i>>1].mn = min(tree[i].mn,tree[i^1].mn);
		tree[i>>1].mx = max(tree[i].mx,tree[i^1].mx);
	}
}
long long queryMin (int l, int r) {
	long long ret = LLONG_MAX;
	for (l += MN-1, r += MN; l < r; l >>= 1, r >>= 1) {
		if (l&1) ret = min(ret,tree[l++].mn);
		if (r&1) ret = min(ret,tree[--r].mn);
	}
	return ret;
}
long long queryMax (int l, int r) {
	long long ret = LLONG_MIN;
	for (l += MN-1, r += MN; l < r; l >>= 1, r >>= 1) {
		if (l&1) ret = max(ret,tree[l++].mx);
		if (r&1) ret = max(ret,tree[--r].mx);
	}
	return ret;
}
int main () {
	int n,c=0; scanf ("%d",&n);
	vector<array<int,4>> pts(n); vector<int> pos(n), ow(n);
	vector<long long> vAt(n+1); vector<int> pAt(n+1);
	for (auto &[x,y,w,id] : pts) scanf ("%d %d %d",&x,&y,&w), id=c++, ow[id] = w;
	vector<tuple<int,int,long long,int,int>> events;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int dx = pts[i][0] - pts[j][0], dy = pts[i][1] - pts[j][1];
			int gcd = __gcd(dx,dy); dx /= gcd; dy /= gcd;
			if (dx < 0) dx = -dx, dy = -dy;
			if (dx == 0 && dy < 0) dy = -dy;
			events.push_back({dx,dy,(long long)dx * pts[i][1] - (long long)dy * pts[i][0],i,j});
		}
	}
	sort(pts.begin(),pts.end());
	auto cmp = [&] (const auto &a, const auto &b) {
		long long getA = (long long)get<1>(a) * get<0>(b), getB = (long long)get<1>(b) * get<0>(a);
		return getA > getB || (getA == getB && get<2>(a) < get<2>(b));
	};
	sort(events.begin(),events.end(),[&](const auto &a, const auto &b) {return cmp(a,b);});
	long long ret = 0, pre = 0;
	for (int i = 0; i < n; i++) {
		pos[pts[i][3]] = i+1; ret = max(ret,(long long)pts[i][2]);
		pre += pts[i][2]; vAt[i+1] = pre; pAt[i+1] = pts[i][3];
		update(i+1,pre);
	}
	vector<vector<array<int,2>>> cur;
	auto solve = [&] () {
		for (auto &v : cur) {
			int mn = 1e9, mx = -1e9;
			for (auto &[i,j] : v) mn = min({mn,pos[i],pos[j]}), mx = max({mx,pos[i],pos[j]});
			assert(mx - mn + 1 <= (int)v.size() + 1);
			reverse(pAt.begin()+mn,pAt.begin()+mx+1);
			for (int i = mn; i <= mx; i++) {
				pos[pAt[i]] = i;
				vAt[i] = vAt[i-1] + ow[pAt[i]];
				update(i,vAt[i]);
			}
		}
		for (auto &v : cur) {
			int mn = 1e9, mx = -1e9;
			for (auto &[i,j] : v) mn = min({mn,pos[i],pos[j]}), mx = max({mx,pos[i],pos[j]});
			//go right
			long long get = queryMax(mx,n);
			for (int i = mx; i >= mn-1; i--) ret = max(ret,get - vAt[i]);
			//go left
			get = min(0LL,queryMin(1,mn-1));
			for (int i = mn-1; i <= mx; i++) ret = max(ret,vAt[i] - get);
			//go middle?
			long long best = vAt[mn-1];
			for (int i = mn; i <= mx; i++) {
				best = min(best,vAt[i]);
				ret = max(ret,vAt[i] - best);
			}
		}
	};
	for (int idx = 0; idx < (int)events.size(); idx++) {
		if (idx > 0 && (long long)get<1>(events[idx]) * get<0>(events[idx-1]) != (long long)get<0>(events[idx]) * get<1>(events[idx-1])) {
			solve();
			cur.clear();
		}
		if (!cur.empty() && cmp(events[idx],events[idx-1]) == cmp(events[idx-1],events[idx])) cur.back().push_back({get<3>(events[idx]),get<4>(events[idx])});
		else cur.push_back({{get<3>(events[idx]),get<4>(events[idx])}});
	}
	if (!cur.empty()) solve();
	printf ("%lld\n",ret);
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:33:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  int n,c=0; scanf ("%d",&n);
      |             ~~~~~~^~~~~~~~~
bulldozer.cpp:36:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  for (auto &[x,y,w,id] : pts) scanf ("%d %d %d",&x,&y,&w), id=c++, ow[id] = w;
      |                               ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 680 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 3 ms 552 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 3 ms 592 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 3 ms 588 KB Output is correct
29 Correct 3 ms 592 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 3 ms 552 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 3 ms 592 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 3 ms 588 KB Output is correct
29 Correct 3 ms 592 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 4 ms 588 KB Output is correct
33 Correct 1160 ms 49800 KB Output is correct
34 Correct 1169 ms 49736 KB Output is correct
35 Correct 1163 ms 49784 KB Output is correct
36 Correct 1183 ms 49784 KB Output is correct
37 Correct 1179 ms 49784 KB Output is correct
38 Correct 1165 ms 49788 KB Output is correct
39 Correct 1184 ms 49748 KB Output is correct
40 Correct 1142 ms 49808 KB Output is correct
41 Correct 1157 ms 49912 KB Output is correct
42 Correct 1165 ms 49764 KB Output is correct
43 Correct 1122 ms 49788 KB Output is correct
44 Correct 1102 ms 49784 KB Output is correct
45 Correct 1101 ms 49784 KB Output is correct
46 Correct 1108 ms 49784 KB Output is correct
47 Correct 1104 ms 49788 KB Output is correct
48 Correct 1127 ms 49784 KB Output is correct
49 Correct 1108 ms 49692 KB Output is correct
50 Correct 1174 ms 49736 KB Output is correct
51 Correct 1115 ms 49780 KB Output is correct
52 Correct 1129 ms 49776 KB Output is correct
53 Correct 1155 ms 49764 KB Output is correct
54 Correct 1104 ms 49708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 3 ms 552 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 3 ms 592 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 3 ms 588 KB Output is correct
29 Correct 3 ms 592 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 4 ms 588 KB Output is correct
33 Correct 1160 ms 49800 KB Output is correct
34 Correct 1169 ms 49736 KB Output is correct
35 Correct 1163 ms 49784 KB Output is correct
36 Correct 1183 ms 49784 KB Output is correct
37 Correct 1179 ms 49784 KB Output is correct
38 Correct 1165 ms 49788 KB Output is correct
39 Correct 1184 ms 49748 KB Output is correct
40 Correct 1142 ms 49808 KB Output is correct
41 Correct 1157 ms 49912 KB Output is correct
42 Correct 1165 ms 49764 KB Output is correct
43 Correct 1122 ms 49788 KB Output is correct
44 Correct 1102 ms 49784 KB Output is correct
45 Correct 1101 ms 49784 KB Output is correct
46 Correct 1108 ms 49784 KB Output is correct
47 Correct 1104 ms 49788 KB Output is correct
48 Correct 1127 ms 49784 KB Output is correct
49 Correct 1108 ms 49692 KB Output is correct
50 Correct 1174 ms 49736 KB Output is correct
51 Correct 1115 ms 49780 KB Output is correct
52 Correct 1129 ms 49776 KB Output is correct
53 Correct 1155 ms 49764 KB Output is correct
54 Correct 1104 ms 49708 KB Output is correct
55 Correct 1148 ms 49720 KB Output is correct
56 Correct 1144 ms 49784 KB Output is correct
57 Correct 1152 ms 49716 KB Output is correct
58 Correct 1150 ms 49784 KB Output is correct
59 Correct 1162 ms 50040 KB Output is correct
60 Correct 1153 ms 49788 KB Output is correct
61 Correct 1144 ms 49844 KB Output is correct
62 Correct 1147 ms 49784 KB Output is correct
63 Correct 1154 ms 49928 KB Output is correct
64 Correct 1170 ms 49880 KB Output is correct
65 Correct 1148 ms 49748 KB Output is correct
66 Correct 1135 ms 49768 KB Output is correct
67 Correct 1153 ms 49828 KB Output is correct
68 Correct 1149 ms 49804 KB Output is correct
69 Correct 1148 ms 49788 KB Output is correct
70 Correct 1140 ms 49804 KB Output is correct
71 Correct 1147 ms 49784 KB Output is correct
72 Correct 1135 ms 49760 KB Output is correct
73 Correct 1145 ms 49752 KB Output is correct
74 Correct 1152 ms 49808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 680 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 588 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 3 ms 588 KB Output is correct
25 Correct 3 ms 552 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 3 ms 588 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 3 ms 588 KB Output is correct
39 Correct 3 ms 588 KB Output is correct
40 Correct 3 ms 592 KB Output is correct
41 Correct 3 ms 588 KB Output is correct
42 Correct 3 ms 588 KB Output is correct
43 Correct 3 ms 588 KB Output is correct
44 Correct 3 ms 592 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 3 ms 588 KB Output is correct
47 Correct 4 ms 588 KB Output is correct
48 Correct 1160 ms 49800 KB Output is correct
49 Correct 1169 ms 49736 KB Output is correct
50 Correct 1163 ms 49784 KB Output is correct
51 Correct 1183 ms 49784 KB Output is correct
52 Correct 1179 ms 49784 KB Output is correct
53 Correct 1165 ms 49788 KB Output is correct
54 Correct 1184 ms 49748 KB Output is correct
55 Correct 1142 ms 49808 KB Output is correct
56 Correct 1157 ms 49912 KB Output is correct
57 Correct 1165 ms 49764 KB Output is correct
58 Correct 1122 ms 49788 KB Output is correct
59 Correct 1102 ms 49784 KB Output is correct
60 Correct 1101 ms 49784 KB Output is correct
61 Correct 1108 ms 49784 KB Output is correct
62 Correct 1104 ms 49788 KB Output is correct
63 Correct 1127 ms 49784 KB Output is correct
64 Correct 1108 ms 49692 KB Output is correct
65 Correct 1174 ms 49736 KB Output is correct
66 Correct 1115 ms 49780 KB Output is correct
67 Correct 1129 ms 49776 KB Output is correct
68 Correct 1155 ms 49764 KB Output is correct
69 Correct 1104 ms 49708 KB Output is correct
70 Correct 1148 ms 49720 KB Output is correct
71 Correct 1144 ms 49784 KB Output is correct
72 Correct 1152 ms 49716 KB Output is correct
73 Correct 1150 ms 49784 KB Output is correct
74 Correct 1162 ms 50040 KB Output is correct
75 Correct 1153 ms 49788 KB Output is correct
76 Correct 1144 ms 49844 KB Output is correct
77 Correct 1147 ms 49784 KB Output is correct
78 Correct 1154 ms 49928 KB Output is correct
79 Correct 1170 ms 49880 KB Output is correct
80 Correct 1148 ms 49748 KB Output is correct
81 Correct 1135 ms 49768 KB Output is correct
82 Correct 1153 ms 49828 KB Output is correct
83 Correct 1149 ms 49804 KB Output is correct
84 Correct 1148 ms 49788 KB Output is correct
85 Correct 1140 ms 49804 KB Output is correct
86 Correct 1147 ms 49784 KB Output is correct
87 Correct 1135 ms 49760 KB Output is correct
88 Correct 1145 ms 49752 KB Output is correct
89 Correct 1152 ms 49808 KB Output is correct
90 Correct 1151 ms 49756 KB Output is correct
91 Correct 1159 ms 49736 KB Output is correct
92 Correct 1153 ms 49780 KB Output is correct
93 Correct 1144 ms 49824 KB Output is correct
94 Correct 1147 ms 49840 KB Output is correct
95 Correct 1144 ms 49788 KB Output is correct
96 Correct 1136 ms 49784 KB Output is correct
97 Correct 1146 ms 49696 KB Output is correct
98 Correct 1143 ms 49784 KB Output is correct
99 Correct 1148 ms 49724 KB Output is correct
100 Correct 618 ms 59364 KB Output is correct
101 Correct 612 ms 59332 KB Output is correct
102 Correct 610 ms 59832 KB Output is correct
103 Correct 604 ms 59260 KB Output is correct
104 Correct 606 ms 59336 KB Output is correct
105 Correct 728 ms 54776 KB Output is correct
106 Correct 722 ms 54596 KB Output is correct
107 Correct 727 ms 54596 KB Output is correct
108 Correct 721 ms 54596 KB Output is correct
109 Correct 732 ms 54648 KB Output is correct
110 Correct 812 ms 49784 KB Output is correct
111 Correct 812 ms 49784 KB Output is correct
112 Correct 817 ms 49784 KB Output is correct
113 Correct 823 ms 49660 KB Output is correct
114 Correct 828 ms 49716 KB Output is correct
115 Correct 831 ms 49784 KB Output is correct
116 Correct 814 ms 49780 KB Output is correct
117 Correct 821 ms 49784 KB Output is correct
118 Correct 875 ms 49740 KB Output is correct
119 Correct 837 ms 49772 KB Output is correct
120 Correct 1 ms 296 KB Output is correct
121 Correct 1 ms 204 KB Output is correct
122 Correct 1068 ms 49760 KB Output is correct
123 Correct 1051 ms 49724 KB Output is correct
124 Correct 1060 ms 49680 KB Output is correct
125 Correct 1099 ms 49692 KB Output is correct
126 Correct 1073 ms 49784 KB Output is correct
127 Correct 1052 ms 49852 KB Output is correct
128 Correct 1067 ms 49784 KB Output is correct
129 Correct 1056 ms 49720 KB Output is correct
130 Correct 1070 ms 49784 KB Output is correct
131 Correct 1039 ms 49784 KB Output is correct
132 Correct 1040 ms 49784 KB Output is correct
133 Correct 1026 ms 49700 KB Output is correct