Submission #551750

# Submission time Handle Problem Language Result Execution time Memory
551750 2022-04-21T12:16:07 Z cadmiumsky Bulldozer (JOI17_bulldozer) C++14
100 / 100
1756 ms 2752 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx")
//#define int long long
using namespace std;
using ll = long long;
const int nmax = 2e3 + 5;
int n;

vector< tuple<int,int,ll> > points;
vector<int> ind;

namespace SSM {
  #define int ll
  struct Node {
    int sum, pref, suff, mx;
    Node() : sum(0), pref(0), suff(0), mx(0) {;}
    Node(int val) : sum(val), pref(max(0LL, val)), suff(max(0LL, val)), mx(max(0LL, val)) {;}
    Node(int s, int p, int u, int m) : sum(s), pref(p), suff(u), mx(m) {;}
    Node operator +(const Node& x) const {
      return Node(x.sum + sum, 
                  max(pref, sum + x.pref), 
                  max(x.suff, x.sum + suff), 
                  max({mx, x.mx, suff + x.pref}));
    }
  };
  #undef int
  Node aint[nmax * 4];
  void upd(int poz, ll val, int node = 1, int cl = 0, int cr = n - 1) {
    if(cl == cr) {
      aint[node] = val;
      return;
    }
    int mid = cl + cr >> 1;
    if(poz <= mid)
      upd(poz, val, 2 * node, cl, mid);
    else
      upd(poz, val, 2 * node + 1, mid + 1, cr);
    aint[node] = aint[2 * node] + aint[2 * node + 1];
  }
  void construct(int l, int r, bool state = 0, int node = 1, int cl = 0, int cr = n - 1) {
  int mid = cl + cr >> 1;
    switch(state) {
      case 0:
        if(l <= cl && cr <= r) {
          construct(l, r, 1, node, cl, cr);
          return;
        }
        if(r < cl || cr < l)
          return;
        construct(l, r, 0, 2 * node, cl, mid);
        construct(l, r, 0, 2 * node + 1, mid + 1, cr);
        aint[node] = aint[2 * node] + aint[2 * node + 1];
        break;
      case 1:
        if(cl == cr) {
          aint[node] = get<2>(points[ind[cl]]);
          return;
        }
        construct(l, r, 1, 2 * node, cl, mid);
        construct(l, r, 1, 2 * node + 1, mid + 1, cr);
        aint[node] = aint[2 * node] + aint[2 * node + 1];
        break;
    };
  }
  ll query() { return aint[1].mx; }
};
#define int ll 
namespace LineContainer { // catthink
  pair<ll,ll> getline(int l, int r) { return {-(get<1>(points[l]) - get<1>(points[r])), -(get<0>(points[l]) - get<0>(points[r]))};}; 
  bool cmpline(pair<ll,ll> l, pair<ll,ll> r) { return (ll)l.first * r.second > (ll)r.first * l.second;};
  bool eqline(pair<ll,ll> l, pair<ll,ll> r) { return (ll)l.first * r.second == (ll)r.first * l.second; };
  bool eq(int i, int j) { return eqline(getline(ind[i], ind[i + 1]), getline(ind[j], ind[j + 1])); };
  auto cmp = [](int i, int j) { return cmpline(getline(ind[i], ind[i + 1]), getline(ind[j], ind[j + 1]))
                                        || (eq(i, j) && i < j); };
  set<int, decltype(cmp)> heap(cmp);
  void rev(int l, int r) {
    if(r - l > 1)
      cerr << "Reverse: " << l << ' ' << r << '\n';
    if(l > 0 && ind[l - 1] < ind[l])
      heap.erase(l - 1);
    if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      heap.erase(r);
    reverse(ind.begin() + l, ind.begin() + r + 1);
    if(l > 0 && ind[l - 1] < ind[l])
      heap.insert(l - 1);
    if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      heap.insert(r);
    SSM::construct(l, r);
  }
  int startmove() {
    if(heap.size() == 0)
      return -1;
    int u = *heap.begin(), last = u;
    //cerr << "- " << u << '\n';
    heap.erase(heap.begin());
    while(!heap.empty() && eq(*heap.begin(), u)) {
      if(*heap.begin() - u > 1) {
        rev(last, u + 1);
        last = *heap.begin();
      }
      u = *heap.begin();
      heap.erase(heap.begin());
    }
    rev(last, u + 1);
    return SSM::query();
  }
}

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  points.resize(n);
  ind.resize(n);
  for(auto &[a, b, c] : points)
    cin >> a >> b >> c;
  sort(points.begin(), points.end());
  for(int i = 0; i < n; i++)
    //cerr << get<0>(points[i]) << ' ' << get<1>(points[i]) << '\n', 
    SSM::upd(i, get<2>(points[i])),
    ind[i] = i;
  for(int i = 0; i < n - 1; i++)
    LineContainer::heap.insert(i);
  ll mx = SSM::query(), temp;
  while((temp = LineContainer::startmove()) >= 0) {
    mx = max(mx, temp);
  }
  cout << mx << '\n';
}

