Submission #395220

# Submission time Handle Problem Language Result Execution time Memory
395220 2021-04-28T03:05:21 Z ChrisT Bulldozer (JOI17_bulldozer) C++17
80 / 100
2000 ms 82044 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<<2];
void update (int ind, int tl, int tr, int i, long long v) {
	if (tl == tr) {
		tree[ind].mx = tree[ind].mn = v;
		return;
	}
	int mid = (tl + tr) / 2;
	if (i <= mid) update(lc,tl,mid,i,v);
	else update(rc,mid+1,tr,i,v);
	tree[ind].mn = min(tree[lc].mn,tree[rc].mn);
	tree[ind].mx = max(tree[lc].mx,tree[rc].mx);
}
long long queryMin (int ind, int tl, int tr, int l, int r) {
	if (tl > r || tr < l) return LLONG_MAX;
	if (l <= tl && tr <= r) return tree[ind].mn;
	int mid = (tl + tr) / 2;
	return min(queryMin(lc,tl,mid,l,r),queryMin(rc,mid+1,tr,l,r));
}
long long queryMax (int ind, int tl, int tr, int l, int r) {
	if (tl > r || tr < l) return LLONG_MIN;
	if (l <= tl && tr <= r) return tree[ind].mx;
	int mid = (tl + tr) / 2;
	return max(queryMax(lc,tl,mid,l,r),queryMax(rc,mid+1,tr,l,r));
}
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];
			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(1,1,n,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]});
			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(1,1,n,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(1,1,n,mx,n);
			for (int i = mx; i >= mn-1; i--) ret = max(ret,get - vAt[i]);
			//go left
			get = min(0LL,queryMin(1,1,n,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();
	//for (auto &[x,y,b,i,j] : events) {
	//	if (pos[i] > pos[j]) swap(i,j);
	//	ret = max(ret,vAt[pos[j]] - min(0LL,queryMin(1,1,n,1,pos[i]-1)) - min(0,ow[i]) - min(0,ow[j]));
	//	ret = max(ret,queryMax(1,1,n,pos[j],n) - (pos[i] == 1 ? 0LL : vAt[pos[i]-1]) - min(0,ow[i]) - min(0,ow[j]));
	//	update(1,1,n,pos[i],ow[j]-ow[i]); vAt[pos[i]] += ow[j] - ow[i];
	//	swap(pos[i],pos[j]);
	//}
	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;
      |                               ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 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 560 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 204 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 4 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 640 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 308 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 1 ms 204 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 4 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 560 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 588 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 3 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 4 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 640 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 308 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 1 ms 204 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 4 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 560 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 588 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 3 ms 588 KB Output is correct
33 Correct 1541 ms 49848 KB Output is correct
34 Correct 1521 ms 49808 KB Output is correct
35 Correct 1588 ms 49732 KB Output is correct
36 Correct 1536 ms 49840 KB Output is correct
37 Correct 1576 ms 49836 KB Output is correct
38 Correct 1559 ms 49780 KB Output is correct
39 Correct 1581 ms 49752 KB Output is correct
40 Correct 1538 ms 49808 KB Output is correct
41 Correct 1556 ms 49788 KB Output is correct
42 Correct 1624 ms 49736 KB Output is correct
43 Correct 1562 ms 49784 KB Output is correct
44 Correct 1562 ms 49784 KB Output is correct
45 Correct 1493 ms 49808 KB Output is correct
46 Correct 1542 ms 49808 KB Output is correct
47 Correct 1526 ms 49764 KB Output is correct
48 Correct 1515 ms 49840 KB Output is correct
49 Correct 1527 ms 49784 KB Output is correct
50 Correct 1510 ms 49780 KB Output is correct
51 Correct 1497 ms 49808 KB Output is correct
52 Correct 1538 ms 49784 KB Output is correct
53 Correct 1497 ms 49808 KB Output is correct
54 Correct 1566 ms 49792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 4 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 640 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 308 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 1 ms 204 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 4 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 560 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 588 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 3 ms 588 KB Output is correct
33 Correct 1541 ms 49848 KB Output is correct
34 Correct 1521 ms 49808 KB Output is correct
35 Correct 1588 ms 49732 KB Output is correct
36 Correct 1536 ms 49840 KB Output is correct
37 Correct 1576 ms 49836 KB Output is correct
38 Correct 1559 ms 49780 KB Output is correct
39 Correct 1581 ms 49752 KB Output is correct
40 Correct 1538 ms 49808 KB Output is correct
41 Correct 1556 ms 49788 KB Output is correct
42 Correct 1624 ms 49736 KB Output is correct
43 Correct 1562 ms 49784 KB Output is correct
44 Correct 1562 ms 49784 KB Output is correct
45 Correct 1493 ms 49808 KB Output is correct
46 Correct 1542 ms 49808 KB Output is correct
47 Correct 1526 ms 49764 KB Output is correct
48 Correct 1515 ms 49840 KB Output is correct
49 Correct 1527 ms 49784 KB Output is correct
50 Correct 1510 ms 49780 KB Output is correct
51 Correct 1497 ms 49808 KB Output is correct
52 Correct 1538 ms 49784 KB Output is correct
53 Correct 1497 ms 49808 KB Output is correct
54 Correct 1566 ms 49792 KB Output is correct
55 Correct 1587 ms 49808 KB Output is correct
56 Correct 1521 ms 49784 KB Output is correct
57 Correct 1541 ms 49808 KB Output is correct
58 Correct 1529 ms 49808 KB Output is correct
59 Correct 1531 ms 49776 KB Output is correct
60 Correct 1542 ms 49784 KB Output is correct
61 Correct 1548 ms 49792 KB Output is correct
62 Correct 1613 ms 49728 KB Output is correct
63 Correct 1549 ms 49812 KB Output is correct
64 Correct 1553 ms 49772 KB Output is correct
65 Correct 1575 ms 49784 KB Output is correct
66 Correct 1516 ms 49740 KB Output is correct
67 Correct 1528 ms 49864 KB Output is correct
68 Correct 1630 ms 49804 KB Output is correct
69 Correct 1550 ms 49808 KB Output is correct
70 Correct 1556 ms 49808 KB Output is correct
71 Correct 1526 ms 49808 KB Output is correct
72 Correct 1526 ms 49784 KB Output is correct
73 Correct 1537 ms 49808 KB Output is correct
74 Correct 1514 ms 49816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 1 ms 556 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 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 560 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 204 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 4 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 640 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 3 ms 560 KB Output is correct
25 Correct 3 ms 588 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 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 4 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 560 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 588 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 3 ms 588 KB Output is correct
47 Correct 3 ms 588 KB Output is correct
48 Correct 1541 ms 49848 KB Output is correct
49 Correct 1521 ms 49808 KB Output is correct
50 Correct 1588 ms 49732 KB Output is correct
51 Correct 1536 ms 49840 KB Output is correct
52 Correct 1576 ms 49836 KB Output is correct
53 Correct 1559 ms 49780 KB Output is correct
54 Correct 1581 ms 49752 KB Output is correct
55 Correct 1538 ms 49808 KB Output is correct
56 Correct 1556 ms 49788 KB Output is correct
57 Correct 1624 ms 49736 KB Output is correct
58 Correct 1562 ms 49784 KB Output is correct
59 Correct 1562 ms 49784 KB Output is correct
60 Correct 1493 ms 49808 KB Output is correct
61 Correct 1542 ms 49808 KB Output is correct
62 Correct 1526 ms 49764 KB Output is correct
63 Correct 1515 ms 49840 KB Output is correct
64 Correct 1527 ms 49784 KB Output is correct
65 Correct 1510 ms 49780 KB Output is correct
66 Correct 1497 ms 49808 KB Output is correct
67 Correct 1538 ms 49784 KB Output is correct
68 Correct 1497 ms 49808 KB Output is correct
69 Correct 1566 ms 49792 KB Output is correct
70 Correct 1587 ms 49808 KB Output is correct
71 Correct 1521 ms 49784 KB Output is correct
72 Correct 1541 ms 49808 KB Output is correct
73 Correct 1529 ms 49808 KB Output is correct
74 Correct 1531 ms 49776 KB Output is correct
75 Correct 1542 ms 49784 KB Output is correct
76 Correct 1548 ms 49792 KB Output is correct
77 Correct 1613 ms 49728 KB Output is correct
78 Correct 1549 ms 49812 KB Output is correct
79 Correct 1553 ms 49772 KB Output is correct
80 Correct 1575 ms 49784 KB Output is correct
81 Correct 1516 ms 49740 KB Output is correct
82 Correct 1528 ms 49864 KB Output is correct
83 Correct 1630 ms 49804 KB Output is correct
84 Correct 1550 ms 49808 KB Output is correct
85 Correct 1556 ms 49808 KB Output is correct
86 Correct 1526 ms 49808 KB Output is correct
87 Correct 1526 ms 49784 KB Output is correct
88 Correct 1537 ms 49808 KB Output is correct
89 Correct 1514 ms 49816 KB Output is correct
90 Correct 1524 ms 49776 KB Output is correct
91 Correct 1538 ms 49784 KB Output is correct
92 Correct 1527 ms 49808 KB Output is correct
93 Correct 1537 ms 49772 KB Output is correct
94 Correct 1525 ms 49784 KB Output is correct
95 Correct 1516 ms 49720 KB Output is correct
96 Correct 1514 ms 49808 KB Output is correct
97 Correct 1518 ms 49808 KB Output is correct
98 Correct 1530 ms 49808 KB Output is correct
99 Correct 1519 ms 49812 KB Output is correct
100 Execution timed out 2074 ms 82044 KB Time limit exceeded
101 Halted 0 ms 0 KB -