Submission #536330

# Submission time Handle Problem Language Result Execution time Memory
536330 2022-03-12T22:50:13 Z michao Bulldozer (JOI17_bulldozer) C++14
100 / 100
969 ms 66432 KB
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1<<11;
const int inf=(int)1e18+9;

struct node{
	int pref,suf,sum,maxi;
};

node t[MAX*2];

node merguj(node a,node b){
	node wyn={-inf,-inf,-inf,-inf};
	wyn.sum=a.sum+b.sum;
	wyn.pref=max(a.pref,a.sum+b.pref);
	wyn.suf=max(b.suf,b.sum+a.suf);
	wyn.maxi=max({a.maxi,b.maxi,a.suf+b.pref});
	return wyn;
}

const node neutral={-inf,-inf,0,0};

void update(int u,int c){
	u+=MAX-1;
	t[u]={c,c,c,c};
	u>>=1;
	while (u){
		t[u]=merguj(t[u<<1],t[(u<<1)|1]);
		u>>=1;
	}
}

node query(int a,int b,int u,int lo,int hi){
	if (b<lo || a>hi)return neutral;
	if (lo>=a && hi<=b)return t[u];
	int mid=(lo+hi)>>1;
	node L=query(a,b,2*u,lo,mid);
	node R=query(a,b,2*u+1,mid+1,hi);
	return merguj(L,R);
}

int getmax(int l,int r){
	return query(l,r,1,1,MAX).maxi;
}

struct point{
	int x,y,w;
	point(int _x,int _y,int _w){
		x=_x,y=_y,w=_w;
	}
	point(){}
};

struct line{
	int id1,id2,diffx,diffy;
	line(int _id1,int _id2,int _diffx,int _diffy){
		id1=_id1;
		id2=_id2;
		diffx=_diffx;
		diffy=_diffy;
	} 
	line(){}
};

bool cmppoint(point p1,point p2){
	return mp(p1.x,p1.y)<mp(p2.x,p2.y);
}

int eval(line l1,line l2){
	return l1.diffy*l2.diffx-(l1.diffx*l2.diffy);
}