Compilation message

bulldozer.cpp: In function 'void SSM::upd(int, ll, int, int, int)':
bulldozer.cpp:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
bulldozer.cpp: In function 'void SSM::construct(int, int, bool, int, int, int)':
bulldozer.cpp:42:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |   int mid = cl + cr >> 1;
      |             ~~~^~~~
bulldozer.cpp: In function 'void LineContainer::rev(ll, ll)':
bulldozer.cpp:82:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      |        ~~^~~~~~~~~~~~~~~~
bulldozer.cpp:87:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     if(r < ind.size() - 1 && ind[r] < ind[r + 1])
      |        ~~^~~~~~~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:115:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  115 |   for(auto &[a, b, c] : points)
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 580 KB Output is correct
7 Correct 1 ms 576 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 2 ms 580 KB Output is correct
14 Correct 1 ms 572 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 576 KB Output is correct
2 Correct 4 ms 576 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 4 ms 576 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 572 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 580 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 576 KB Output is correct
19 Correct 1 ms 580 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 572 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 576 KB Output is correct
24 Correct 4 ms 608 KB Output is correct
25 Correct 4 ms 584 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 6 ms 584 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 4 ms 596 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 576 KB Output is correct
2 Correct 4 ms 576 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 4 ms 576 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 572 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 580 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 576 KB Output is correct
19 Correct 1 ms 580 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 572 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 576 KB Output is correct
24 Correct 4 ms 608 KB Output is correct
25 Correct 4 ms 584 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 6 ms 584 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 4 ms 596 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 1756 ms 752 KB Output is correct
34 Correct 1666 ms 748 KB Output is correct
35 Correct 1637 ms 752 KB Output is correct
36 Correct 1655 ms 752 KB Output is correct
37 Correct 1648 ms 752 KB Output is correct
38 Correct 1617 ms 756 KB Output is correct
39 Correct 1731 ms 752 KB Output is correct
40 Correct 1570 ms 752 KB Output is correct
41 Correct 1569 ms 752 KB Output is correct
42 Correct 1549 ms 748 KB Output is correct
43 Correct 1561 ms 752 KB Output is correct
44 Correct 1644 ms 752 KB Output is correct
45 Correct 1655 ms 756 KB Output is correct
46 Correct 1634 ms 724 KB Output is correct
47 Correct 1692 ms 748 KB Output is correct
48 Correct 1562 ms 748 KB Output is correct
49 Correct 1555 ms 748 KB Output is correct
50 Correct 1683 ms 756 KB Output is correct
51 Correct 1671 ms 756 KB Output is correct
52 Correct 1636 ms 760 KB Output is correct
53 Correct 1624 ms 772 KB Output is correct
54 Correct 1584 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 576 KB Output is correct
2 Correct 4 ms 576 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 4 ms 576 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 572 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 580 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 576 KB Output is correct
19 Correct 1 ms 580 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 3 ms 572 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 576 KB Output is correct
24 Correct 4 ms 608 KB Output is correct
25 Correct 4 ms 584 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 6 ms 584 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 4 ms 596 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 1756 ms 752 KB Output is correct
34 Correct 1666 ms 748 KB Output is correct
35 Correct 1637 ms 752 KB Output is correct
36 Correct 1655 ms 752 KB Output is correct
37 Correct 1648 ms 752 KB Output is correct
38 Correct 1617 ms 756 KB Output is correct
39 Correct 1731 ms 752 KB Output is correct
40 Correct 1570 ms 752 KB Output is correct
41 Correct 1569 ms 752 KB Output is correct
42 Correct 1549 ms 748 KB Output is correct
43 Correct 1561 ms 752 KB Output is correct
44 Correct 1644 ms 752 KB Output is correct
45 Correct 1655 ms 756 KB Output is correct
46 Correct 1634 ms 724 KB Output is correct
47 Correct 1692 ms 748 KB Output is correct
48 Correct 1562 ms 748 KB Output is correct
49 Correct 1555 ms 748 KB Output is correct
50 Correct 1683 ms 756 KB Output is correct
51 Correct 1671 ms 756 KB Output is correct
52 Correct 1636 ms 760 KB Output is correct
53 Correct 1624 ms 772 KB Output is correct
54 Correct 1584 ms 764 KB Output is correct
55 Correct 1556 ms 752 KB Output is correct
56 Correct 1448 ms 772 KB Output is correct
57 Correct 1441 ms 752 KB Output is correct
58 Correct 1448 ms 724 KB Output is correct
59 Correct 1531 ms 752 KB Output is correct
60 Correct 1540 ms 756 KB Output is correct
61 Correct 1497 ms 752 KB Output is correct
62 Correct 1528 ms 748 KB Output is correct
63 Correct 1503 ms 752 KB Output is correct
64 Correct 1496 ms 772 KB Output is correct
65 Correct 1453 ms 772 KB Output is correct
66 Correct 1466 ms 764 KB Output is correct
67 Correct 1486 ms 756 KB Output is correct
68 Correct 1470 ms 760 KB Output is correct
69 Correct 1488 ms 756 KB Output is correct
70 Correct 1470 ms 744 KB Output is correct
71 Correct 1502 ms 752 KB Output is correct
72 Correct 1451 ms 724 KB Output is correct
73 Correct 1531 ms 756 KB Output is correct
74 Correct 1437 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 580 KB Output is correct
7 Correct 1 ms 576 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 2 ms 580 KB Output is correct
14 Correct 1 ms 572 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 4 ms 576 KB Output is correct
17 Correct 4 ms 576 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 3 ms 468 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 4 ms 576 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 572 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 580 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 576 KB Output is correct
34 Correct 1 ms 580 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 3 ms 572 KB Output is correct
37 Correct 4 ms 468 KB Output is correct
38 Correct 4 ms 576 KB Output is correct
39 Correct 4 ms 608 KB Output is correct
40 Correct 4 ms 584 KB Output is correct
41 Correct 3 ms 588 KB Output is correct
42 Correct 6 ms 584 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 3 ms 468 KB Output is correct
45 Correct 4 ms 596 KB Output is correct
46 Correct 5 ms 468 KB Output is correct
47 Correct 4 ms 468 KB Output is correct
48 Correct 1756 ms 752 KB Output is correct
49 Correct 1666 ms 748 KB Output is correct
50 Correct 1637 ms 752 KB Output is correct
51 Correct 1655 ms 752 KB Output is correct
52 Correct 1648 ms 752 KB Output is correct
53 Correct 1617 ms 756 KB Output is correct
54 Correct 1731 ms 752 KB Output is correct
55 Correct 1570 ms 752 KB Output is correct
56 Correct 1569 ms 752 KB Output is correct
57 Correct 1549 ms 748 KB Output is correct
58 Correct 1561 ms 752 KB Output is correct
59 Correct 1644 ms 752 KB Output is correct
60 Correct 1655 ms 756 KB Output is correct
61 Correct 1634 ms 724 KB Output is correct
62 Correct 1692 ms 748 KB Output is correct
63 Correct 1562 ms 748 KB Output is correct
64 Correct 1555 ms 748 KB Output is correct
65 Correct 1683 ms 756 KB Output is correct
66 Correct 1671 ms 756 KB Output is correct
67 Correct 1636 ms 760 KB Output is correct
68 Correct 1624 ms 772 KB Output is correct
69 Correct 1584 ms 764 KB Output is correct
70 Correct 1556 ms 752 KB Output is correct
71 Correct 1448 ms 772 KB Output is correct
72 Correct 1441 ms 752 KB Output is correct
73 Correct 1448 ms 724 KB Output is correct
74 Correct 1531 ms 752 KB Output is correct
75 Correct 1540 ms 756 KB Output is correct
76 Correct 1497 ms 752 KB Output is correct
77 Correct 1528 ms 748 KB Output is correct
78 Correct 1503 ms 752 KB Output is correct
79 Correct 1496 ms 772 KB Output is correct
80 Correct 1453 ms 772 KB Output is correct
81 Correct 1466 ms 764 KB Output is correct
82 Correct 1486 ms 756 KB Output is correct
83 Correct 1470 ms 760 KB Output is correct
84 Correct 1488 ms 756 KB Output is correct
85 Correct 1470 ms 744 KB Output is correct
86 Correct 1502 ms 752 KB Output is correct
87 Correct 1451 ms 724 KB Output is correct
88 Correct 1531 ms 756 KB Output is correct
89 Correct 1437 ms 756 KB Output is correct
90 Correct 1468 ms 752 KB Output is correct
91 Correct 1465 ms 752 KB Output is correct
92 Correct 1447 ms 724 KB Output is correct
93 Correct 1461 ms 844 KB Output is correct
94 Correct 1439 ms 748 KB Output is correct
95 Correct 1447 ms 756 KB Output is correct
96 Correct 1410 ms 760 KB Output is correct
97 Correct 1420 ms 752 KB Output is correct
98 Correct 1443 ms 756 KB Output is correct
99 Correct 1438 ms 760 KB Output is correct
100 Correct 469 ms 740 KB Output is correct
101 Correct 476 ms 748 KB Output is correct
102 Correct 461 ms 744 KB Output is correct
103 Correct 468 ms 752 KB Output is correct
104 Correct 474 ms 768 KB Output is correct
105 Correct 693 ms 744 KB Output is correct
106 Correct 717 ms 720 KB Output is correct
107 Correct 689 ms 736 KB Output is correct
108 Correct 696 ms 740 KB Output is correct
109 Correct 700 ms 740 KB Output is correct
110 Correct 1372 ms 2584 KB Output is correct
111 Correct 1356 ms 2752 KB Output is correct
112 Correct 1346 ms 2664 KB Output is correct
113 Correct 1385 ms 2680 KB Output is correct
114 Correct 1360 ms 2672 KB Output is correct
115 Correct 1359 ms 2668 KB Output is correct
116 Correct 1354 ms 2640 KB Output is correct
117 Correct 1401 ms 2592 KB Output is correct
118 Correct 1364 ms 2700 KB Output is correct
119 Correct 1366 ms 2616 KB Output is correct
120 Correct 1 ms 468 KB Output is correct
121 Correct 1 ms 580 KB Output is correct
122 Correct 1460 ms 772 KB Output is correct
123 Correct 1465 ms 904 KB Output is correct
124 Correct 1459 ms 1016 KB Output is correct
125 Correct 1449 ms 772 KB Output is correct
126 Correct 1455 ms 972 KB Output is correct
127 Correct 1453 ms 776 KB Output is correct
128 Correct 1444 ms 880 KB Output is correct
129 Correct 1433 ms 764 KB Output is correct
130 Correct 1423 ms 852 KB Output is correct
131 Correct 1412 ms 756 KB Output is correct
132 Correct 1453 ms 752 KB Output is correct
133 Correct 1462 ms 756 KB Output is correct