#include<bits/stdc++.h>
using namespace std;
#define float double
#define int long long
const float PI = 3.14159265358979323846;
const float EPSILON = 0.0000000001;
#define vec vector
struct SegNode {
int max_sss = 0;
int max_pref_sum = 0;
int max_suf_sum = 0;
int sum = 0;
SegNode merge(SegNode other) {
return {max(max(max_sss, other.max_sss), max_suf_sum+other.max_pref_sum),
max(max_pref_sum, sum+other.max_pref_sum),
max(other.max_suf_sum, max_suf_sum + other.sum),
sum + other.sum};
}
};
struct SegTree {
int n;
vec<SegNode> data;
SegTree(int in) {
n = 1;
while(n < in) n *= 2;
data = vec<SegNode>(n*2);
}
void set(int i, int val) {
i += n;
data[i] = SegNode {max(val, 0LL), max(val, 0LL), max(val, 0LL), val};
while(i > 1) {
i /= 2;
data[i] = data[i*2].merge(data[i*2+1]);
}
}
SegNode query(int l, int r, int i = 1, int ll = 0, int rr = -1) {
if(rr == -1) rr = n;
if(ll >= r || rr <= l) return {};
if(ll >= l && rr <= r) return data[i];
int mid = (ll+rr)/2;
return query(l, r, i*2, ll, mid).merge(query(l, r, i*2+1, mid, rr));
}
};
struct Point {
int x;
int y;
int w;
int i;
};
float angle(Point p1, Point p2) {
Point dif = {p2.x-p1.x, p2.y-p1.y};
return atan2(dif.y, dif.x);
}
float norm_angle(float angle) {
while(angle >= 2*PI) angle -= 2*PI;
return angle;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vec<Point> ps(n);
for(int i = 0; i<n; i++) {
cin >> ps[i].x >> ps[i].y >> ps[i].w;
}
sort(ps.begin(), ps.end(), [&](auto p1, auto p2) { return p1.x == p2.x ? p1.y < p2.y : p1.x < p2.x; });
for(int i = 0; i<n; i++) ps[i].i = i;
vec<pair<float, pair<int, int>>> evs(0);
for(int i = 0; i<n; i++) {
for(int j = i+1; j<n; j++) {
float cur_angle = angle(ps[i], ps[j]);
//cerr << "ANGLE: " << cur_angle << '\n';
float t1 = ((float)3)/2 * PI;
float t2 = ((float)1)/2 * PI;
float dif1 = (t1 + 2*PI) - cur_angle;
float dif2 = (t2 + 2*PI) - cur_angle;
dif1 = norm_angle(dif1);
dif2 = norm_angle(dif2);
// cerr << dif1 << ' ' << dif2 << '\n';
evs.push_back({dif1, {i, j}});
evs.push_back({dif2, {i, j}});
}
}
sort(evs.begin(), evs.end());
//vec<int> ap(n);
//iota(ap.begin(), ap.end(), 0);
int ans = 0;
SegTree st(n);
for(int i = 0; i<n; i++) st.set(i, ps[i].w);
auto eval = [&]() {
int mx = st.query(0, n).max_sss;
//cerr << mx << '\n';
ans = max(mx, ans);
};
evs.push_back({1'000, {}});
eval();
for(int ei = 0; ei < evs.size()-1; ei++) {
auto ev = evs[ei];
int i = ev.second.first;
int j = ev.second.second;
int temp = ps[i].i;
ps[i].i = ps[j].i;
ps[j].i = temp;
//cerr << "swapping: " << i << ' ' << j << " at angle: " << ev.first << '\n';
st.set(ps[i].i, ps[i].w);
st.set(ps[j].i, ps[j].w);
//swap(ap[ps[i].i], ap[ps[j].i]);
if(abs(evs[ei+1].first - evs[ei].first) < EPSILON) continue;
eval();
}
//eval();
cout << ans << '\n';
}
Compilation message
bulldozer.cpp: In function 'int32_t main()':
bulldozer.cpp:139:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for(int ei = 0; ei < evs.size()-1; ei++) {
| ~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
792 KB |
Output is correct |
2 |
Correct |
2 ms |
796 KB |
Output is correct |
3 |
Correct |
2 ms |
796 KB |
Output is correct |
4 |
Correct |
2 ms |
796 KB |
Output is correct |
5 |
Correct |
2 ms |
796 KB |
Output is correct |
6 |
Correct |
2 ms |
796 KB |
Output is correct |
7 |
Correct |
3 ms |
796 KB |
Output is correct |
8 |
Correct |
2 ms |
796 KB |
Output is correct |
9 |
Correct |
2 ms |
796 KB |
Output is correct |
10 |
Correct |
2 ms |
796 KB |
Output is correct |
11 |
Correct |
0 ms |
396 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
448 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
796 KB |
Output is correct |
2 |
Correct |
3 ms |
796 KB |
Output is correct |
3 |
Correct |
3 ms |
796 KB |
Output is correct |
4 |
Correct |
2 ms |
796 KB |
Output is correct |
5 |
Correct |
3 ms |
796 KB |
Output is correct |
6 |
Correct |
3 ms |
796 KB |
Output is correct |
7 |
Correct |
3 ms |
796 KB |
Output is correct |
8 |
Correct |
3 ms |
796 KB |
Output is correct |
9 |
Correct |
2 ms |
796 KB |
Output is correct |
10 |
Correct |
2 ms |
796 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
796 KB |
Output is correct |
22 |
Correct |
3 ms |
796 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
796 KB |
Output is correct |
25 |
Correct |
3 ms |
796 KB |
Output is correct |
26 |
Correct |
3 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
796 KB |
Output is correct |
28 |
Correct |
3 ms |
796 KB |
Output is correct |
29 |
Correct |
3 ms |
796 KB |
Output is correct |
30 |
Correct |
3 ms |
796 KB |
Output is correct |
31 |
Correct |
3 ms |
796 KB |
Output is correct |
32 |
Correct |
3 ms |
792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
796 KB |
Output is correct |
2 |
Correct |
3 ms |
796 KB |
Output is correct |
3 |
Correct |
3 ms |
796 KB |
Output is correct |
4 |
Correct |
2 ms |
796 KB |
Output is correct |
5 |
Correct |
3 ms |
796 KB |
Output is correct |
6 |
Correct |
3 ms |
796 KB |
Output is correct |
7 |
Correct |
3 ms |
796 KB |
Output is correct |
8 |
Correct |
3 ms |
796 KB |
Output is correct |
9 |
Correct |
2 ms |
796 KB |
Output is correct |
10 |
Correct |
2 ms |
796 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
796 KB |
Output is correct |
22 |
Correct |
3 ms |
796 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
796 KB |
Output is correct |
25 |
Correct |
3 ms |
796 KB |
Output is correct |
26 |
Correct |
3 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
796 KB |
Output is correct |
28 |
Correct |
3 ms |
796 KB |
Output is correct |
29 |
Correct |
3 ms |
796 KB |
Output is correct |
30 |
Correct |
3 ms |
796 KB |
Output is correct |
31 |
Correct |
3 ms |
796 KB |
Output is correct |
32 |
Correct |
3 ms |
792 KB |
Output is correct |
33 |
Correct |
1270 ms |
100248 KB |
Output is correct |
34 |
Correct |
1272 ms |
100760 KB |
Output is correct |
35 |
Correct |
1205 ms |
100636 KB |
Output is correct |
36 |
Correct |
1249 ms |
99184 KB |
Output is correct |
37 |
Correct |
1265 ms |
100736 KB |
Output is correct |
38 |
Correct |
1271 ms |
99740 KB |
Output is correct |
39 |
Correct |
1261 ms |
99488 KB |
Output is correct |
40 |
Correct |
1268 ms |
98976 KB |
Output is correct |
41 |
Correct |
1310 ms |
99280 KB |
Output is correct |
42 |
Correct |
1280 ms |
99488 KB |
Output is correct |
43 |
Correct |
1246 ms |
99148 KB |
Output is correct |
44 |
Correct |
1234 ms |
100056 KB |
Output is correct |
45 |
Correct |
1264 ms |
101016 KB |
Output is correct |
46 |
Correct |
1319 ms |
101020 KB |
Output is correct |
47 |
Correct |
1215 ms |
98972 KB |
Output is correct |
48 |
Correct |
1240 ms |
99988 KB |
Output is correct |
49 |
Correct |
1227 ms |
98984 KB |
Output is correct |
50 |
Correct |
1255 ms |
100020 KB |
Output is correct |
51 |
Correct |
1294 ms |
98980 KB |
Output is correct |
52 |
Correct |
1266 ms |
99364 KB |
Output is correct |
53 |
Correct |
1254 ms |
98964 KB |
Output is correct |
54 |
Correct |
1261 ms |
98972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
796 KB |
Output is correct |
2 |
Correct |
3 ms |
796 KB |
Output is correct |
3 |
Correct |
3 ms |
796 KB |
Output is correct |
4 |
Correct |
2 ms |
796 KB |
Output is correct |
5 |
Correct |
3 ms |
796 KB |
Output is correct |
6 |
Correct |
3 ms |
796 KB |
Output is correct |
7 |
Correct |
3 ms |
796 KB |
Output is correct |
8 |
Correct |
3 ms |
796 KB |
Output is correct |
9 |
Correct |
2 ms |
796 KB |
Output is correct |
10 |
Correct |
2 ms |
796 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
796 KB |
Output is correct |
22 |
Correct |
3 ms |
796 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
796 KB |
Output is correct |
25 |
Correct |
3 ms |
796 KB |
Output is correct |
26 |
Correct |
3 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
796 KB |
Output is correct |
28 |
Correct |
3 ms |
796 KB |
Output is correct |
29 |
Correct |
3 ms |
796 KB |
Output is correct |
30 |
Correct |
3 ms |
796 KB |
Output is correct |
31 |
Correct |
3 ms |
796 KB |
Output is correct |
32 |
Correct |
3 ms |
792 KB |
Output is correct |
33 |
Correct |
1270 ms |
100248 KB |
Output is correct |
34 |
Correct |
1272 ms |
100760 KB |
Output is correct |
35 |
Correct |
1205 ms |
100636 KB |
Output is correct |
36 |
Correct |
1249 ms |
99184 KB |
Output is correct |
37 |
Correct |
1265 ms |
100736 KB |
Output is correct |
38 |
Correct |
1271 ms |
99740 KB |
Output is correct |
39 |
Correct |
1261 ms |
99488 KB |
Output is correct |
40 |
Correct |
1268 ms |
98976 KB |
Output is correct |
41 |
Correct |
1310 ms |
99280 KB |
Output is correct |
42 |
Correct |
1280 ms |
99488 KB |
Output is correct |
43 |
Correct |
1246 ms |
99148 KB |
Output is correct |
44 |
Correct |
1234 ms |
100056 KB |
Output is correct |
45 |
Correct |
1264 ms |
101016 KB |
Output is correct |
46 |
Correct |
1319 ms |
101020 KB |
Output is correct |
47 |
Correct |
1215 ms |
98972 KB |
Output is correct |
48 |
Correct |
1240 ms |
99988 KB |
Output is correct |
49 |
Correct |
1227 ms |
98984 KB |
Output is correct |
50 |
Correct |
1255 ms |
100020 KB |
Output is correct |
51 |
Correct |
1294 ms |
98980 KB |
Output is correct |
52 |
Correct |
1266 ms |
99364 KB |
Output is correct |
53 |
Correct |
1254 ms |
98964 KB |
Output is correct |
54 |
Correct |
1261 ms |
98972 KB |
Output is correct |
55 |
Correct |
1277 ms |
99068 KB |
Output is correct |
56 |
Correct |
1236 ms |
99208 KB |
Output is correct |
57 |
Correct |
1222 ms |
98972 KB |
Output is correct |
58 |
Correct |
1229 ms |
100756 KB |
Output is correct |
59 |
Correct |
1194 ms |
100748 KB |
Output is correct |
60 |
Correct |
1227 ms |
100760 KB |
Output is correct |
61 |
Correct |
1198 ms |
98972 KB |
Output is correct |
62 |
Correct |
1228 ms |
99008 KB |
Output is correct |
63 |
Correct |
1206 ms |
99740 KB |
Output is correct |
64 |
Correct |
1217 ms |
98976 KB |
Output is correct |
65 |
Correct |
1208 ms |
99744 KB |
Output is correct |
66 |
Correct |
1251 ms |
101020 KB |
Output is correct |
67 |
Correct |
1211 ms |
98972 KB |
Output is correct |
68 |
Correct |
1206 ms |
98964 KB |
Output is correct |
69 |
Correct |
1249 ms |
100000 KB |
Output is correct |
70 |
Correct |
1279 ms |
100500 KB |
Output is correct |
71 |
Correct |
1221 ms |
98968 KB |
Output is correct |
72 |
Correct |
1193 ms |
99748 KB |
Output is correct |
73 |
Correct |
1203 ms |
99012 KB |
Output is correct |
74 |
Correct |
1218 ms |
98996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
792 KB |
Output is correct |
2 |
Correct |
2 ms |
796 KB |
Output is correct |
3 |
Correct |
2 ms |
796 KB |
Output is correct |
4 |
Correct |
2 ms |
796 KB |
Output is correct |
5 |
Correct |
2 ms |
796 KB |
Output is correct |
6 |
Correct |
2 ms |
796 KB |
Output is correct |
7 |
Correct |
3 ms |
796 KB |
Output is correct |
8 |
Correct |
2 ms |
796 KB |
Output is correct |
9 |
Correct |
2 ms |
796 KB |
Output is correct |
10 |
Correct |
2 ms |
796 KB |
Output is correct |
11 |
Correct |
0 ms |
396 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
448 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
2 ms |
796 KB |
Output is correct |
20 |
Correct |
3 ms |
796 KB |
Output is correct |
21 |
Correct |
3 ms |
796 KB |
Output is correct |
22 |
Correct |
3 ms |
796 KB |
Output is correct |
23 |
Correct |
3 ms |
796 KB |
Output is correct |
24 |
Correct |
2 ms |
796 KB |
Output is correct |
25 |
Correct |
2 ms |
796 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
796 KB |
Output is correct |
37 |
Correct |
3 ms |
796 KB |
Output is correct |
38 |
Correct |
4 ms |
792 KB |
Output is correct |
39 |
Correct |
3 ms |
796 KB |
Output is correct |
40 |
Correct |
3 ms |
796 KB |
Output is correct |
41 |
Correct |
3 ms |
796 KB |
Output is correct |
42 |
Correct |
3 ms |
796 KB |
Output is correct |
43 |
Correct |
3 ms |
796 KB |
Output is correct |
44 |
Correct |
3 ms |
796 KB |
Output is correct |
45 |
Correct |
3 ms |
796 KB |
Output is correct |
46 |
Correct |
3 ms |
796 KB |
Output is correct |
47 |
Correct |
3 ms |
792 KB |
Output is correct |
48 |
Correct |
1270 ms |
100248 KB |
Output is correct |
49 |
Correct |
1272 ms |
100760 KB |
Output is correct |
50 |
Correct |
1205 ms |
100636 KB |
Output is correct |
51 |
Correct |
1249 ms |
99184 KB |
Output is correct |
52 |
Correct |
1265 ms |
100736 KB |
Output is correct |
53 |
Correct |
1271 ms |
99740 KB |
Output is correct |
54 |
Correct |
1261 ms |
99488 KB |
Output is correct |
55 |
Correct |
1268 ms |
98976 KB |
Output is correct |
56 |
Correct |
1310 ms |
99280 KB |
Output is correct |
57 |
Correct |
1280 ms |
99488 KB |
Output is correct |
58 |
Correct |
1246 ms |
99148 KB |
Output is correct |
59 |
Correct |
1234 ms |
100056 KB |
Output is correct |
60 |
Correct |
1264 ms |
101016 KB |
Output is correct |
61 |
Correct |
1319 ms |
101020 KB |
Output is correct |
62 |
Correct |
1215 ms |
98972 KB |
Output is correct |
63 |
Correct |
1240 ms |
99988 KB |
Output is correct |
64 |
Correct |
1227 ms |
98984 KB |
Output is correct |
65 |
Correct |
1255 ms |
100020 KB |
Output is correct |
66 |
Correct |
1294 ms |
98980 KB |
Output is correct |
67 |
Correct |
1266 ms |
99364 KB |
Output is correct |
68 |
Correct |
1254 ms |
98964 KB |
Output is correct |
69 |
Correct |
1261 ms |
98972 KB |
Output is correct |
70 |
Correct |
1277 ms |
99068 KB |
Output is correct |
71 |
Correct |
1236 ms |
99208 KB |
Output is correct |
72 |
Correct |
1222 ms |
98972 KB |
Output is correct |
73 |
Correct |
1229 ms |
100756 KB |
Output is correct |
74 |
Correct |
1194 ms |
100748 KB |
Output is correct |
75 |
Correct |
1227 ms |
100760 KB |
Output is correct |
76 |
Correct |
1198 ms |
98972 KB |
Output is correct |
77 |
Correct |
1228 ms |
99008 KB |
Output is correct |
78 |
Correct |
1206 ms |
99740 KB |
Output is correct |
79 |
Correct |
1217 ms |
98976 KB |
Output is correct |
80 |
Correct |
1208 ms |
99744 KB |
Output is correct |
81 |
Correct |
1251 ms |
101020 KB |
Output is correct |
82 |
Correct |
1211 ms |
98972 KB |
Output is correct |
83 |
Correct |
1206 ms |
98964 KB |
Output is correct |
84 |
Correct |
1249 ms |
100000 KB |
Output is correct |
85 |
Correct |
1279 ms |
100500 KB |
Output is correct |
86 |
Correct |
1221 ms |
98968 KB |
Output is correct |
87 |
Correct |
1193 ms |
99748 KB |
Output is correct |
88 |
Correct |
1203 ms |
99012 KB |
Output is correct |
89 |
Correct |
1218 ms |
98996 KB |
Output is correct |
90 |
Correct |
1246 ms |
99228 KB |
Output is correct |
91 |
Correct |
1227 ms |
98968 KB |
Output is correct |
92 |
Correct |
1234 ms |
99608 KB |
Output is correct |
93 |
Correct |
1244 ms |
100504 KB |
Output is correct |
94 |
Correct |
1227 ms |
98960 KB |
Output is correct |
95 |
Correct |
1231 ms |
99144 KB |
Output is correct |
96 |
Correct |
1217 ms |
99996 KB |
Output is correct |
97 |
Correct |
1195 ms |
98980 KB |
Output is correct |
98 |
Correct |
1199 ms |
98972 KB |
Output is correct |
99 |
Correct |
1225 ms |
99284 KB |
Output is correct |
100 |
Incorrect |
876 ms |
98984 KB |
Output isn't correct |
101 |
Halted |
0 ms |
0 KB |
- |