Submission #676905

# Submission time Handle Problem Language Result Execution time Memory
676905 2023-01-01T14:19:59 Z ymm Bulldozer (JOI17_bulldozer) C++17
25 / 100
2000 ms 99244 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

class Seg {
private:
	int sz;
	struct node {
		ll val, pre, suf, tot;
	} *t;

	void merge(int i) {
		node &l = t[2*i+1], &r = t[2*i+2];
		t[i].tot = l.tot + r.tot;
		t[i].pre = max(l.pre, l.tot + r.pre);
		t[i].suf = max(r.suf, r.tot + l.suf);
		t[i].val = max({l.val, r.val, l.suf + r.pre});
	}
	void up_impl(int p, ll x, int i, int b, int e) {
		if (e-b == 1) {
			ll y = max(x, 0ll);
			t[i] = {y, y, y, x};
			return;
		}
		if (p < (b+e)/2)
			up_impl(p, x, 2*i+1, b, (b+e)/2);
		else
			up_impl(p, x, 2*i+2, (b+e)/2, e);
		merge(i);
	}
public:
	void init(int n) {
		sz = n;
		t = new node[4*n]{};
	}
	void up(int p, ll x) { up_impl(p, x, 0, 0, sz); }
	ll get_max() { return t[0].val; }
} seg;

const int N = 2048;
int pos[N];
int ord[N];
ll val[N];

void swap_pnt_pos(int x, int y)
{
	int i = ord[x];
	int j = ord[y];
	seg.up(pos[i], val[j]);
	seg.up(pos[j], val[i]);
	swap(pos[i], pos[j]);
	swap(ord[x], ord[y]);
}

struct Angle {
	ll x, y;
};
int reg(Angle a)
{
	if (a.x > 0 && a.y == 0)
		return 0;
	if (a.x > 0 && a.y > 0)
		return 1;
	if (a.x == 0 && a.y > 0)
		return 2;
	if (a.x < 0 && a.y > 0)
		return 3;
	if (a.x < 0 && a.y == 0)
		return 4;
	if (a.x < 0 && a.y < 0)
		return 5;
	if (a.x == 0 && a.y < 0)
		return 6;
	if (a.x > 0 && a.y < 0)
		return 7;
	return -1;
}
ll sign(ll x) { return x < 0? -1: 1; }
bool operator<(Angle x, Angle y)
{
	int r1 = reg(x), r2 = reg(y);
	if (r1 != r2)
		return r1 < r2;
	if (r1%2 == 0)
		return 0;
	// x.y / x.x < y.y / y.x
	return x.y * y.x * sign(x.x * y.x) < y.y * x.x * sign(x.x * y.x);
}

pll pnt[N];

bool init_cmp_pnt(int i, int j)
{
	if (pnt[i].second != pnt[j].second)
		return pnt[i].second < pnt[j].second;
	else
		return pnt[i].first < pnt[j].first;
}

int n;

int is_left[N], id = 0;
vector<pair<Angle,pii>> vec;

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	Loop (i,0,n) {
		cin >> pnt[i].first >> pnt[i].second >> val[i];
		ord[i] = i;
	}
	sort(ord, ord+n, init_cmp_pnt);
	Loop (i,0,n)
		pos[ord[i]] = i;
	seg.init(n);
	Loop (i,0,n)
		seg.up(pos[i], val[i]);
	ll ans = seg.get_max();
	Loop (i,0,n) Loop (j,0,n) {
		if (i == j)
			continue;
		vec.push_back({{pnt[j].first - pnt[i].first, pnt[j].second - pnt[i].second}, {i, j}});
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < vec.size(); ++i) {
		int j = i;
		while (j < vec.size() && !(vec[i].first < vec[j].first))
			++j;
		++id;
		set<int> pnts;
		Loop (k,i,j) {
			auto [x, y] = vec[k].second;
			assert(pos[x] < pos[y]);
			is_left[pos[x]] = id;
			pnts.insert(x);
		}
		int dard = 0;
		for (int k : pnts) {
			int l = pos[k];
			if (is_left[l-1] == id)
				continue;
			int r = l+1;
			while (r < n && is_left[r-1] == id)
				++r;
			Loop (x,l,(l+r)/2)
				swap_pnt_pos(x, l+r-x-1);
			dard += r-l;
		}
		i = j-1;
		ans = max(ans, seg.get_max());
	}
	cout << ans << '\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:130:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Angle, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |  for (int i = 0; i < vec.size(); ++i) {
      |                  ~~^~~~~~~~~~~~
bulldozer.cpp:132:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Angle, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |   while (j < vec.size() && !(vec[i].first < vec[j].first))
      |          ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 792 KB Output is correct
