Submission #104378

# Submission time Handle Problem Language Result Execution time Memory
104378 2019-04-05T19:37:53 Z Noam527 Bulldozer (JOI17_bulldozer) C++17
100 / 100
605 ms 55936 KB
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 0;
const int OOO = 1;
using namespace std;

struct point {
	ll x, y, c, i;
	point() {}
	point(ll xx, ll yy, ll cc, int ii) {
		x = xx;
		y = yy;
		c = cc;
		i = ii;
	}
	bool operator < (const point &a) const {
		if (y != a.y) return y < a.y;
		return x < a.x;
	}
};

struct block {
	ll mx, L, R, S;
	block(ll v = 0) {
		mx = L = R = S = v;
	}
	block operator * (const block &a) const {
		block rtn;
		rtn.S = S + a.S;
		rtn.L = max(L, S + a.L);
		rtn.R = max(R + a.S, a.R);
		rtn.mx = max(max(mx, a.mx), R + a.L);
		return rtn;
	}
};

struct segtree {
	int n;
	vector<block> t;
	segtree() {}
	segtree(const vector<point> &a) {
		n = max(2, (int)a.size());
		while (n != (n & -n)) n += (n & -n);
		t.resize(2 * n);
		for (int i = 0; i < a.size(); i++)
			t[i + n - 1] = block(a[i].c);
		for (int i = n - 2; i >= 0; i--) fix(i);
	}
	void fix(int x) {
		t[x] = t[x + x + 1] * t[x + x + 2];
	}
	void upd(int x, ll v) {
		x += n - 1;
		t[x] = block(v);
		x = (x - 1) / 2;
		while (x) {
			fix(x);
			x = (x - 1) / 2;
		}
		fix(0);
	}
	ll query() {
		return t[0].mx;
	}
};

struct eve {
	ll x, y;
	int u, v;
	eve(ll xx = 0, ll yy = 0, int uu = 0, int vv = 0) {
		x = xx;
		y = yy;
		if (y < 0) {
			x = -x;
			y = -y;
		}
		u = uu;
		v = vv;
	}
	bool operator < (const eve &a) const {
		return x * a.y - y * a.x > 0;
	}
	bool operator == (const eve &a) const {
		return x * a.y == y * a.x;
	}
};

int n;
vector<point> a;
vector<int> ind;
vector<eve> E;
segtree T;

ll ans = 0;

void apply(int i, int j) {
	int u = a[i].i, v = a[j].i;
	if (OO) {
		cout << "swapping points\n";
		cout << a[i].x << " " << a[i].y << '\n';
		cout << a[j].x << " " << a[j].y << '\n';
		cout << "which is indicies " << i << " " << j << '\n';
		cout << "and in ind " << u << " " << v << '\n';
	}
	swap(a[i], a[j]);
	swap(ind[u], ind[v]);
	T.upd(i, a[i].c);
	T.upd(j, a[j].c);
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	a.resize(n);
	E.reserve(n * (n - 1) / 2);
	for (auto &i : a) cin >> i.x >> i.y >> i.c;
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) a[i].i = i;
	ind.resize(n);
	for (int i = 0; i < n; i++) ind[i] = i;
	for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++)
		E.push_back(eve(a[j].x - a[i].x, a[j].y - a[i].y, i, j));
	sort(E.begin(), E.end());
	T = segtree(a);
	if (OO) {
		cout << "querying on\n";
		for (const auto &i : a) cout << i.x << " " << i.y << '\n';
		cout << "result = " << T.query() << '\n';
	}
	ans = max(ans, T.query());
	int nxt = 0;
	vector<pair<int, int>> those;
	while (nxt < E.size()) {
		those.clear();
		do {
			if (OO) cout << "adding event " << nxt << " " << E[nxt].x << " " << E[nxt].y << " " << E[nxt].u << " " << E[nxt].v << '\n';
			those.emplace_back(min(ind[E[nxt].u], ind[E[nxt].v]), max(ind[E[nxt].u], ind[E[nxt].v]));
			nxt++;
		} while (nxt < E.size() && E[nxt - 1] == E[nxt]);
		sort(those.begin(), those.end());
		for (const auto &i : those) apply(i.first, i.second);

		if (OO) {
			cout << "querying on\n";
			for (const auto &i : a) cout << i.x << " " << i.y << '\n';
			cout << "result = " << T.query() << '\n';
		}
		ans = max(ans, T.query());
		if (OO) {
			cout << "now ind = \n";
			for (const auto &i : ind) cout << i << " "; cout << '\n';
		}
	}
	finish(ans);
}

Compilation message

bulldozer.cpp: In constructor 'segtree::segtree(const std::vector<point>&)':
bulldozer.cpp:50:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < a.size(); i++)
                   ~~^~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:138:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (nxt < E.size()) {
         ~~~~^~~~~~~~~~
bulldozer.cpp:144:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   } while (nxt < E.size() && E[nxt - 1] == E[nxt]);
            ~~~~^~~~~~~~~~
bulldozer.cpp:156:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for (const auto &i : ind) cout << i << " "; cout << '\n';
    ^~~
bulldozer.cpp:156:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for (const auto &i : ind) cout << i << " "; cout << '\n';
                                                ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 556 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 356 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 539 ms 47532 KB Output is correct
34 Correct 566 ms 47724 KB Output is correct
35 Correct 575 ms 47548 KB Output is correct
36 Correct 558 ms 47536 KB Output is correct
37 Correct 555 ms 47544 KB Output is correct
38 Correct 555 ms 47608 KB Output is correct
39 Correct 569 ms 47428 KB Output is correct
40 Correct 551 ms 47608 KB Output is correct
41 Correct 569 ms 47664 KB Output is correct
42 Correct 573 ms 47540 KB Output is correct
43 Correct 547 ms 47484 KB Output is correct
44 Correct 542 ms 47540 KB Output is correct
45 Correct 559 ms 47540 KB Output is correct
46 Correct 536 ms 47540 KB Output is correct
47 Correct 556 ms 47532 KB Output is correct
48 Correct 570 ms 47536 KB Output is correct
49 Correct 545 ms 47612 KB Output is correct
50 Correct 540 ms 47536 KB Output is correct
51 Correct 538 ms 47480 KB Output is correct
52 Correct 530 ms 47544 KB Output is correct
53 Correct 544 ms 47536 KB Output is correct
54 Correct 541 ms 47544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 539 ms 47532 KB Output is correct
34 Correct 566 ms 47724 KB Output is correct
35 Correct 575 ms 47548 KB Output is correct
36 Correct 558 ms 47536 KB Output is correct
37 Correct 555 ms 47544 KB Output is correct
38 Correct 555 ms 47608 KB Output is correct
39 Correct 569 ms 47428 KB Output is correct
40 Correct 551 ms 47608 KB Output is correct
41 Correct 569 ms 47664 KB Output is correct
42 Correct 573 ms 47540 KB Output is correct
43 Correct 547 ms 47484 KB Output is correct
44 Correct 542 ms 47540 KB Output is correct
45 Correct 559 ms 47540 KB Output is correct
46 Correct 536 ms 47540 KB Output is correct
47 Correct 556 ms 47532 KB Output is correct
48 Correct 570 ms 47536 KB Output is correct
49 Correct 545 ms 47612 KB Output is correct
50 Correct 540 ms 47536 KB Output is correct
51 Correct 538 ms 47480 KB Output is correct
52 Correct 530 ms 47544 KB Output is correct
53 Correct 544 ms 47536 KB Output is correct
54 Correct 541 ms 47544 KB Output is correct
55 Correct 549 ms 47668 KB Output is correct
56 Correct 557 ms 47544 KB Output is correct
57 Correct 539 ms 47532 KB Output is correct
58 Correct 558 ms 47480 KB Output is correct
59 Correct 552 ms 47664 KB Output is correct
60 Correct 568 ms 47612 KB Output is correct
61 Correct 599 ms 47676 KB Output is correct
62 Correct 579 ms 47544 KB Output is correct
63 Correct 562 ms 47544 KB Output is correct
64 Correct 553 ms 47480 KB Output is correct
65 Correct 605 ms 47672 KB Output is correct
66 Correct 567 ms 47628 KB Output is correct
67 Correct 560 ms 47636 KB Output is correct
68 Correct 550 ms 47552 KB Output is correct
69 Correct 557 ms 47784 KB Output is correct
70 Correct 580 ms 47688 KB Output is correct
71 Correct 569 ms 47484 KB Output is correct
72 Correct 536 ms 47540 KB Output is correct
73 Correct 537 ms 47536 KB Output is correct
74 Correct 534 ms 47560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 556 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 356 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 539 ms 47532 KB Output is correct
49 Correct 566 ms 47724 KB Output is correct
50 Correct 575 ms 47548 KB Output is correct
51 Correct 558 ms 47536 KB Output is correct
52 Correct 555 ms 47544 KB Output is correct
53 Correct 555 ms 47608 KB Output is correct
54 Correct 569 ms 47428 KB Output is correct
55 Correct 551 ms 47608 KB Output is correct
56 Correct 569 ms 47664 KB Output is correct
57 Correct 573 ms 47540 KB Output is correct
58 Correct 547 ms 47484 KB Output is correct
59 Correct 542 ms 47540 KB Output is correct
60 Correct 559 ms 47540 KB Output is correct
61 Correct 536 ms 47540 KB Output is correct
62 Correct 556 ms 47532 KB Output is correct
63 Correct 570 ms 47536 KB Output is correct
64 Correct 545 ms 47612 KB Output is correct
65 Correct 540 ms 47536 KB Output is correct
66 Correct 538 ms 47480 KB Output is correct
67 Correct 530 ms 47544 KB Output is correct
68 Correct 544 ms 47536 KB Output is correct
69 Correct 541 ms 47544 KB Output is correct
70 Correct 549 ms 47668 KB Output is correct
71 Correct 557 ms 47544 KB Output is correct
72 Correct 539 ms 47532 KB Output is correct
73 Correct 558 ms 47480 KB Output is correct
74 Correct 552 ms 47664 KB Output is correct
75 Correct 568 ms 47612 KB Output is correct
76 Correct 599 ms 47676 KB Output is correct
77 Correct 579 ms 47544 KB Output is correct
78 Correct 562 ms 47544 KB Output is correct
79 Correct 553 ms 47480 KB Output is correct
80 Correct 605 ms 47672 KB Output is correct
81 Correct 567 ms 47628 KB Output is correct
82 Correct 560 ms 47636 KB Output is correct
83 Correct 550 ms 47552 KB Output is correct
84 Correct 557 ms 47784 KB Output is correct
85 Correct 580 ms 47688 KB Output is correct
86 Correct 569 ms 47484 KB Output is correct
87 Correct 536 ms 47540 KB Output is correct
88 Correct 537 ms 47536 KB Output is correct
89 Correct 534 ms 47560 KB Output is correct
90 Correct 537 ms 47656 KB Output is correct
91 Correct 549 ms 47540 KB Output is correct
92 Correct 555 ms 47608 KB Output is correct
93 Correct 565 ms 47536 KB Output is correct
94 Correct 561 ms 47608 KB Output is correct
95 Correct 560 ms 47664 KB Output is correct
96 Correct 562 ms 47480 KB Output is correct
97 Correct 561 ms 47608 KB Output is correct
98 Correct 571 ms 47608 KB Output is correct
99 Correct 523 ms 47452 KB Output is correct
100 Correct 527 ms 55888 KB Output is correct
101 Correct 560 ms 55936 KB Output is correct
102 Correct 518 ms 55848 KB Output is correct
103 Correct 525 ms 55840 KB Output is correct
104 Correct 511 ms 55836 KB Output is correct
105 Correct 547 ms 55880 KB Output is correct
106 Correct 545 ms 55908 KB Output is correct
107 Correct 549 ms 55780 KB Output is correct
108 Correct 544 ms 55864 KB Output is correct
109 Correct 553 ms 55840 KB Output is correct
110 Correct 534 ms 48044 KB Output is correct
111 Correct 535 ms 47988 KB Output is correct
112 Correct 539 ms 48048 KB Output is correct
113 Correct 537 ms 47988 KB Output is correct
114 Correct 540 ms 47964 KB Output is correct
115 Correct 549 ms 48116 KB Output is correct
116 Correct 547 ms 48044 KB Output is correct
117 Correct 554 ms 47988 KB Output is correct
118 Correct 531 ms 47916 KB Output is correct
119 Correct 525 ms 47992 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 531 ms 47536 KB Output is correct
123 Correct 551 ms 47560 KB Output is correct
124 Correct 537 ms 47676 KB Output is correct
125 Correct 547 ms 47536 KB Output is correct
126 Correct 548 ms 47608 KB Output is correct
127 Correct 564 ms 47608 KB Output is correct
128 Correct 573 ms 47664 KB Output is correct
129 Correct 567 ms 47668 KB Output is correct
130 Correct 549 ms 47608 KB Output is correct
131 Correct 536 ms 47536 KB Output is correct
132 Correct 544 ms 47536 KB Output is correct
133 Correct 543 ms 47540 KB Output is correct