답안 #261530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261530 2020-08-11T20:29:54 Z Haunted_Cpp Fuel Station (NOI20_fuelstation) C++17
79 / 100
651 ms 70904 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

class SegmentTree {
private:
  struct Node {
    long long prefix, sum, best;
    Node () {
      prefix = sum = best = 1e9;
    }
    void merge(Node l, Node r) {
      prefix = min(l.prefix, l.sum + r.prefix);
      sum = l.sum + r.sum;
      best = min({l.best, prefix});
    }
  };
  vector<Node> seg;
  const int LO, HI;
  void build(int l, int r, int node, const vector<int> &arr) {
    if (l == r) {
      seg[node].prefix = seg[node].sum = seg[node].best = arr[l];
      return;
    }
    const int mid = l + (r - l) / 2;
    build(l, mid, 2 * node + 1, arr);
    build(mid + 1, r, 2 * node + 2, arr);
    seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]);
  }
  void modify(int where, int delta, int l, int r, int node) {
    if (l > where || r < where) return;
    if (l >= where && r <= where) {
      seg[node].prefix = seg[node].sum = seg[node].best = delta;
      return;
    }
    const int mid = l + (r - l) / 2;
    modify(where, delta, l, mid, 2 * node + 1);
    modify(where, delta, mid + 1, r, 2 * node + 2);
    seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]);
  }
