Submission #690651

# Submission time Handle Problem Language Result Execution time Memory
690651 2023-01-30T10:44:11 Z browntoad Bulldozer (JOI17_bulldozer) C++14
100 / 100
1453 ms 132236 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char> 
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif

const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=2005;
const double PI=acos(-1);

ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}

ll inv(ll a, ll m=mod){
    return pw(a,m-2);
}

//=======================================================================================

struct Point{
	int x, y, w;
	Point operator -(Point b){
		return {x-b.x, y-b.y};
	}
};
struct Seg{
	Point a, b; 
	int ida, idb;
};
struct Node{
	int v, pf, sf, sm;
};
bool operator ==(Point a, Point b){
	if (a.x==b.x && a.y==b.y) return 1;
	return 0;
}
bool operator <(Point a, Point b){
	if (a.y == b.y) return a.x<b.x;
	return a.y<b.y;
}
int cross(Point a, Point b){
	return a.x*b.y - a.y*b.x;
}

vector<int> pos(maxn);
vector<Node> seg(4*maxn);
vector<Point> vc;
vector<Seg> segs;
int compslop(Seg A, Seg B){
	Point ta=A.b-A.a, tb=B.b-B.a;
	if (cross(ta, tb)==0) return 0;
	else if (cross(ta, tb)<0) return -1;
	else return 1;
}
bool shareline(Seg A, Seg B){
	int tmp2 = cross(A.b-A.a, B.a-A.a), tmp3 = cross(A.b-A.a, B.b-A.a);
	if (tmp2 == 0 && tmp3 == 0) return 1;
	return 0;
}
bool cmp(Seg A, Seg B){
	int tmp=compslop(A, B);
	if (tmp == 0){
		if (shareline(A, B)){
			// on the same line
			if (A.a == B.a) return A.b<B.b;
			else return A.a<B.a;
		}
		else{
			// doesn't matter how its ordered except for x-axis
			return A.a<B.a;
		}
	}	
	else return (tmp+1)/2; // 1 means its smaller, -1 means its bigger
}	

int n, fans = 0;

// seg treeeee
void pull(int x){
	seg[x].pf = max(seg[x+x].pf, seg[x+x].sm+seg[x+x+1].pf);
	seg[x].sf = max(seg[x+x+1].sf, seg[x+x].sf+seg[x+x+1].sm);
	seg[x].sm = seg[x+x].sm+seg[x+x+1].sm;
	seg[x].v = max({seg[x+x].v, seg[x+x+1].v, seg[x+x].sf+seg[x+x+1].pf});
}
void build(int l, int r, int x){
	// use vc's order
	if (l==r){
		seg[x].v = seg[x].pf = seg[x].sf = max(0ll, vc[l].w);
		seg[x].sm = vc[l].w;
		return;
	}
	int mid = (l+r)>>1;
	build(l, mid, x+x); 
	build(mid+1, r, x+x+1);
	pull(x);
}
void modify(int l, int r, int pos, int val, int x){
	if (l==r){
		seg[x].v = seg[x].pf = seg[x].sf = max(0ll, val);
		seg[x].sm = val;
		return;
	}
	int mid = (l+r)>>1;
	if (l<=pos && pos<=mid){
		modify(l, mid, pos, val, x+x);
	}
	else modify(mid+1, r, pos, val, x+x+1);
	pull(x);
}

void swapp(int a, int b){
	// index a and b
	modify(1, n, pos[b], vc[a].w, 1);
	modify(1, n, pos[a], vc[b].w, 1);
	swap(pos[a], pos[b]);
}
void check(){
	fans = max(fans, seg[1].v);
}

