#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
const int N=2048;
const int M=2*N;
ll l[M],r[M],sum[M],ans[M];
int A[N];
void pull(int c)
{
ans[c]=max(max(ans[c<<1],ans[c<<1|1]),r[c<<1]+l[c<<1|1]);
l[c]=max(l[c<<1],sum[c<<1]+l[c<<1|1]);
r[c]=max(r[c<<1|1],sum[c<<1|1]+r[c<<1]);
sum[c]=sum[c<<1]+sum[c<<1|1];
}
void Build()
{
for(int i=N;i<M;i++) sum[i]=A[i-N],l[i]=r[i]=ans[i]=max(0,A[i-N]);
for(int i=N-1;i;i--) pull(i);
/*if(ss==se){ sum[c]=A[ss];l[c]=r[c]=ans[c]=max(0,A[ss]);return;}
int mid=ss+se>>1;
Build(c<<1,ss,mid);
Build(c<<1|1,mid+1,se);
pull(c);*/
}
void Set(int qi, int x)
{
qi+=N;sum[qi]=x;l[qi]=r[qi]=ans[qi]=max(x,0);
for(qi>>=1;qi;qi>>=1) pull(qi);
}
/*void Set(int c, int ss, int se, int qi, int x)
{
if(ss==se){ sum[c]=x;l[c]=r[c]=ans[c]=max(0,x);return;}
int mid=ss+se>>1;
if(qi<=mid) Set(c<<1,ss,mid,qi,x);
else Set(c<<1|1,mid+1,se,qi,x);
pull(c);
}*/
struct pt{ ll x,y;pt(){}pt(ll a, ll b):x(a),y(b){}};
bool operator < (pt a, pt b){ return mp(a.y,a.x)<mp(b.y,b.x);}
pt operator - (pt a, pt b){ return pt(a.x-b.x,a.y-b.y);}
ll cross(pt a, pt b){ return a.x*b.y-a.y*b.x;}
ll dot(pt a, pt b){ return a.x*b.x+a.y*b.y;}
ll sq(pt a){ return dot(a,a);}
int part(pt a){ return a<pt(0,0);}
#define ldb double
const ldb PI=acos(-1);
ldb angle(pt a)
{
ldb ang=atan2(a.y,a.x);
if(ang<0) ang+=2*PI;
return ang;
}
bool comp(pt a, pt b){ return mt(part(a),(ll)0)<mt(part(b),cross(a,b));}
bool eq(pt a, pt b){ return comp(a,b)==comp(b,a);}
pt P[N];
int w[N],id[N],pos[N];
ll sol;
void SW(int x, int y)
{
swap(pos[x],pos[y]);
swap(A[pos[x]],A[pos[y]]);
Set(pos[x],A[pos[x]]);
Set(pos[y],A[pos[y]]);
//sol=max(sol,ans[1]);
}
int main()
{
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++) scanf("%lld %lld %i",&P[i].x,&P[i].y,&w[i]),id[i]=i;
sort(id+1,id+1+n,[&](int i, int j){ return P[i]<P[j];});
for(int i=1;i<=n;i++) A[i]=w[id[i]],pos[id[i]]=i;
Build();
sol=ans[1];
int sz=n*(n-1)/2;
vector<pt> events;
vector<int> id,X,Y;
vector<ldb> ang;
events.reserve(sz);
X.reserve(sz);
Y.reserve(sz);
id.reserve(sz);
ang.reserve(sz);
for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++)
{
pt d=P[i]-P[j];
if(part(d)==1) d=pt(0,0)-d;
id.pb(events.size()),events.pb(d),ang.pb(angle(d));
X.pb(i);Y.pb(j);
}
//sort(events.begin(),events.end(),[&](pair<pt,pair<int,int>> a, pair<pt,pair<int,int>> b){ return comp(a.first,b.first);});
sort(id.begin(),id.end(),[&](int i, int j){ return comp(events[i],events[j]);});
for(int i=0,j;i<id.size();i=j)
{
vector<int> v;//SW(events[id[j]].second.first,events[id[j]].second.second);
for(j=i;j<id.size() && eq(events[id[i]],events[id[j]])/*ang[id[i]]==ang[id[j]]*/;j++) v.pb(X[id[j]]),v.pb(Y[id[j]]);
sort(v.begin(),v.end(),[&](int a, int b){ return pos[a]<pos[b];});
v.erase(unique(v.begin(),v.end()),v.end());
for(int k=0,l;k<v.size();k=l)
{
for(l=k+1;l<v.size() && pos[v[l-1]]+1==pos[v[l]];l++);
for(int z=k,t=l-1;z<t;z++,t--) SW(v[z],v[t]);
}
/*int x=events[i].second.first;
int y=events[i].second.second;
swap(pos[x],pos[y]);
swap(A[pos[x]],A[pos[y]]);
Set(pos[x],A[pos[x]]);
Set(pos[y],A[pos[y]]);
//printf("SWAP %i %i: %lld\n",x,y,ans[1]);
sol=max(sol,ans[1]);
//for(int z=N+1;z<=N+n;z++) printf("%lld ",sum[z]);
//printf("\n");*/
sol=max(sol,ans[1]);
}
printf("%lld\n",sol);
return 0;
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:97:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0,j;i<id.size();i=j)
~^~~~~~~~~~
bulldozer.cpp:100:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=i;j<id.size() && eq(events[id[i]],events[id[j]])/*ang[id[i]]==ang[id[j]]*/;j++) v.pb(X[id[j]]),v.pb(Y[id[j]]);
~^~~~~~~~~~
bulldozer.cpp:103:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0,l;k<v.size();k=l)
~^~~~~~~~~
bulldozer.cpp:105:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(l=k+1;l<v.size() && pos[v[l-1]]+1==pos[v[l]];l++);
~^~~~~~~~~
bulldozer.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
bulldozer.cpp:74:70: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%lld %lld %i",&P[i].x,&P[i].y,&w[i]),id[i]=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
3 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
5 ms |
632 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
632 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
4 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
632 KB |
Output is correct |
26 |
Correct |
5 ms |
632 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
632 KB |
Output is correct |
29 |
Correct |
4 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
5 ms |
632 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
632 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
4 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
632 KB |
Output is correct |
26 |
Correct |
5 ms |
632 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
632 KB |
Output is correct |
29 |
Correct |
4 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
1914 ms |
70972 KB |
Output is correct |
34 |
Correct |
1994 ms |
71032 KB |
Output is correct |
35 |
Correct |
1910 ms |
71004 KB |
Output is correct |
36 |
Correct |
1936 ms |
71032 KB |
Output is correct |
37 |
Correct |
1966 ms |
70992 KB |
Output is correct |
38 |
Correct |
1946 ms |
71024 KB |
Output is correct |
39 |
Correct |
1980 ms |
71052 KB |
Output is correct |
40 |
Execution timed out |
2033 ms |
71000 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
5 ms |
632 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
632 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
4 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
632 KB |
Output is correct |
26 |
Correct |
5 ms |
632 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
632 KB |
Output is correct |
29 |
Correct |
4 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
1914 ms |
70972 KB |
Output is correct |
34 |
Correct |
1994 ms |
71032 KB |
Output is correct |
35 |
Correct |
1910 ms |
71004 KB |
Output is correct |
36 |
Correct |
1936 ms |
71032 KB |
Output is correct |
37 |
Correct |
1966 ms |
70992 KB |
Output is correct |
38 |
Correct |
1946 ms |
71024 KB |
Output is correct |
39 |
Correct |
1980 ms |
71052 KB |
Output is correct |
40 |
Execution timed out |
2033 ms |
71000 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
3 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
508 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
636 KB |
Output is correct |
21 |
Correct |
5 ms |
632 KB |
Output is correct |
22 |
Correct |
4 ms |
632 KB |
Output is correct |
23 |
Correct |
4 ms |
632 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
632 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
508 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
2 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
5 ms |
632 KB |
Output is correct |
37 |
Correct |
5 ms |
632 KB |
Output is correct |
38 |
Correct |
5 ms |
632 KB |
Output is correct |
39 |
Correct |
4 ms |
632 KB |
Output is correct |
40 |
Correct |
5 ms |
632 KB |
Output is correct |
41 |
Correct |
5 ms |
632 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
4 ms |
632 KB |
Output is correct |
44 |
Correct |
4 ms |
632 KB |
Output is correct |
45 |
Correct |
5 ms |
632 KB |
Output is correct |
46 |
Correct |
5 ms |
632 KB |
Output is correct |
47 |
Correct |
5 ms |
760 KB |
Output is correct |
48 |
Correct |
1914 ms |
70972 KB |
Output is correct |
49 |
Correct |
1994 ms |
71032 KB |
Output is correct |
50 |
Correct |
1910 ms |
71004 KB |
Output is correct |
51 |
Correct |
1936 ms |
71032 KB |
Output is correct |
52 |
Correct |
1966 ms |
70992 KB |
Output is correct |
53 |
Correct |
1946 ms |
71024 KB |
Output is correct |
54 |
Correct |
1980 ms |
71052 KB |
Output is correct |
55 |
Execution timed out |
2033 ms |
71000 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |