Submission #673204

# Submission time Handle Problem Language Result Execution time Memory
673204 2022-12-19T22:21:56 Z peijar Bulldozer (JOI17_bulldozer) C++17
100 / 100
1443 ms 189288 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

template <typename T> struct Point {
  T x, y;

  Point() : x(0), y(0) {}

  Point(T _x, T _y) : x(_x), y(_y) {}

  Point operator+(const Point other) const {
    return Point(x + other.x, y + other.y);
  }
  Point operator-(const Point other) const {
    return Point(x - other.x, y - other.y);
  }

  Point operator*(const T lambda) const {
    return Point(x * lambda, y * lambda);
  }

  Point operator/(const T lambda) const {
    return Point(x / lambda, y / lambda);
  }

  bool operator<(const Point &other) const {
    return tie(x, y) < tie(other.x, other.y);
  }
  bool operator==(const Point &other) const {
    return tie(x, y) == tie(other.x, other.y);
  }
  bool operator>(const Point &other) const { return other < *this; }
  bool operator!=(const Point &other) const { return !(*this == other); }
  bool operator<=(const Point &other) const { return !(other < *this); }
  bool operator>=(const Point &other) const { return other <= *this; }

  friend ostream &operator<<(ostream &out, const Point &a) {
    return out << a.x << " " << a.y;
  }
  friend istream &operator>>(istream &in, Point &a) { return in >> a.x >> a.y; }
  friend T dot(const Point a, const Point b) { return a.x * b.x + a.y * b.y; }

  friend T cross(const Point a, const Point b) { return a.x * b.y - a.y * b.x; }

  friend T dis2(const Point a, const Point b) { return dot(b - a, b - a); }
};

using P = Point<int>;

struct Angle {
  int x, y;

  Angle() : x(0), y(0) {}
  Angle(int _x, int _y) : x(_x), y(_y) {}

  int half() const {
    assert(x or y);
    return y < 0 or (!y and x < 0);
  }

  friend bool operator<(Angle a, Angle b) {
    return make_pair(a.half(), a.y * b.x) < make_pair(b.half(), a.x * b.y);
  }

  friend bool operator==(Angle a, Angle b) { return !(a < b) and !(b < a); }
};

const int MAXN = 1e4;

int iDeb[MAXN], iFin[MAXN];
int prefMax[MAXN], suffMax[MAXN], rangeSum[MAXN], maxSum[MAXN];

void pull(int node) {
  prefMax[node] =
      max(prefMax[2 * node], rangeSum[2 * node] + prefMax[2 * node + 1]);
  suffMax[node] =
      max(suffMax[2 * node + 1], rangeSum[2 * node + 1] + suffMax[2 * node]);
  maxSum[node] = max({maxSum[2 * node], maxSum[2 * node + 1],
                      suffMax[2 * node] + prefMax[2 * node + 1]});
  rangeSum[node] = rangeSum[2 * node] + rangeSum[2 * node + 1];
}

void build(int node, int l, int r) {
  iDeb[node] = l, iFin[node] = r;
  if (l == r)
    return;
  int m = (l + r) / 2;
  build(2 * node, l, m);
  build(2 * node + 1, m + 1, r);
}