signed main (){
    // IOS();
    cin>>n;
    vc.resize(n+1);
    vc[0].x=-inf;
    vc[0].y=-inf;
    REP1(i, n){
    	cin>>vc[i].x>>vc[i].y>>vc[i].w;
    }
    sort(ALL(vc));
    REP1(i, n){
    	pos[i]=i;
    	// rank of point indexed as i is pos[i]
    }
    REP1(i, n){
    	FOR(j, i+1, n+1){
    		segs.pb({vc[i], vc[j], i, j});
    	}
    }
    sort(ALL(segs), cmp);
    /*REP(i, SZ(segs)){
    	// cout<<segs[i].ida<<' '<<segs[i].idb<<endl;
    	// cout<<segs[i].a.x<<' '<<segs[i].a.y<<" con "<<segs[i].b.x<<' '<<segs[i].b.y<<endl;
    }
    */
    build(1, n, 1);
    fans = seg[1].v;
    REP(i, SZ(segs)){
    	swapp(segs[i].ida, segs[i].idb);
    	if (i==SZ(segs)-1 || compslop(segs[i], segs[i+1])!=0) {
    		check();
    	}
    }
    cout<<fans<<endl;
}
/*
1:15
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1252 KB Output is correct
2 Correct 3 ms 1216 KB Output is correct
3 Correct 2 ms 1232 KB Output is correct
4 Correct 3 ms 1232 KB Output is correct
5 Correct 3 ms 1232 KB Output is correct
6 Correct 2 ms 1232 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 3 ms 1220 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 2 ms 1104 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 584 KB Output is correct
13 Correct 1 ms 580 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1232 KB Output is correct
2 Correct 3 ms 1232 KB Output is correct
3 Correct 3 ms 1232 KB Output is correct
4 Correct 3 ms 1220 KB Output is correct
5 Correct 3 ms 1220 KB Output is correct
6 Correct 4 ms 1220 KB Output is correct
7 Correct 4 ms 1232 KB Output is correct
8 Correct 4 ms 1232 KB Output is correct
9 Correct 4 ms 1232 KB Output is correct
10 Correct 3 ms 1232 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 580 KB Output is correct
18 Correct 1 ms 584 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 1216 KB Output is correct
22 Correct 3 ms 1220 KB Output is correct
23 Correct 3 ms 1232 KB Output is correct
24 Correct 3 ms 1232 KB Output is correct
25 Correct 3 ms 1232 KB Output is correct
26 Correct 3 ms 1232 KB Output is correct
27 Correct 3 ms 1232 KB Output is correct
28 Correct 3 ms 1232 KB Output is correct
29 Correct 3 ms 1216 KB Output is correct
30 Correct 4 ms 1220 KB Output is correct
31 Correct 3 ms 1224 KB Output is correct
32 Correct 3 ms 1224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1232 KB Output is correct
2 Correct 3 ms 1232 KB Output is correct
3 Correct 3 ms 1232 KB Output is correct
4 Correct 3 ms 1220 KB Output is correct
5 Correct 3 ms 1220 KB Output is correct
6 Correct 4 ms 1220 KB Output is correct
7 Correct 4 ms 1232 KB Output is correct
8 Correct 4 ms 1232 KB Output is correct
9 Correct 4 ms 1232 KB Output is correct
10 Correct 3 ms 1232 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 580 KB Output is correct
18 Correct 1 ms 584 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 1216 KB Output is correct
22 Correct 3 ms 1220 KB Output is correct
23 Correct 3 ms 1232 KB Output is correct
24 Correct 3 ms 1232 KB Output is correct
25 Correct 3 ms 1232 KB Output is correct
26 Correct 3 ms 1232 KB Output is correct
27 Correct 3 ms 1232 KB Output is correct
28 Correct 3 ms 1232 KB Output is correct
29 Correct 3 ms 1216 KB Output is correct
30 Correct 4 ms 1220 KB Output is correct
31 Correct 3 ms 1224 KB Output is correct
32 Correct 3 ms 1224 KB Output is correct
33 Correct 1362 ms 132048 KB Output is correct
34 Correct 1382 ms 132144 KB Output is correct
35 Correct 1339 ms 132128 KB Output is correct
36 Correct 1369 ms 132064 KB Output is correct
37 Correct 1388 ms 132020 KB Output is correct
38 Correct 1386 ms 132108 KB Output is correct
39 Correct 1338 ms 132108 KB Output is correct
40 Correct 1322 ms 132140 KB Output is correct
41 Correct 1266 ms 132140 KB Output is correct
42 Correct 1322 ms 132032 KB Output is correct
43 Correct 1371 ms 132020 KB Output is correct
44 Correct 1320 ms 132136 KB Output is correct
45 Correct 1453 ms 132152 KB Output is correct
46 Correct 1340 ms 132088 KB Output is correct
47 Correct 1349 ms 132020 KB Output is correct
48 Correct 1315 ms 132016 KB Output is correct
49 Correct 1173 ms 132108 KB Output is correct
50 Correct 1298 ms 132140 KB Output is correct
51 Correct 1216 ms 132112 KB Output is correct
52 Correct 1190 ms 132040 KB Output is correct
53 Correct 1299 ms 132092 KB Output is correct
54 Correct 1283 ms 132092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1232 KB Output is correct
2 Correct 3 ms 1232 KB Output is correct
3 Correct 3 ms 1232 KB Output is correct
4 Correct 3 ms 1220 KB Output is correct
5 Correct 3 ms 1220 KB Output is correct
6 Correct 4 ms 1220 KB Output is correct
7 Correct 4 ms 1232 KB Output is correct
8 Correct 4 ms 1232 KB Output is correct
9 Correct 4 ms 1232 KB Output is correct
10 Correct 3 ms 1232 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 580 KB Output is correct
18 Correct 1 ms 584 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 1216 KB Output is correct
22 Correct 3 ms 1220 KB Output is correct
23 Correct 3 ms 1232 KB Output is correct
24 Correct 3 ms 1232 KB Output is correct
25 Correct 3 ms 1232 KB Output is correct
26 Correct 3 ms 1232 KB Output is correct
27 Correct 3 ms 1232 KB Output is correct
28 Correct 3 ms 1232 KB Output is correct
29 Correct 3 ms 1216 KB Output is correct
30 Correct 4 ms 1220 KB Output is correct
31 Correct 3 ms 1224 KB Output is correct
32 Correct 3 ms 1224 KB Output is correct
33 Correct 1362 ms 132048 KB Output is correct
34 Correct 1382 ms 132144 KB Output is correct
35 Correct 1339 ms 132128 KB Output is correct
36 Correct 1369 ms 132064 KB Output is correct
37 Correct 1388 ms 132020 KB Output is correct
38 Correct 1386 ms 132108 KB Output is correct
39 Correct 1338 ms 132108 KB Output is correct
40 Correct 1322 ms 132140 KB Output is correct
41 Correct 1266 ms 132140 KB Output is correct
42 Correct 1322 ms 132032 KB Output is correct
43 Correct 1371 ms 132020 KB Output is correct
44 Correct 1320 ms 132136 KB Output is correct
45 Correct 1453 ms 132152 KB Output is correct
46 Correct 1340 ms 132088 KB Output is correct
47 Correct 1349 ms 132020 KB Output is correct
48 Correct 1315 ms 132016 KB Output is correct
49 Correct 1173 ms 132108 KB Output is correct
50 Correct 1298 ms 132140 KB Output is correct
51 Correct 1216 ms 132112 KB Output is correct
52 Correct 1190 ms 132040 KB Output is correct
53 Correct 1299 ms 132092 KB Output is correct
54 Correct 1283 ms 132092 KB Output is correct
55 Correct 1253 ms 132140 KB Output is correct
56 Correct 1407 ms 132012 KB Output is correct
57 Correct 1299 ms 132016 KB Output is correct
58 Correct 1223 ms 132104 KB Output is correct
59 Correct 1236 ms 132092 KB Output is correct
60 Correct 1224 ms 132016 KB Output is correct
61 Correct 1270 ms 132140 KB Output is correct
62 Correct 1208 ms 132208 KB Output is correct
63 Correct 1236 ms 132236 KB Output is correct
64 Correct 1214 ms 132064 KB Output is correct
65 Correct 1202 ms 132080 KB Output is correct
66 Correct 1257 ms 132140 KB Output is correct
67 Correct 1326 ms 132080 KB Output is correct
68 Correct 1214 ms 132084 KB Output is correct
69 Correct 1273 ms 132052 KB Output is correct
70 Correct 1355 ms 132124 KB Output is correct
71 Correct 1280 ms 132056 KB Output is correct
72 Correct 1229 ms 132164 KB Output is correct
73 Correct 1217 ms 132140 KB Output is correct
74 Correct 1270 ms 132140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1252 KB Output is correct
2 Correct 3 ms 1216 KB Output is correct
3 Correct 2 ms 1232 KB Output is correct
4 Correct 3 ms 1232 KB Output is correct
5 Correct 3 ms 1232 KB Output is correct
6 Correct 2 ms 1232 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 3 ms 1220 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 2 ms 1104 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 584 KB Output is correct
13 Correct 1 ms 580 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 3 ms 1232 KB Output is correct
17 Correct 3 ms 1232 KB Output is correct
18 Correct 3 ms 1232 KB Output is correct
19 Correct 3 ms 1220 KB Output is correct
20 Correct 3 ms 1220 KB Output is correct
21 Correct 4 ms 1220 KB Output is correct
22 Correct 4 ms 1232 KB Output is correct
23 Correct 4 ms 1232 KB Output is correct
24 Correct 4 ms 1232 KB Output is correct
25 Correct 3 ms 1232 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 580 KB Output is correct
33 Correct 1 ms 584 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 3 ms 1216 KB Output is correct
37 Correct 3 ms 1220 KB Output is correct
38 Correct 3 ms 1232 KB Output is correct
39 Correct 3 ms 1232 KB Output is correct
40 Correct 3 ms 1232 KB Output is correct
41 Correct 3 ms 1232 KB Output is correct
42 Correct 3 ms 1232 KB Output is correct
43 Correct 3 ms 1232 KB Output is correct
44 Correct 3 ms 1216 KB Output is correct
45 Correct 4 ms 1220 KB Output is correct
46 Correct 3 ms 1224 KB Output is correct
47 Correct 3 ms 1224 KB Output is correct
48 Correct 1362 ms 132048 KB Output is correct
49 Correct 1382 ms 132144 KB Output is correct
50 Correct 1339 ms 132128 KB Output is correct
51 Correct 1369 ms 132064 KB Output is correct
52 Correct 1388 ms 132020 KB Output is correct
53 Correct 1386 ms 132108 KB Output is correct
54 Correct 1338 ms 132108 KB Output is correct
55 Correct 1322 ms 132140 KB Output is correct
56 Correct 1266 ms 132140 KB Output is correct
57 Correct 1322 ms 132032 KB Output is correct
58 Correct 1371 ms 132020 KB Output is correct
59 Correct 1320 ms 132136 KB Output is correct
60 Correct 1453 ms 132152 KB Output is correct
61 Correct 1340 ms 132088 KB Output is correct
62 Correct 1349 ms 132020 KB Output is correct
63 Correct 1315 ms 132016 KB Output is correct
64 Correct 1173 ms 132108 KB Output is correct
65 Correct 1298 ms 132140 KB Output is correct
66 Correct 1216 ms 132112 KB Output is correct
67 Correct 1190 ms 132040 KB Output is correct
68 Correct 1299 ms 132092 KB Output is correct
69 Correct 1283 ms 132092 KB Output is correct
70 Correct 1253 ms 132140 KB Output is correct
71 Correct 1407 ms 132012 KB Output is correct
72 Correct 1299 ms 132016 KB Output is correct
73 Correct 1223 ms 132104 KB Output is correct
74 Correct 1236 ms 132092 KB Output is correct
75 Correct 1224 ms 132016 KB Output is correct
76 Correct 1270 ms 132140 KB Output is correct
77 Correct 1208 ms 132208 KB Output is correct
78 Correct 1236 ms 132236 KB Output is correct
79 Correct 1214 ms 132064 KB Output is correct
80 Correct 1202 ms 132080 KB Output is correct
81 Correct 1257 ms 132140 KB Output is correct
82 Correct 1326 ms 132080 KB Output is correct
83 Correct 1214 ms 132084 KB Output is correct
84 Correct 1273 ms 132052 KB Output is correct
85 Correct 1355 ms 132124 KB Output is correct
86 Correct 1280 ms 132056 KB Output is correct
87 Correct 1229 ms 132164 KB Output is correct
88 Correct 1217 ms 132140 KB Output is correct
89 Correct 1270 ms 132140 KB Output is correct
90 Correct 1385 ms 132084 KB Output is correct
91 Correct 1240 ms 132068 KB Output is correct
92 Correct 1434 ms 132088 KB Output is correct
93 Correct 1422 ms 132032 KB Output is correct
94 Correct 1294 ms 132060 KB Output is correct
95 Correct 1315 ms 132020 KB Output is correct
96 Correct 1442 ms 132140 KB Output is correct
97 Correct 1449 ms 132032 KB Output is correct
98 Correct 1442 ms 132048 KB Output is correct
99 Correct 1305 ms 132048 KB Output is correct
100 Correct 1220 ms 132028 KB Output is correct
101 Correct 1253 ms 132032 KB Output is correct
102 Correct 1332 ms 132012 KB Output is correct
103 Correct 1290 ms 132068 KB Output is correct
104 Correct 1258 ms 132020 KB Output is correct
105 Correct 1244 ms 132012 KB Output is correct
106 Correct 1263 ms 132068 KB Output is correct
107 Correct 1231 ms 132024 KB Output is correct
108 Correct 1198 ms 132008 KB Output is correct
109 Correct 1295 ms 132080 KB Output is correct
110 Correct 1181 ms 132016 KB Output is correct
111 Correct 1156 ms 132012 KB Output is correct
112 Correct 1186 ms 132092 KB Output is correct
113 Correct 1194 ms 132184 KB Output is correct
114 Correct 1187 ms 132016 KB Output is correct
115 Correct 1171 ms 132004 KB Output is correct
116 Correct 1185 ms 132012 KB Output is correct
117 Correct 1213 ms 132008 KB Output is correct
118 Correct 1154 ms 132044 KB Output is correct
119 Correct 1175 ms 132012 KB Output is correct
120 Correct 1 ms 468 KB Output is correct
121 Correct 1 ms 468 KB Output is correct
122 Correct 1180 ms 132144 KB Output is correct
123 Correct 1205 ms 132140 KB Output is correct
124 Correct 1212 ms 132140 KB Output is correct
125 Correct 1249 ms 132084 KB Output is correct
126 Correct 1188 ms 132104 KB Output is correct
127 Correct 1371 ms 132124 KB Output is correct
128 Correct 1426 ms 132096 KB Output is correct
129 Correct 1389 ms 132088 KB Output is correct
130 Correct 1286 ms 132144 KB Output is correct
131 Correct 1214 ms 132012 KB Output is correct
132 Correct 1250 ms 132132 KB Output is correct
133 Correct 1201 ms 132012 KB Output is correct