bool cmpline(line l1,line l2){
  if (eval(l1,l2)!=0)
		return l1.diffy*l2.diffx<l1.diffx*l2.diffy;
	return mp(l1.id1,l1.id2)<mp(l2.id1,l2.id2);
}
vector<line>l;
int pos[MAX];
int32_t main(){
  BOOST;
  int n;
  cin>>n;
  vector<point>p;
  for (int i=0;i<n;i++){
		int x,y,w;
		cin>>x>>y>>w;
		p.pb(point(x,y,w));
  }
  sort(p.begin(),p.end(),cmppoint);
  for (int i=0;i<sz(p);i++){
		for (int j=i+1;j<sz(p);j++){
			l.pb(line(i,j,p[i].x-p[j].x,p[i].y-p[j].y));
		}
  }
  sort(l.begin(),l.end(),cmpline);
  int ans=0;
  for (int i=0;i<n;i++)pos[i]=i;
  for (int i=0;i<n;i++){
		update(pos[i]+1,p[i].w);
  }
  ans=max(ans,getmax(1,n));
  for (int i=0;i<sz(l);i++){
		int x=l[i].id1;
		int y=l[i].id2;
		swap(pos[x],pos[y]);
		update(pos[x]+1,p[x].w);
		update(pos[y]+1,p[y].w);
		if (i<sz(l)-1 && eval(l[i],l[i+1])==0)continue;
		ans=max(ans,getmax(1,n));
  }
  cout<<ans;
  return 0; 
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 688 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 712 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 708 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 0 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 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 4 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 712 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 712 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 708 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 0 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 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 4 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 712 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 947 ms 66220 KB Output is correct
34 Correct 923 ms 66192 KB Output is correct
35 Correct 941 ms 66220 KB Output is correct
36 Correct 969 ms 66228 KB Output is correct
37 Correct 923 ms 66316 KB Output is correct
38 Correct 935 ms 66188 KB Output is correct
39 Correct 903 ms 66308 KB Output is correct
40 Correct 900 ms 66184 KB Output is correct
41 Correct 901 ms 66212 KB Output is correct
42 Correct 880 ms 66216 KB Output is correct
43 Correct 897 ms 66172 KB Output is correct
44 Correct 907 ms 66156 KB Output is correct
45 Correct 900 ms 66156 KB Output is correct
46 Correct 897 ms 66160 KB Output is correct
47 Correct 876 ms 66236 KB Output is correct
48 Correct 901 ms 66180 KB Output is correct
49 Correct 914 ms 66188 KB Output is correct
50 Correct 893 ms 66268 KB Output is correct
51 Correct 886 ms 66168 KB Output is correct
52 Correct 897 ms 66172 KB Output is correct
53 Correct 887 ms 66156 KB Output is correct
54 Correct 921 ms 66188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 712 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 708 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 0 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 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 4 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 712 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 947 ms 66220 KB Output is correct
34 Correct 923 ms 66192 KB Output is correct
35 Correct 941 ms 66220 KB Output is correct
36 Correct 969 ms 66228 KB Output is correct
37 Correct 923 ms 66316 KB Output is correct
38 Correct 935 ms 66188 KB Output is correct
39 Correct 903 ms 66308 KB Output is correct
40 Correct 900 ms 66184 KB Output is correct
41 Correct 901 ms 66212 KB Output is correct
42 Correct 880 ms 66216 KB Output is correct
43 Correct 897 ms 66172 KB Output is correct
44 Correct 907 ms 66156 KB Output is correct
45 Correct 900 ms 66156 KB Output is correct
46 Correct 897 ms 66160 KB Output is correct
47 Correct 876 ms 66236 KB Output is correct
48 Correct 901 ms 66180 KB Output is correct
49 Correct 914 ms 66188 KB Output is correct
50 Correct 893 ms 66268 KB Output is correct
51 Correct 886 ms 66168 KB Output is correct
52 Correct 897 ms 66172 KB Output is correct
53 Correct 887 ms 66156 KB Output is correct
54 Correct 921 ms 66188 KB Output is correct
55 Correct 890 ms 66208 KB Output is correct
56 Correct 886 ms 66152 KB Output is correct
57 Correct 904 ms 66272 KB Output is correct
58 Correct 898 ms 66188 KB Output is correct
59 Correct 917 ms 66160 KB Output is correct
60 Correct 945 ms 66204 KB Output is correct
61 Correct 890 ms 66188 KB Output is correct
62 Correct 925 ms 66188 KB Output is correct
63 Correct 929 ms 66168 KB Output is correct
64 Correct 913 ms 66200 KB Output is correct
65 Correct 900 ms 66188 KB Output is correct
66 Correct 898 ms 66156 KB Output is correct
67 Correct 930 ms 66148 KB Output is correct
68 Correct 912 ms 66152 KB Output is correct
69 Correct 898 ms 66220 KB Output is correct
70 Correct 929 ms 66192 KB Output is correct
71 Correct 920 ms 66184 KB Output is correct
72 Correct 909 ms 66204 KB Output is correct
73 Correct 934 ms 66196 KB Output is correct
74 Correct 906 ms 66140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 688 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 716 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 708 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 3 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 3 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 712 KB Output is correct
43 Correct 2 ms 716 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 716 KB Output is correct
46 Correct 3 ms 724 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 947 ms 66220 KB Output is correct
49 Correct 923 ms 66192 KB Output is correct
50 Correct 941 ms 66220 KB Output is correct
51 Correct 969 ms 66228 KB Output is correct
52 Correct 923 ms 66316 KB Output is correct
53 Correct 935 ms 66188 KB Output is correct
54 Correct 903 ms 66308 KB Output is correct
55 Correct 900 ms 66184 KB Output is correct
56 Correct 901 ms 66212 KB Output is correct
57 Correct 880 ms 66216 KB Output is correct
58 Correct 897 ms 66172 KB Output is correct
59 Correct 907 ms 66156 KB Output is correct
60 Correct 900 ms 66156 KB Output is correct
61 Correct 897 ms 66160 KB Output is correct
62 Correct 876 ms 66236 KB Output is correct
63 Correct 901 ms 66180 KB Output is correct
64 Correct 914 ms 66188 KB Output is correct
65 Correct 893 ms 66268 KB Output is correct
66 Correct 886 ms 66168 KB Output is correct
67 Correct 897 ms 66172 KB Output is correct
68 Correct 887 ms 66156 KB Output is correct
69 Correct 921 ms 66188 KB Output is correct
70 Correct 890 ms 66208 KB Output is correct
71 Correct 886 ms 66152 KB Output is correct
72 Correct 904 ms 66272 KB Output is correct
73 Correct 898 ms 66188 KB Output is correct
74 Correct 917 ms 66160 KB Output is correct
75 Correct 945 ms 66204 KB Output is correct
76 Correct 890 ms 66188 KB Output is correct
77 Correct 925 ms 66188 KB Output is correct
78 Correct 929 ms 66168 KB Output is correct
79 Correct 913 ms 66200 KB Output is correct
80 Correct 900 ms 66188 KB Output is correct
81 Correct 898 ms 66156 KB Output is correct
82 Correct 930 ms 66148 KB Output is correct
83 Correct 912 ms 66152 KB Output is correct
84 Correct 898 ms 66220 KB Output is correct
85 Correct 929 ms 66192 KB Output is correct
86 Correct 920 ms 66184 KB Output is correct
87 Correct 909 ms 66204 KB Output is correct
88 Correct 934 ms 66196 KB Output is correct
89 Correct 906 ms 66140 KB Output is correct
90 Correct 908 ms 66200 KB Output is correct
91 Correct 888 ms 66172 KB Output is correct
92 Correct 917 ms 66148 KB Output is correct
93 Correct 890 ms 66156 KB Output is correct
94 Correct 883 ms 66156 KB Output is correct
95 Correct 905 ms 66188 KB Output is correct
96 Correct 886 ms 66312 KB Output is correct
97 Correct 932 ms 66212 KB Output is correct
98 Correct 889 ms 66164 KB Output is correct
99 Correct 896 ms 66188 KB Output is correct
100 Correct 704 ms 66188 KB Output is correct
101 Correct 700 ms 66224 KB Output is correct
102 Correct 706 ms 66432 KB Output is correct
103 Correct 697 ms 66180 KB Output is correct
104 Correct 723 ms 66188 KB Output is correct
105 Correct 784 ms 66192 KB Output is correct
106 Correct 758 ms 66188 KB Output is correct
107 Correct 743 ms 66156 KB Output is correct
108 Correct 759 ms 66252 KB Output is correct
109 Correct 763 ms 66156 KB Output is correct
110 Correct 788 ms 66188 KB Output is correct
111 Correct 772 ms 66156 KB Output is correct
112 Correct 775 ms 66156 KB Output is correct
113 Correct 762 ms 66188 KB Output is correct
114 Correct 767 ms 66232 KB Output is correct
115 Correct 779 ms 66212 KB Output is correct
116 Correct 784 ms 66100 KB Output is correct
117 Correct 767 ms 66236 KB Output is correct
118 Correct 759 ms 66132 KB Output is correct
119 Correct 760 ms 66332 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 0 ms 340 KB Output is correct
122 Correct 870 ms 66316 KB Output is correct
123 Correct 878 ms 66256 KB Output is correct
124 Correct 897 ms 66160 KB Output is correct
125 Correct 882 ms 66156 KB Output is correct
126 Correct 872 ms 66188 KB Output is correct
127 Correct 889 ms 66184 KB Output is correct
128 Correct 879 ms 66272 KB Output is correct
129 Correct 904 ms 66392 KB Output is correct
130 Correct 870 ms 66212 KB Output is correct
131 Correct 914 ms 66156 KB Output is correct
132 Correct 888 ms 66188 KB Output is correct
133 Correct 874 ms 66196 KB Output is correct