void upd(int node, int pos, int x) {
  if (iDeb[node] > pos or iFin[node] < pos)
    return;
  if (iDeb[node] == iFin[node]) {
    rangeSum[node] = x;
    prefMax[node] = suffMax[node] = maxSum[node] = max(0LL, x);
    return;
  }

  upd(2 * node, pos, x);
  upd(2 * node + 1, pos, x);
  pull(node);
}
const int MAX = 4e6;
vector<int> withAngles[MAX];

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int nbPoints;
  cin >> nbPoints;
  vector<P> points(nbPoints);
  vector<int> poids(nbPoints);
  for (int i = 0; i < nbPoints; ++i)
    cin >> points[i] >> poids[i];
  vector<tuple<Angle, int, int>> events;
  for (int i = 0; i < nbPoints; ++i)
    for (int j = i + 1; j < nbPoints; ++j) {
      P diff = points[j] - points[i];
      if (diff.y < 0 or (diff.y == 0 and diff.x < 0))
        diff = diff * (-1);
      events.emplace_back(Angle(diff.x, diff.y), i, j);
    }
  sort(events.begin(), events.end());
  vector<int> ordreInit(nbPoints);
  iota(ordreInit.begin(), ordreInit.end(), 0LL);
  build(1, 0, nbPoints - 1);

  auto getComparator = [&](P dir) {
    return [&points, dir](int i, int j) {
      if (cross(dir, points[i]) != cross(dir, points[j]))
        return cross(dir, points[i]) < cross(dir, points[j]);
      return dot(dir, points[i]) > dot(dir, points[j]);
    };
  };

  sort(ordreInit.begin(), ordreInit.end(), getComparator({1, 0}));
  for (int i = 0; i < nbPoints; ++i)
    upd(1, i, poids[ordreInit[i]]);
  vector<int> curPos(nbPoints);
  for (int i = 0; i < nbPoints; ++i)
    curPos[ordreInit[i]] = i;
  int ret = maxSum[1];
  for (int deb = 0; deb < (int)events.size();) {
    int fin = deb + 1;
    while (fin < (int)events.size() and
           get<0>(events[deb]) == get<0>(events[fin]))
      fin++;
    vector<int> toUpdate;
    for (int i = deb; i < fin; ++i) {
      auto [A, x, y] = events[i];
      toUpdate.push_back(x);
      toUpdate.push_back(y);
    }
    Angle a = get<0>(events[deb]);
    sort(toUpdate.begin(), toUpdate.end(), getComparator(P(a.x, a.y)));
    toUpdate.resize(unique(toUpdate.begin(), toUpdate.end()) -
                    toUpdate.begin());
    vector<int> positions;
    for (int x : toUpdate)
      positions.push_back(curPos[x]);
    sort(positions.begin(), positions.end());
    int nbUpd = toUpdate.size();
    for (int i = 0; i < nbUpd; ++i) {
      upd(1, positions[i], poids[toUpdate[i]]);
      curPos[toUpdate[i]] = positions[i];
    }
    for (int i = 0; i < nbUpd; ++i)
      ordreInit[positions[i]] = toUpdate[i];
    ret = max(ret, maxSum[1]);
    deb = fin;
  }
  cout << ret << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 94636 KB Output is correct