2 Correct 3 ms 772 KB Output is correct
3 Correct 3 ms 792 KB Output is correct
4 Correct 3 ms 792 KB Output is correct
5 Correct 3 ms 792 KB Output is correct
6 Correct 3 ms 776 KB Output is correct
7 Correct 3 ms 776 KB Output is correct
8 Correct 4 ms 776 KB Output is correct
9 Correct 4 ms 776 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 772 KB Output is correct
2 Correct 5 ms 804 KB Output is correct
3 Correct 4 ms 792 KB Output is correct
4 Correct 4 ms 792 KB Output is correct
5 Correct 5 ms 792 KB Output is correct
6 Correct 6 ms 792 KB Output is correct
7 Correct 4 ms 792 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 5 ms 772 KB Output is correct
10 Correct 6 ms 792 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 340 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 792 KB Output is correct
22 Correct 4 ms 792 KB Output is correct
23 Correct 4 ms 792 KB Output is correct
24 Correct 5 ms 792 KB Output is correct
25 Correct 4 ms 792 KB Output is correct
26 Correct 4 ms 792 KB Output is correct
27 Correct 4 ms 772 KB Output is correct
28 Correct 5 ms 792 KB Output is correct
29 Correct 5 ms 792 KB Output is correct
30 Correct 5 ms 784 KB Output is correct
31 Correct 5 ms 776 KB Output is correct
32 Correct 5 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 772 KB Output is correct
2 Correct 5 ms 804 KB Output is correct
3 Correct 4 ms 792 KB Output is correct
4 Correct 4 ms 792 KB Output is correct
5 Correct 5 ms 792 KB Output is correct
6 Correct 6 ms 792 KB Output is correct
7 Correct 4 ms 792 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 5 ms 772 KB Output is correct
10 Correct 6 ms 792 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 340 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 792 KB Output is correct
22 Correct 4 ms 792 KB Output is correct
23 Correct 4 ms 792 KB Output is correct
24 Correct 5 ms 792 KB Output is correct
25 Correct 4 ms 792 KB Output is correct
26 Correct 4 ms 792 KB Output is correct
27 Correct 4 ms 772 KB Output is correct
28 Correct 5 ms 792 KB Output is correct
29 Correct 5 ms 792 KB Output is correct
30 Correct 5 ms 784 KB Output is correct
31 Correct 5 ms 776 KB Output is correct
32 Correct 5 ms 792 KB Output is correct
33 Execution timed out 2095 ms 99244 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 772 KB Output is correct
2 Correct 5 ms 804 KB Output is correct
3 Correct 4 ms 792 KB Output is correct
4 Correct 4 ms 792 KB Output is correct
5 Correct 5 ms 792 KB Output is correct
6 Correct 6 ms 792 KB Output is correct
7 Correct 4 ms 792 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 5 ms 772 KB Output is correct
10 Correct 6 ms 792 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 340 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 792 KB Output is correct
22 Correct 4 ms 792 KB Output is correct
23 Correct 4 ms 792 KB Output is correct
24 Correct 5 ms 792 KB Output is correct
25 Correct 4 ms 792 KB Output is correct
26 Correct 4 ms 792 KB Output is correct
27 Correct 4 ms 772 KB Output is correct
28 Correct 5 ms 792 KB Output is correct
29 Correct 5 ms 792 KB Output is correct
30 Correct 5 ms 784 KB Output is correct
31 Correct 5 ms 776 KB Output is correct
32 Correct 5 ms 792 KB Output is correct
33 Execution timed out 2095 ms 99244 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 792 KB Output is correct
2 Correct 3 ms 772 KB Output is correct
3 Correct 3 ms 792 KB Output is correct
4 Correct 3 ms 792 KB Output is correct
5 Correct 3 ms 792 KB Output is correct
6 Correct 3 ms 776 KB Output is correct
7 Correct 3 ms 776 KB Output is correct
8 Correct 4 ms 776 KB Output is correct
9 Correct 4 ms 776 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 772 KB Output is correct
17 Correct 5 ms 804 KB Output is correct
18 Correct 4 ms 792 KB Output is correct
19 Correct 4 ms 792 KB Output is correct
20 Correct 5 ms 792 KB Output is correct
21 Correct 6 ms 792 KB Output is correct
22 Correct 4 ms 792 KB Output is correct
23 Correct 4 ms 792 KB Output is correct
24 Correct 5 ms 772 KB Output is correct
25 Correct 6 ms 792 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 340 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 5 ms 792 KB Output is correct
37 Correct 4 ms 792 KB Output is correct
38 Correct 4 ms 792 KB Output is correct
39 Correct 5 ms 792 KB Output is correct
40 Correct 4 ms 792 KB Output is correct
41 Correct 4 ms 792 KB Output is correct
42 Correct 4 ms 772 KB Output is correct
43 Correct 5 ms 792 KB Output is correct
44 Correct 5 ms 792 KB Output is correct
45 Correct 5 ms 784 KB Output is correct
46 Correct 5 ms 776 KB Output is correct
47 Correct 5 ms 792 KB Output is correct
48 Execution timed out 2095 ms 99244 KB Time limit exceeded
49 Halted 0 ms 0 KB -