public:
  SegmentTree(const vector<int> &arr) : LO(0), HI((int)arr.size() - 1) {
    seg.clear();
    seg.resize(4 * (int) arr.size());
    build(LO, HI, 0, arr);
  }
  void modify(int where, int delta) {
    modify(where, delta, LO, HI, 0);
  }
  long long worst_prefix() {
    return seg[0].best;
  } 
};

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  vector<tuple<int, int, int>> arr(n);
  vector<pair<int, int>> top_up;
  vector<int> distancias;
  for (int i = 0; i < n; i++) {
    int x, a, b;
    cin >> x >> a >> b;
    arr[i] = make_tuple(x, a, b);
    distancias.emplace_back(d - a);
  }
  sort(arr.begin(), arr.end());
  for (int i = 0; i < n; i++) top_up.emplace_back(get<2>(arr[i]), i);
  sort(top_up.begin(), top_up.end());
  vector<int> pre = {0};
  vector<int> where_is_it(n);
  for (int i = 0; i < n; i++) {
    int dist = get<0>(arr[i]) - (i - 1 < 0 ? 0 : get<0>(arr[i - 1]));
    distancias.emplace_back(dist);
    pre.emplace_back(-dist);
    where_is_it[i] = pre.size();
    pre.emplace_back(get<1>(arr[i]));
  }
  distancias.emplace_back(d);
  pre.emplace_back(-d + get<0>(arr.back()));
  sort(distancias.begin(), distancias.end());
  distancias.erase(unique(distancias.begin(), distancias.end()), distancias.end());
  SegmentTree seg(pre);
  int rem = 0;
  for (auto cur : distancias) {
    while(rem < n && get<0>(top_up[rem]) < cur) {
      const int where = where_is_it[get<1>(top_up[rem])];
      seg.modify(where, 0);
      ++rem;
    }
    seg.modify(0, cur);
    if (seg.worst_prefix() >= 0) {
      cout << cur << '\n';
      return 0;
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 69076 KB Output is correct
2 Correct 289 ms 68996 KB Output is correct
3 Correct 362 ms 69052 KB Output is correct
4 Correct 310 ms 69072 KB Output is correct
5 Correct 355 ms 69072 KB Output is correct
6 Correct 292 ms 69212 KB Output is correct
7 Correct 285 ms 69072 KB Output is correct
8 Correct 347 ms 69204 KB Output is correct
9 Correct 316 ms 69072 KB Output is correct
10 Correct 309 ms 69096 KB Output is correct
11 Correct 298 ms 69072 KB Output is correct
12 Correct 292 ms 69112 KB Output is correct
13 Correct 307 ms 69072 KB Output is correct
14 Correct 294 ms 69116 KB Output is correct
15 Correct 279 ms 69072 KB Output is correct
16 Correct 298 ms 69200 KB Output is correct
17 Correct 292 ms 69076 KB Output is correct
18 Correct 287 ms 69072 KB Output is correct
19 Correct 284 ms 69088 KB Output is correct
20 Correct 281 ms 69076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 9 ms 2944 KB Output is correct
3 Correct 8 ms 2944 KB Output is correct
4 Correct 8 ms 2944 KB Output is correct
5 Correct 8 ms 2944 KB Output is correct
6 Correct 8 ms 2944 KB Output is correct
7 Correct 8 ms 2944 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 12 ms 2944 KB Output is correct
15 Correct 12 ms 2944 KB Output is correct
16 Correct 12 ms 2944 KB Output is correct
17 Correct 12 ms 2944 KB Output is correct
18 Correct 12 ms 2944 KB Output is correct
19 Correct 9 ms 2944 KB Output is correct
20 Correct 8 ms 2944 KB Output is correct
21 Correct 9 ms 3072 KB Output is correct
22 Correct 8 ms 2944 KB Output is correct
23 Correct 8 ms 2944 KB Output is correct
24 Correct 9 ms 2944 KB Output is correct
25 Correct 8 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 9 ms 2944 KB Output is correct
3 Correct 8 ms 2944 KB Output is correct
4 Correct 8 ms 2944 KB Output is correct
5 Correct 8 ms 2944 KB Output is correct
6 Correct 8 ms 2944 KB Output is correct
7 Correct 8 ms 2944 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 12 ms 2944 KB Output is correct
15 Correct 12 ms 2944 KB Output is correct
16 Correct 12 ms 2944 KB Output is correct
17 Correct 12 ms 2944 KB Output is correct
18 Correct 12 ms 2944 KB Output is correct
19 Correct 9 ms 2944 KB Output is correct
20 Correct 8 ms 2944 KB Output is correct
21 Correct 9 ms 3072 KB Output is correct
22 Correct 8 ms 2944 KB Output is correct
23 Correct 8 ms 2944 KB Output is correct
24 Correct 9 ms 2944 KB Output is correct
25 Correct 8 ms 2944 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 255 ms 70740 KB Output is correct
28 Correct 255 ms 70888 KB Output is correct
29 Correct 248 ms 70740 KB Output is correct
30 Correct 250 ms 70904 KB Output is correct
31 Correct 253 ms 70740 KB Output is correct
32 Correct 289 ms 70732 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 471 ms 70832 KB Output is correct
40 Correct 455 ms 70740 KB Output is correct
41 Correct 452 ms 70736 KB Output is correct
42 Correct 447 ms 70736 KB Output is correct
43 Correct 445 ms 70772 KB Output is correct
44 Correct 306 ms 70736 KB Output is correct
45 Correct 319 ms 70744 KB Output is correct
46 Correct 254 ms 70736 KB Output is correct
47 Correct 250 ms 70864 KB Output is correct
48 Correct 258 ms 70788 KB Output is correct
49 Correct 240 ms 70736 KB Output is correct
50 Correct 276 ms 70812 KB Output is correct
51 Correct 252 ms 70736 KB Output is correct
52 Correct 247 ms 70864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 9 ms 2944 KB Output is correct
18 Correct 8 ms 2944 KB Output is correct
19 Correct 8 ms 2944 KB Output is correct
20 Correct 8 ms 2944 KB Output is correct
21 Correct 8 ms 2944 KB Output is correct
22 Correct 8 ms 2944 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 12 ms 2944 KB Output is correct
30 Correct 12 ms 2944 KB Output is correct
31 Correct 12 ms 2944 KB Output is correct
32 Correct 12 ms 2944 KB Output is correct
33 Correct 12 ms 2944 KB Output is correct
34 Correct 9 ms 2944 KB Output is correct
35 Correct 8 ms 2944 KB Output is correct
36 Correct 9 ms 3072 KB Output is correct
37 Correct 8 ms 2944 KB Output is correct
38 Correct 8 ms 2944 KB Output is correct
39 Correct 9 ms 2944 KB Output is correct
40 Correct 8 ms 2944 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 10 ms 2944 KB Output is correct
43 Correct 10 ms 2944 KB Output is correct
44 Correct 11 ms 3072 KB Output is correct
45 Correct 13 ms 3064 KB Output is correct
46 Correct 11 ms 3072 KB Output is correct
47 Correct 11 ms 3072 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 18 ms 3104 KB Output is correct
55 Correct 16 ms 3072 KB Output is correct
56 Correct 16 ms 3072 KB Output is correct
57 Correct 15 ms 3072 KB Output is correct
58 Correct 14 ms 3072 KB Output is correct
59 Correct 14 ms 3072 KB Output is correct
60 Correct 10 ms 3072 KB Output is correct
61 Correct 9 ms 3072 KB Output is correct
62 Correct 12 ms 3072 KB Output is correct
63 Correct 10 ms 3072 KB Output is correct
64 Correct 11 ms 3072 KB Output is correct
65 Correct 10 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 292 ms 69076 KB Output is correct
17 Correct 289 ms 68996 KB Output is correct
18 Correct 362 ms 69052 KB Output is correct
19 Correct 310 ms 69072 KB Output is correct
20 Correct 355 ms 69072 KB Output is correct
21 Correct 292 ms 69212 KB Output is correct
22 Correct 285 ms 69072 KB Output is correct
23 Correct 347 ms 69204 KB Output is correct
24 Correct 316 ms 69072 KB Output is correct
25 Correct 309 ms 69096 KB Output is correct
26 Correct 298 ms 69072 KB Output is correct
27 Correct 292 ms 69112 KB Output is correct
28 Correct 307 ms 69072 KB Output is correct
29 Correct 294 ms 69116 KB Output is correct
30 Correct 279 ms 69072 KB Output is correct
31 Correct 298 ms 69200 KB Output is correct
32 Correct 292 ms 69076 KB Output is correct
33 Correct 287 ms 69072 KB Output is correct
34 Correct 284 ms 69088 KB Output is correct
35 Correct 281 ms 69076 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 9 ms 2944 KB Output is correct
38 Correct 8 ms 2944 KB Output is correct
39 Correct 8 ms 2944 KB Output is correct
40 Correct 8 ms 2944 KB Output is correct
41 Correct 8 ms 2944 KB Output is correct
42 Correct 8 ms 2944 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 12 ms 2944 KB Output is correct
50 Correct 12 ms 2944 KB Output is correct
51 Correct 12 ms 2944 KB Output is correct
52 Correct 12 ms 2944 KB Output is correct
53 Correct 12 ms 2944 KB Output is correct
54 Correct 9 ms 2944 KB Output is correct
55 Correct 8 ms 2944 KB Output is correct
56 Correct 9 ms 3072 KB Output is correct
57 Correct 8 ms 2944 KB Output is correct
58 Correct 8 ms 2944 KB Output is correct
59 Correct 9 ms 2944 KB Output is correct
60 Correct 8 ms 2944 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 255 ms 70740 KB Output is correct
63 Correct 255 ms 70888 KB Output is correct
64 Correct 248 ms 70740 KB Output is correct
65 Correct 250 ms 70904 KB Output is correct
66 Correct 253 ms 70740 KB Output is correct
67 Correct 289 ms 70732 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 471 ms 70832 KB Output is correct
75 Correct 455 ms 70740 KB Output is correct
76 Correct 452 ms 70736 KB Output is correct
77 Correct 447 ms 70736 KB Output is correct
78 Correct 445 ms 70772 KB Output is correct
79 Correct 306 ms 70736 KB Output is correct
80 Correct 319 ms 70744 KB Output is correct
81 Correct 254 ms 70736 KB Output is correct
82 Correct 250 ms 70864 KB Output is correct
83 Correct 258 ms 70788 KB Output is correct
84 Correct 240 ms 70736 KB Output is correct
85 Correct 276 ms 70812 KB Output is correct
86 Correct 252 ms 70736 KB Output is correct
87 Correct 247 ms 70864 KB Output is correct
88 Correct 0 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 320 KB Output is correct
92 Correct 0 ms 384 KB Output is correct
93 Correct 0 ms 384 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 0 ms 384 KB Output is correct
98 Correct 1 ms 384 KB Output is correct
99 Correct 1 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 10 ms 2944 KB Output is correct
105 Correct 10 ms 2944 KB Output is correct
106 Correct 11 ms 3072 KB Output is correct
107 Correct 13 ms 3064 KB Output is correct
108 Correct 11 ms 3072 KB Output is correct
109 Correct 11 ms 3072 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 1 ms 384 KB Output is correct
114 Correct 0 ms 384 KB Output is correct
115 Correct 1 ms 384 KB Output is correct
116 Correct 18 ms 3104 KB Output is correct
117 Correct 16 ms 3072 KB Output is correct
118 Correct 16 ms 3072 KB Output is correct
119 Correct 15 ms 3072 KB Output is correct
120 Correct 14 ms 3072 KB Output is correct
121 Correct 14 ms 3072 KB Output is correct
122 Correct 10 ms 3072 KB Output is correct
123 Correct 9 ms 3072 KB Output is correct
124 Correct 12 ms 3072 KB Output is correct
125 Correct 10 ms 3072 KB Output is correct
126 Correct 11 ms 3072 KB Output is correct
127 Correct 10 ms 2944 KB Output is correct
128 Correct 0 ms 384 KB Output is correct
129 Correct 303 ms 69840 KB Output is correct
130 Correct 308 ms 69968 KB Output is correct
131 Correct 319 ms 69968 KB Output is correct
132 Correct 309 ms 69840 KB Output is correct
133 Correct 313 ms 69880 KB Output is correct
134 Correct 315 ms 69840 KB Output is correct
135 Correct 1 ms 384 KB Output is correct
136 Correct 1 ms 384 KB Output is correct
137 Correct 0 ms 384 KB Output is correct
138 Correct 1 ms 384 KB Output is correct
139 Correct 1 ms 384 KB Output is correct
140 Correct 1 ms 384 KB Output is correct
141 Correct 573 ms 69844 KB Output is correct
142 Correct 569 ms 69844 KB Output is correct
143 Correct 526 ms 69840 KB Output is correct
144 Correct 581 ms 69840 KB Output is correct
145 Correct 651 ms 69840 KB Output is correct
146 Incorrect 486 ms 69956 KB Output isn't correct
147 Halted 0 ms 0 KB -