답안 #676909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676909 2023-01-01T14:28:48 Z ymm Bulldozer (JOI17_bulldozer) C++17
100 / 100
1273 ms 50108 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;
		Angle a = {pnt[j].first - pnt[i].first, pnt[j].second - pnt[i].second};
		if (reg(a) >= 4)
			continue;
		vec.push_back({a, {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:133: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]
  133 |  for (int i = 0; i < vec.size(); ++i) {
      |                  ~~^~~~~~~~~~~~
bulldozer.cpp:135: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]
  135 |   while (j < vec.size() && !(vec[i].first < vec[j].first))
      |          ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 608 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 608 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 1223 ms 49948 KB Output is correct
34 Correct 1220 ms 49968 KB Output is correct
35 Correct 1200 ms 49984 KB Output is correct
36 Correct 1194 ms 49924 KB Output is correct
37 Correct 1197 ms 49948 KB Output is correct
38 Correct 1221 ms 49948 KB Output is correct
39 Correct 1207 ms 49948 KB Output is correct
40 Correct 1212 ms 50052 KB Output is correct
41 Correct 1247 ms 49924 KB Output is correct
42 Correct 1273 ms 50080 KB Output is correct
43 Correct 1191 ms 49924 KB Output is correct
44 Correct 1186 ms 49972 KB Output is correct
45 Correct 1190 ms 50024 KB Output is correct
46 Correct 1156 ms 49948 KB Output is correct
47 Correct 1169 ms 50064 KB Output is correct
48 Correct 1177 ms 49964 KB Output is correct
49 Correct 1258 ms 49944 KB Output is correct
50 Correct 1248 ms 50044 KB Output is correct
51 Correct 1226 ms 50020 KB Output is correct
52 Correct 1219 ms 49924 KB Output is correct
53 Correct 1256 ms 49968 KB Output is correct
54 Correct 1246 ms 49960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 608 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 1223 ms 49948 KB Output is correct
34 Correct 1220 ms 49968 KB Output is correct
35 Correct 1200 ms 49984 KB Output is correct
36 Correct 1194 ms 49924 KB Output is correct
37 Correct 1197 ms 49948 KB Output is correct
38 Correct 1221 ms 49948 KB Output is correct
39 Correct 1207 ms 49948 KB Output is correct
40 Correct 1212 ms 50052 KB Output is correct
41 Correct 1247 ms 49924 KB Output is correct
42 Correct 1273 ms 50080 KB Output is correct
43 Correct 1191 ms 49924 KB Output is correct
44 Correct 1186 ms 49972 KB Output is correct
45 Correct 1190 ms 50024 KB Output is correct
46 Correct 1156 ms 49948 KB Output is correct
47 Correct 1169 ms 50064 KB Output is correct
48 Correct 1177 ms 49964 KB Output is correct
49 Correct 1258 ms 49944 KB Output is correct
50 Correct 1248 ms 50044 KB Output is correct
51 Correct 1226 ms 50020 KB Output is correct
52 Correct 1219 ms 49924 KB Output is correct
53 Correct 1256 ms 49968 KB Output is correct
54 Correct 1246 ms 49960 KB Output is correct
55 Correct 1227 ms 50044 KB Output is correct
56 Correct 1205 ms 49952 KB Output is correct
57 Correct 1216 ms 49940 KB Output is correct
58 Correct 1177 ms 50004 KB Output is correct
59 Correct 1189 ms 49936 KB Output is correct
60 Correct 1259 ms 49960 KB Output is correct
61 Correct 1213 ms 50016 KB Output is correct
62 Correct 1234 ms 49904 KB Output is correct
63 Correct 1245 ms 49960 KB Output is correct
64 Correct 1231 ms 49980 KB Output is correct
65 Correct 1237 ms 49984 KB Output is correct
66 Correct 1248 ms 49980 KB Output is correct
67 Correct 1253 ms 49972 KB Output is correct
68 Correct 1213 ms 49944 KB Output is correct
69 Correct 1211 ms 50012 KB Output is correct
70 Correct 1240 ms 49960 KB Output is correct
71 Correct 1192 ms 49948 KB Output is correct
72 Correct 1174 ms 49988 KB Output is correct
73 Correct 1188 ms 49924 KB Output is correct
74 Correct 1179 ms 49972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 2 ms 608 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 3 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 3 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 596 KB Output is correct
48 Correct 1223 ms 49948 KB Output is correct
49 Correct 1220 ms 49968 KB Output is correct
50 Correct 1200 ms 49984 KB Output is correct
51 Correct 1194 ms 49924 KB Output is correct
52 Correct 1197 ms 49948 KB Output is correct
53 Correct 1221 ms 49948 KB Output is correct
54 Correct 1207 ms 49948 KB Output is correct
55 Correct 1212 ms 50052 KB Output is correct
56 Correct 1247 ms 49924 KB Output is correct
57 Correct 1273 ms 50080 KB Output is correct
58 Correct 1191 ms 49924 KB Output is correct
59 Correct 1186 ms 49972 KB Output is correct
60 Correct 1190 ms 50024 KB Output is correct
61 Correct 1156 ms 49948 KB Output is correct
62 Correct 1169 ms 50064 KB Output is correct
63 Correct 1177 ms 49964 KB Output is correct
64 Correct 1258 ms 49944 KB Output is correct
65 Correct 1248 ms 50044 KB Output is correct
66 Correct 1226 ms 50020 KB Output is correct
67 Correct 1219 ms 49924 KB Output is correct
68 Correct 1256 ms 49968 KB Output is correct
69 Correct 1246 ms 49960 KB Output is correct
70 Correct 1227 ms 50044 KB Output is correct
71 Correct 1205 ms 49952 KB Output is correct
72 Correct 1216 ms 49940 KB Output is correct
73 Correct 1177 ms 50004 KB Output is correct
74 Correct 1189 ms 49936 KB Output is correct
75 Correct 1259 ms 49960 KB Output is correct
76 Correct 1213 ms 50016 KB Output is correct
77 Correct 1234 ms 49904 KB Output is correct
78 Correct 1245 ms 49960 KB Output is correct
79 Correct 1231 ms 49980 KB Output is correct
80 Correct 1237 ms 49984 KB Output is correct
81 Correct 1248 ms 49980 KB Output is correct
82 Correct 1253 ms 49972 KB Output is correct
83 Correct 1213 ms 49944 KB Output is correct
84 Correct 1211 ms 50012 KB Output is correct
85 Correct 1240 ms 49960 KB Output is correct
86 Correct 1192 ms 49948 KB Output is correct
87 Correct 1174 ms 49988 KB Output is correct
88 Correct 1188 ms 49924 KB Output is correct
89 Correct 1179 ms 49972 KB Output is correct
90 Correct 1209 ms 49948 KB Output is correct
91 Correct 1195 ms 49988 KB Output is correct
92 Correct 1194 ms 50096 KB Output is correct
93 Correct 1169 ms 50012 KB Output is correct
94 Correct 1174 ms 49956 KB Output is correct
95 Correct 1172 ms 49924 KB Output is correct
96 Correct 1162 ms 49960 KB Output is correct
97 Correct 1188 ms 49956 KB Output is correct
98 Correct 1171 ms 49964 KB Output is correct
99 Correct 1183 ms 49948 KB Output is correct
100 Correct 976 ms 49944 KB Output is correct
101 Correct 953 ms 50076 KB Output is correct
102 Correct 1010 ms 50016 KB Output is correct
103 Correct 1004 ms 49984 KB Output is correct
104 Correct 1035 ms 50020 KB Output is correct
105 Correct 1035 ms 50084 KB Output is correct
106 Correct 1047 ms 50000 KB Output is correct
107 Correct 1069 ms 49948 KB Output is correct
108 Correct 1082 ms 50052 KB Output is correct
109 Correct 1122 ms 49904 KB Output is correct
110 Correct 1135 ms 50032 KB Output is correct
111 Correct 1126 ms 49948 KB Output is correct
112 Correct 1101 ms 50044 KB Output is correct
113 Correct 1085 ms 49948 KB Output is correct
114 Correct 1114 ms 49956 KB Output is correct
115 Correct 1098 ms 49960 KB Output is correct
116 Correct 1112 ms 50028 KB Output is correct
117 Correct 1090 ms 49976 KB Output is correct
118 Correct 1084 ms 49948 KB Output is correct
119 Correct 1087 ms 49948 KB Output is correct
120 Correct 0 ms 212 KB Output is correct
121 Correct 0 ms 340 KB Output is correct
122 Correct 1151 ms 49940 KB Output is correct
123 Correct 1180 ms 49948 KB Output is correct
124 Correct 1209 ms 49924 KB Output is correct
125 Correct 1163 ms 49996 KB Output is correct
126 Correct 1171 ms 49948 KB Output is correct
127 Correct 1171 ms 49948 KB Output is correct
128 Correct 1217 ms 49948 KB Output is correct
129 Correct 1237 ms 50040 KB Output is correct
130 Correct 1237 ms 50000 KB Output is correct
131 Correct 1222 ms 49976 KB Output is correct
132 Correct 1224 ms 50108 KB Output is correct
133 Correct 1224 ms 49924 KB Output is correct