Submission #676906

# Submission time Handle Problem Language Result Execution time Memory
676906 2023-01-01T14:22:29 Z ymm Bulldozer (JOI17_bulldozer) C++17
100 / 100
1977 ms 99468 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) {
		if (reg(vec[i].first) >= 4)
			break;
		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:134: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]
  134 |   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 792 KB Output is correct
3 Correct 3 ms 784 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 792 KB Output is correct
7 Correct 3 ms 792 KB Output is correct
8 Correct 3 ms 792 KB Output is correct
9 Correct 3 ms 792 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 792 KB Output is correct
2 Correct 3 ms 792 KB Output is correct
3 Correct 4 ms 792 KB Output is correct
4 Correct 4 ms 792 KB Output is correct
5 Correct 4 ms 792 KB Output is correct
6 Correct 4 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 4 ms 792 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 324 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 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 4 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 5 ms 792 KB Output is correct
28 Correct 3 ms 792 KB Output is correct
29 Correct 3 ms 792 KB Output is correct
30 Correct 3 ms 792 KB Output is correct
31 Correct 5 ms 792 KB Output is correct
32 Correct 4 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 792 KB Output is correct
2 Correct 3 ms 792 KB Output is correct
3 Correct 4 ms 792 KB Output is correct
4 Correct 4 ms 792 KB Output is correct
5 Correct 4 ms 792 KB Output is correct
6 Correct 4 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 4 ms 792 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 324 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 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 4 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 5 ms 792 KB Output is correct
28 Correct 3 ms 792 KB Output is correct
29 Correct 3 ms 792 KB Output is correct
30 Correct 3 ms 792 KB Output is correct
31 Correct 5 ms 792 KB Output is correct
32 Correct 4 ms 792 KB Output is correct
33 Correct 1932 ms 99280 KB Output is correct
34 Correct 1977 ms 99272 KB Output is correct
35 Correct 1898 ms 99384 KB Output is correct
36 Correct 1838 ms 99384 KB Output is correct
37 Correct 1809 ms 99292 KB Output is correct
38 Correct 1828 ms 99284 KB Output is correct
39 Correct 1839 ms 99420 KB Output is correct
40 Correct 1827 ms 99304 KB Output is correct
41 Correct 1805 ms 99320 KB Output is correct
42 Correct 1814 ms 99244 KB Output is correct
43 Correct 1809 ms 99276 KB Output is correct
44 Correct 1843 ms 99332 KB Output is correct
45 Correct 1820 ms 99272 KB Output is correct
46 Correct 1790 ms 99224 KB Output is correct
47 Correct 1827 ms 99260 KB Output is correct
48 Correct 1781 ms 99456 KB Output is correct
49 Correct 1810 ms 99284 KB Output is correct
50 Correct 1869 ms 99416 KB Output is correct
51 Correct 1835 ms 99340 KB Output is correct
52 Correct 1827 ms 99320 KB Output is correct
53 Correct 1843 ms 99248 KB Output is correct
54 Correct 1826 ms 99280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 792 KB Output is correct
2 Correct 3 ms 792 KB Output is correct
3 Correct 4 ms 792 KB Output is correct
4 Correct 4 ms 792 KB Output is correct
5 Correct 4 ms 792 KB Output is correct
6 Correct 4 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 4 ms 792 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 324 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 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 4 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 5 ms 792 KB Output is correct
28 Correct 3 ms 792 KB Output is correct
29 Correct 3 ms 792 KB Output is correct
30 Correct 3 ms 792 KB Output is correct
31 Correct 5 ms 792 KB Output is correct
32 Correct 4 ms 792 KB Output is correct
33 Correct 1932 ms 99280 KB Output is correct
34 Correct 1977 ms 99272 KB Output is correct
35 Correct 1898 ms 99384 KB Output is correct
36 Correct 1838 ms 99384 KB Output is correct
37 Correct 1809 ms 99292 KB Output is correct
38 Correct 1828 ms 99284 KB Output is correct
39 Correct 1839 ms 99420 KB Output is correct
40 Correct 1827 ms 99304 KB Output is correct
41 Correct 1805 ms 99320 KB Output is correct
42 Correct 1814 ms 99244 KB Output is correct
43 Correct 1809 ms 99276 KB Output is correct
44 Correct 1843 ms 99332 KB Output is correct
45 Correct 1820 ms 99272 KB Output is correct
46 Correct 1790 ms 99224 KB Output is correct
47 Correct 1827 ms 99260 KB Output is correct
48 Correct 1781 ms 99456 KB Output is correct
49 Correct 1810 ms 99284 KB Output is correct
50 Correct 1869 ms 99416 KB Output is correct
51 Correct 1835 ms 99340 KB Output is correct
52 Correct 1827 ms 99320 KB Output is correct
53 Correct 1843 ms 99248 KB Output is correct
54 Correct 1826 ms 99280 KB Output is correct
55 Correct 1802 ms 99284 KB Output is correct
56 Correct 1870 ms 99312 KB Output is correct
57 Correct 1813 ms 99328 KB Output is correct
58 Correct 1822 ms 99276 KB Output is correct
59 Correct 1844 ms 99332 KB Output is correct
60 Correct 1791 ms 99252 KB Output is correct
61 Correct 1820 ms 99452 KB Output is correct
62 Correct 1797 ms 99244 KB Output is correct
63 Correct 1799 ms 99392 KB Output is correct
64 Correct 1827 ms 99240 KB Output is correct
65 Correct 1830 ms 99308 KB Output is correct
66 Correct 1874 ms 99260 KB Output is correct
67 Correct 1838 ms 99296 KB Output is correct
68 Correct 1903 ms 99328 KB Output is correct
69 Correct 1820 ms 99220 KB Output is correct
70 Correct 1851 ms 99244 KB Output is correct
71 Correct 1818 ms 99328 KB Output is correct
72 Correct 1837 ms 99280 KB Output is correct
73 Correct 1854 ms 99276 KB Output is correct
74 Correct 1854 ms 99272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 792 KB Output is correct
2 Correct 3 ms 792 KB Output is correct
3 Correct 3 ms 784 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 792 KB Output is correct
7 Correct 3 ms 792 KB Output is correct
8 Correct 3 ms 792 KB Output is correct
9 Correct 3 ms 792 KB Output is correct
10 Correct 4 ms 792 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 3 ms 792 KB Output is correct
18 Correct 4 ms 792 KB Output is correct
19 Correct 4 ms 792 KB Output is correct
20 Correct 4 ms 792 KB Output is correct
21 Correct 4 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 4 ms 792 KB Output is correct
25 Correct 4 ms 792 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 3 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 4 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 5 ms 792 KB Output is correct
43 Correct 3 ms 792 KB Output is correct
44 Correct 3 ms 792 KB Output is correct
45 Correct 3 ms 792 KB Output is correct
46 Correct 5 ms 792 KB Output is correct
47 Correct 4 ms 792 KB Output is correct
48 Correct 1932 ms 99280 KB Output is correct
49 Correct 1977 ms 99272 KB Output is correct
50 Correct 1898 ms 99384 KB Output is correct
51 Correct 1838 ms 99384 KB Output is correct
52 Correct 1809 ms 99292 KB Output is correct
53 Correct 1828 ms 99284 KB Output is correct
54 Correct 1839 ms 99420 KB Output is correct
55 Correct 1827 ms 99304 KB Output is correct
56 Correct 1805 ms 99320 KB Output is correct
57 Correct 1814 ms 99244 KB Output is correct
58 Correct 1809 ms 99276 KB Output is correct
59 Correct 1843 ms 99332 KB Output is correct
60 Correct 1820 ms 99272 KB Output is correct
61 Correct 1790 ms 99224 KB Output is correct
62 Correct 1827 ms 99260 KB Output is correct
63 Correct 1781 ms 99456 KB Output is correct
64 Correct 1810 ms 99284 KB Output is correct
65 Correct 1869 ms 99416 KB Output is correct
66 Correct 1835 ms 99340 KB Output is correct
67 Correct 1827 ms 99320 KB Output is correct
68 Correct 1843 ms 99248 KB Output is correct
69 Correct 1826 ms 99280 KB Output is correct
70 Correct 1802 ms 99284 KB Output is correct
71 Correct 1870 ms 99312 KB Output is correct
72 Correct 1813 ms 99328 KB Output is correct
73 Correct 1822 ms 99276 KB Output is correct
74 Correct 1844 ms 99332 KB Output is correct
75 Correct 1791 ms 99252 KB Output is correct
76 Correct 1820 ms 99452 KB Output is correct
77 Correct 1797 ms 99244 KB Output is correct
78 Correct 1799 ms 99392 KB Output is correct
79 Correct 1827 ms 99240 KB Output is correct
80 Correct 1830 ms 99308 KB Output is correct
81 Correct 1874 ms 99260 KB Output is correct
82 Correct 1838 ms 99296 KB Output is correct
83 Correct 1903 ms 99328 KB Output is correct
84 Correct 1820 ms 99220 KB Output is correct
85 Correct 1851 ms 99244 KB Output is correct
86 Correct 1818 ms 99328 KB Output is correct
87 Correct 1837 ms 99280 KB Output is correct
88 Correct 1854 ms 99276 KB Output is correct
89 Correct 1854 ms 99272 KB Output is correct
90 Correct 1803 ms 99212 KB Output is correct
91 Correct 1792 ms 99328 KB Output is correct
92 Correct 1843 ms 99316 KB Output is correct
93 Correct 1789 ms 99328 KB Output is correct
94 Correct 1813 ms 99324 KB Output is correct
95 Correct 1834 ms 99224 KB Output is correct
96 Correct 1818 ms 99276 KB Output is correct
97 Correct 1836 ms 99208 KB Output is correct
98 Correct 1828 ms 99288 KB Output is correct
99 Correct 1835 ms 99244 KB Output is correct
100 Correct 1673 ms 99280 KB Output is correct
101 Correct 1653 ms 99224 KB Output is correct
102 Correct 1653 ms 99280 KB Output is correct
103 Correct 1609 ms 99248 KB Output is correct
104 Correct 1642 ms 99300 KB Output is correct
105 Correct 1714 ms 99200 KB Output is correct
106 Correct 1676 ms 99320 KB Output is correct
107 Correct 1700 ms 99284 KB Output is correct
108 Correct 1727 ms 99300 KB Output is correct
109 Correct 1754 ms 99420 KB Output is correct
110 Correct 1775 ms 99212 KB Output is correct
111 Correct 1770 ms 99380 KB Output is correct
112 Correct 1776 ms 99280 KB Output is correct
113 Correct 1846 ms 99280 KB Output is correct
114 Correct 1874 ms 99284 KB Output is correct
115 Correct 1814 ms 99468 KB Output is correct
116 Correct 1863 ms 99292 KB Output is correct
117 Correct 1802 ms 99308 KB Output is correct
118 Correct 1829 ms 99300 KB Output is correct
119 Correct 1846 ms 99292 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 1 ms 340 KB Output is correct
122 Correct 1824 ms 99280 KB Output is correct
123 Correct 1866 ms 99240 KB Output is correct
124 Correct 1846 ms 99324 KB Output is correct
125 Correct 1851 ms 99248 KB Output is correct
126 Correct 1791 ms 99340 KB Output is correct
127 Correct 1799 ms 99312 KB Output is correct
128 Correct 1818 ms 99276 KB Output is correct
129 Correct 1838 ms 99280 KB Output is correct
130 Correct 1817 ms 99280 KB Output is correct
131 Correct 1846 ms 99220 KB Output is correct
132 Correct 1816 ms 99280 KB Output is correct
133 Correct 1802 ms 99216 KB Output is correct