2 Correct 44 ms 94588 KB Output is correct
3 Correct 44 ms 94540 KB Output is correct
4 Correct 45 ms 94656 KB Output is correct
5 Correct 45 ms 94596 KB Output is correct
6 Correct 49 ms 94588 KB Output is correct
7 Correct 46 ms 94532 KB Output is correct
8 Correct 45 ms 94588 KB Output is correct
9 Correct 44 ms 94596 KB Output is correct
10 Correct 44 ms 94604 KB Output is correct
11 Correct 43 ms 94160 KB Output is correct
12 Correct 45 ms 94264 KB Output is correct
13 Correct 44 ms 94176 KB Output is correct
14 Correct 48 ms 94164 KB Output is correct
15 Correct 44 ms 94240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94560 KB Output is correct
2 Correct 45 ms 94548 KB Output is correct
3 Correct 45 ms 94740 KB Output is correct
4 Correct 45 ms 94564 KB Output is correct
5 Correct 45 ms 94556 KB Output is correct
6 Correct 47 ms 94568 KB Output is correct
7 Correct 49 ms 94584 KB Output is correct
8 Correct 45 ms 94552 KB Output is correct
9 Correct 45 ms 94584 KB Output is correct
10 Correct 51 ms 94540 KB Output is correct
11 Correct 42 ms 94232 KB Output is correct
12 Correct 44 ms 94156 KB Output is correct
13 Correct 45 ms 94196 KB Output is correct
14 Correct 45 ms 94156 KB Output is correct
15 Correct 43 ms 94156 KB Output is correct
16 Correct 47 ms 94200 KB Output is correct
17 Correct 50 ms 94196 KB Output is correct
18 Correct 43 ms 94180 KB Output is correct
19 Correct 42 ms 94164 KB Output is correct
20 Correct 44 ms 94176 KB Output is correct
21 Correct 44 ms 94588 KB Output is correct
22 Correct 45 ms 94548 KB Output is correct
23 Correct 45 ms 94556 KB Output is correct
24 Correct 46 ms 94572 KB Output is correct
25 Correct 46 ms 94544 KB Output is correct
26 Correct 46 ms 94636 KB Output is correct
27 Correct 48 ms 94604 KB Output is correct
28 Correct 46 ms 94616 KB Output is correct
29 Correct 48 ms 94540 KB Output is correct
30 Correct 52 ms 94580 KB Output is correct
31 Correct 47 ms 94552 KB Output is correct
32 Correct 46 ms 94660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94560 KB Output is correct
2 Correct 45 ms 94548 KB Output is correct
3 Correct 45 ms 94740 KB Output is correct
4 Correct 45 ms 94564 KB Output is correct
5 Correct 45 ms 94556 KB Output is correct
6 Correct 47 ms 94568 KB Output is correct
7 Correct 49 ms 94584 KB Output is correct
8 Correct 45 ms 94552 KB Output is correct
9 Correct 45 ms 94584 KB Output is correct
10 Correct 51 ms 94540 KB Output is correct
11 Correct 42 ms 94232 KB Output is correct
12 Correct 44 ms 94156 KB Output is correct
13 Correct 45 ms 94196 KB Output is correct
14 Correct 45 ms 94156 KB Output is correct
15 Correct 43 ms 94156 KB Output is correct
16 Correct 47 ms 94200 KB Output is correct
17 Correct 50 ms 94196 KB Output is correct
18 Correct 43 ms 94180 KB Output is correct
19 Correct 42 ms 94164 KB Output is correct
20 Correct 44 ms 94176 KB Output is correct
21 Correct 44 ms 94588 KB Output is correct
22 Correct 45 ms 94548 KB Output is correct
23 Correct 45 ms 94556 KB Output is correct
24 Correct 46 ms 94572 KB Output is correct
25 Correct 46 ms 94544 KB Output is correct
26 Correct 46 ms 94636 KB Output is correct
27 Correct 48 ms 94604 KB Output is correct
28 Correct 46 ms 94616 KB Output is correct
29 Correct 48 ms 94540 KB Output is correct
30 Correct 52 ms 94580 KB Output is correct
31 Correct 47 ms 94552 KB Output is correct
32 Correct 46 ms 94660 KB Output is correct
33 Correct 1261 ms 160124 KB Output is correct
34 Correct 1248 ms 160180 KB Output is correct
35 Correct 1230 ms 160104 KB Output is correct
36 Correct 1251 ms 160108 KB Output is correct
37 Correct 1234 ms 160108 KB Output is correct
38 Correct 1274 ms 160128 KB Output is correct
39 Correct 1249 ms 160076 KB Output is correct
40 Correct 1223 ms 160164 KB Output is correct
41 Correct 1255 ms 160176 KB Output is correct
42 Correct 1284 ms 160252 KB Output is correct
43 Correct 1233 ms 160144 KB Output is correct
44 Correct 1230 ms 160144 KB Output is correct
45 Correct 1210 ms 160204 KB Output is correct
46 Correct 1299 ms 160116 KB Output is correct
47 Correct 1237 ms 160200 KB Output is correct
48 Correct 1252 ms 160052 KB Output is correct
49 Correct 1214 ms 160136 KB Output is correct
50 Correct 1227 ms 160176 KB Output is correct
51 Correct 1208 ms 160172 KB Output is correct
52 Correct 1204 ms 160128 KB Output is correct
53 Correct 1232 ms 160092 KB Output is correct
54 Correct 1207 ms 160212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94560 KB Output is correct
2 Correct 45 ms 94548 KB Output is correct
3 Correct 45 ms 94740 KB Output is correct
4 Correct 45 ms 94564 KB Output is correct
5 Correct 45 ms 94556 KB Output is correct
6 Correct 47 ms 94568 KB Output is correct
7 Correct 49 ms 94584 KB Output is correct
8 Correct 45 ms 94552 KB Output is correct
9 Correct 45 ms 94584 KB Output is correct
10 Correct 51 ms 94540 KB Output is correct
11 Correct 42 ms 94232 KB Output is correct
12 Correct 44 ms 94156 KB Output is correct
13 Correct 45 ms 94196 KB Output is correct
14 Correct 45 ms 94156 KB Output is correct
15 Correct 43 ms 94156 KB Output is correct
16 Correct 47 ms 94200 KB Output is correct
17 Correct 50 ms 94196 KB Output is correct
18 Correct 43 ms 94180 KB Output is correct
19 Correct 42 ms 94164 KB Output is correct
20 Correct 44 ms 94176 KB Output is correct
21 Correct 44 ms 94588 KB Output is correct
22 Correct 45 ms 94548 KB Output is correct
23 Correct 45 ms 94556 KB Output is correct
24 Correct 46 ms 94572 KB Output is correct
25 Correct 46 ms 94544 KB Output is correct
26 Correct 46 ms 94636 KB Output is correct
27 Correct 48 ms 94604 KB Output is correct
28 Correct 46 ms 94616 KB Output is correct
29 Correct 48 ms 94540 KB Output is correct
30 Correct 52 ms 94580 KB Output is correct
31 Correct 47 ms 94552 KB Output is correct
32 Correct 46 ms 94660 KB Output is correct
33 Correct 1261 ms 160124 KB Output is correct
34 Correct 1248 ms 160180 KB Output is correct
35 Correct 1230 ms 160104 KB Output is correct
36 Correct 1251 ms 160108 KB Output is correct
37 Correct 1234 ms 160108 KB Output is correct
38 Correct 1274 ms 160128 KB Output is correct
39 Correct 1249 ms 160076 KB Output is correct
40 Correct 1223 ms 160164 KB Output is correct
41 Correct 1255 ms 160176 KB Output is correct
42 Correct 1284 ms 160252 KB Output is correct
43 Correct 1233 ms 160144 KB Output is correct
44 Correct 1230 ms 160144 KB Output is correct
45 Correct 1210 ms 160204 KB Output is correct
46 Correct 1299 ms 160116 KB Output is correct
47 Correct 1237 ms 160200 KB Output is correct
48 Correct 1252 ms 160052 KB Output is correct
49 Correct 1214 ms 160136 KB Output is correct
50 Correct 1227 ms 160176 KB Output is correct
51 Correct 1208 ms 160172 KB Output is correct
52 Correct 1204 ms 160128 KB Output is correct
53 Correct 1232 ms 160092 KB Output is correct
54 Correct 1207 ms 160212 KB Output is correct
55 Correct 1246 ms 160144 KB Output is correct
56 Correct 1248 ms 160084 KB Output is correct
57 Correct 1215 ms 160140 KB Output is correct
58 Correct 1248 ms 160160 KB Output is correct
59 Correct 1238 ms 160120 KB Output is correct
60 Correct 1252 ms 160132 KB Output is correct
61 Correct 1277 ms 160096 KB Output is correct
62 Correct 1247 ms 160140 KB Output is correct
63 Correct 1221 ms 160172 KB Output is correct
64 Correct 1288 ms 160104 KB Output is correct
65 Correct 1234 ms 160040 KB Output is correct
66 Correct 1239 ms 160256 KB Output is correct
67 Correct 1247 ms 160060 KB Output is correct
68 Correct 1222 ms 160152 KB Output is correct
69 Correct 1255 ms 160168 KB Output is correct
70 Correct 1222 ms 160156 KB Output is correct
71 Correct 1232 ms 160140 KB Output is correct
72 Correct 1224 ms 160200 KB Output is correct
73 Correct 1230 ms 160088 KB Output is correct
74 Correct 1238 ms 160124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 94636 KB Output is correct
2 Correct 44 ms 94588 KB Output is correct
3 Correct 44 ms 94540 KB Output is correct
4 Correct 45 ms 94656 KB Output is correct
5 Correct 45 ms 94596 KB Output is correct
6 Correct 49 ms 94588 KB Output is correct
7 Correct 46 ms 94532 KB Output is correct
8 Correct 45 ms 94588 KB Output is correct
9 Correct 44 ms 94596 KB Output is correct
10 Correct 44 ms 94604 KB Output is correct
11 Correct 43 ms 94160 KB Output is correct
12 Correct 45 ms 94264 KB Output is correct
13 Correct 44 ms 94176 KB Output is correct
14 Correct 48 ms 94164 KB Output is correct
15 Correct 44 ms 94240 KB Output is correct
16 Correct 45 ms 94560 KB Output is correct
17 Correct 45 ms 94548 KB Output is correct
18 Correct 45 ms 94740 KB Output is correct
19 Correct 45 ms 94564 KB Output is correct
20 Correct 45 ms 94556 KB Output is correct
21 Correct 47 ms 94568 KB Output is correct
22 Correct 49 ms 94584 KB Output is correct
23 Correct 45 ms 94552 KB Output is correct
24 Correct 45 ms 94584 KB Output is correct
25 Correct 51 ms 94540 KB Output is correct
26 Correct 42 ms 94232 KB Output is correct
27 Correct 44 ms 94156 KB Output is correct
28 Correct 45 ms 94196 KB Output is correct
29 Correct 45 ms 94156 KB Output is correct
30 Correct 43 ms 94156 KB Output is correct
31 Correct 47 ms 94200 KB Output is correct
32 Correct 50 ms 94196 KB Output is correct
33 Correct 43 ms 94180 KB Output is correct
34 Correct 42 ms 94164 KB Output is correct
35 Correct 44 ms 94176 KB Output is correct
36 Correct 44 ms 94588 KB Output is correct
37 Correct 45 ms 94548 KB Output is correct
38 Correct 45 ms 94556 KB Output is correct
39 Correct 46 ms 94572 KB Output is correct
40 Correct 46 ms 94544 KB Output is correct
41 Correct 46 ms 94636 KB Output is correct
42 Correct 48 ms 94604 KB Output is correct
43 Correct 46 ms 94616 KB Output is correct
44 Correct 48 ms 94540 KB Output is correct
45 Correct 52 ms 94580 KB Output is correct
46 Correct 47 ms 94552 KB Output is correct
47 Correct 46 ms 94660 KB Output is correct
48 Correct 1261 ms 160124 KB Output is correct
49 Correct 1248 ms 160180 KB Output is correct
50 Correct 1230 ms 160104 KB Output is correct
51 Correct 1251 ms 160108 KB Output is correct
52 Correct 1234 ms 160108 KB Output is correct
53 Correct 1274 ms 160128 KB Output is correct
54 Correct 1249 ms 160076 KB Output is correct
55 Correct 1223 ms 160164 KB Output is correct
56 Correct 1255 ms 160176 KB Output is correct
57 Correct 1284 ms 160252 KB Output is correct
58 Correct 1233 ms 160144 KB Output is correct
59 Correct 1230 ms 160144 KB Output is correct
60 Correct 1210 ms 160204 KB Output is correct
61 Correct 1299 ms 160116 KB Output is correct
62 Correct 1237 ms 160200 KB Output is correct
63 Correct 1252 ms 160052 KB Output is correct
64 Correct 1214 ms 160136 KB Output is correct
65 Correct 1227 ms 160176 KB Output is correct
66 Correct 1208 ms 160172 KB Output is correct
67 Correct 1204 ms 160128 KB Output is correct
68 Correct 1232 ms 160092 KB Output is correct
69 Correct 1207 ms 160212 KB Output is correct
70 Correct 1246 ms 160144 KB Output is correct
71 Correct 1248 ms 160084 KB Output is correct
72 Correct 1215 ms 160140 KB Output is correct
73 Correct 1248 ms 160160 KB Output is correct
74 Correct 1238 ms 160120 KB Output is correct
75 Correct 1252 ms 160132 KB Output is correct
76 Correct 1277 ms 160096 KB Output is correct
77 Correct 1247 ms 160140 KB Output is correct
78 Correct 1221 ms 160172 KB Output is correct
79 Correct 1288 ms 160104 KB Output is correct
80 Correct 1234 ms 160040 KB Output is correct
81 Correct 1239 ms 160256 KB Output is correct
82 Correct 1247 ms 160060 KB Output is correct
83 Correct 1222 ms 160152 KB Output is correct
84 Correct 1255 ms 160168 KB Output is correct
85 Correct 1222 ms 160156 KB Output is correct
86 Correct 1232 ms 160140 KB Output is correct
87 Correct 1224 ms 160200 KB Output is correct
88 Correct 1230 ms 160088 KB Output is correct
89 Correct 1238 ms 160124 KB Output is correct
90 Correct 1292 ms 160072 KB Output is correct
91 Correct 1330 ms 160116 KB Output is correct
92 Correct 1432 ms 160204 KB Output is correct
93 Correct 1311 ms 160140 KB Output is correct
94 Correct 1443 ms 160156 KB Output is correct
95 Correct 1306 ms 160112 KB Output is correct
96 Correct 1313 ms 160156 KB Output is correct
97 Correct 1359 ms 160144 KB Output is correct
98 Correct 1363 ms 160136 KB Output is correct
99 Correct 1323 ms 160112 KB Output is correct
100 Correct 1260 ms 189252 KB Output is correct
101 Correct 1060 ms 189244 KB Output is correct
102 Correct 1058 ms 189196 KB Output is correct
103 Correct 1049 ms 189204 KB Output is correct
104 Correct 1054 ms 189288 KB Output is correct
105 Correct 1121 ms 184104 KB Output is correct
106 Correct 1107 ms 184080 KB Output is correct
107 Correct 1109 ms 184008 KB Output is correct
108 Correct 1117 ms 184232 KB Output is correct
109 Correct 1115 ms 184076 KB Output is correct
110 Correct 1022 ms 160100 KB Output is correct
111 Correct 1018 ms 160080 KB Output is correct
112 Correct 1022 ms 160156 KB Output is correct
113 Correct 1012 ms 160132 KB Output is correct
114 Correct 1035 ms 160200 KB Output is correct
115 Correct 1022 ms 160136 KB Output is correct
116 Correct 1012 ms 160080 KB Output is correct
117 Correct 1014 ms 160068 KB Output is correct
118 Correct 1016 ms 160084 KB Output is correct
119 Correct 1026 ms 160120 KB Output is correct
120 Correct 44 ms 94252 KB Output is correct
121 Correct 44 ms 94236 KB Output is correct
122 Correct 1220 ms 160108 KB Output is correct
123 Correct 1231 ms 160092 KB Output is correct
124 Correct 1234 ms 160140 KB Output is correct
125 Correct 1224 ms 160156 KB Output is correct
126 Correct 1238 ms 160140 KB Output is correct
127 Correct 1242 ms 160156 KB Output is correct
128 Correct 1209 ms 160188 KB Output is correct
129 Correct 1203 ms 160080 KB Output is correct
130 Correct 1206 ms 160128 KB Output is correct
131 Correct 1205 ms 160068 KB Output is correct
132 Correct 1203 ms 160164 KB Output is correct
133 Correct 1217 ms 160224 KB Output is correct