Submission #1049185

# Submission time Handle Problem Language Result Execution time Memory
1049185 2024-08-08T14:36:19 Z abczz Treatment Project (JOI20_treatment) C++17
100 / 100
217 ms 102952 KB
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <queue>
#define ll long long

using namespace std;

ll n, m, f, cur, dp[100000], X[100000];
bool ok[100000];
priority_queue <array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> pq;
array <ll, 4> A[100000];

struct SegTree{
  vector <array<ll, 2> > V[400000];
  void build(ll id, ll l, ll r) {
    if (l == r) {
      V[id].push_back({X[l], l});
      return;
    }
    ll mid = (l+r)/2;
    build(id*2, l, mid);
    build(id*2+1, mid+1, r);
    int i = 0, j = 0;
    while (i < V[id*2].size() && j < V[id*2+1].size()) {
      if (V[id*2][i][0] >= V[id*2+1][j][0]) V[id].push_back(V[id*2][i++]);
      else V[id].push_back(V[id*2+1][j++]);
    }
    while (i < V[id*2].size()) V[id].push_back(V[id*2][i++]);
    while (j < V[id*2+1].size()) V[id].push_back(V[id*2+1][j++]);
  }
  void query(ll id, ll l, ll r, ll ql, ll qr, ll x) {
    if (qr < l || r < ql) return;
    else if (ql <= l && r <= qr) {
      while (!V[id].empty() && V[id].back()[0] <= x) {
        if (!ok[V[id].back()[1]]) {
          //cout << A[V[id].back()[1]][1] << " " << A[V[id].back()[1]][2] << "*" << endl;
          dp[V[id].back()[1]] = cur + A[V[id].back()[1]][3];
          ok[V[id].back()[1]] = 1;
          pq.push({dp[V[id].back()[1]], V[id].back()[1]});
        }
        V[id].pop_back();
      }
      return;
    }
    ll mid = (l+r)/2;
    query(id*2, l, mid, ql, qr, x);
    query(id*2+1, mid+1, r, ql, qr, x);
  }
}STA, STB;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  f = 1e18;
  cin >> n >> m;
  for (int i=0; i<m; ++i) {
    for (int j=0; j<4; ++j) {
      cin >> A[i][j];
    }
  }
  sort(A, A+m);
  for (int i=0; i<m; ++i) X[i] = A[i][1]+A[i][0];
  STA.build(1, 0, m-1);
  for (int i=0; i<m; ++i) X[i] = A[i][1]-A[i][0];
  STB.build(1, 0, m-1);
  for (int i=0; i<m; ++i) {
    if (A[i][1] == 1) {
      ok[i] = 1;
      dp[i] = A[i][3];
      pq.push({dp[i], i});
    }
  }
  while (!pq.empty()) {
    auto [w, u] = pq.top();
    auto x = A[u];
    pq.pop();
    if (x[2] == n) f = min(f, dp[u]);
    cur = dp[u];
    STA.query(1, 0, m-1, u, m-1, x[2]+x[0]+1);
    STB.query(1, 0, m-1, 0, u, x[2]-x[0]+1);
  }
  if (f >= 1e18) cout << "-1\n";
  else cout << f << '\n';
}

Compilation message

treatment.cpp: In member function 'void SegTree::build(long long int, long long int, long long int)':
treatment.cpp:26:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     while (i < V[id*2].size() && j < V[id*2+1].size()) {
      |            ~~^~~~~~~~~~~~~~~~
treatment.cpp:26:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     while (i < V[id*2].size() && j < V[id*2+1].size()) {
      |                                  ~~^~~~~~~~~~~~~~~~~~
treatment.cpp:30:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (i < V[id*2].size()) V[id].push_back(V[id*2][i++]);
      |            ~~^~~~~~~~~~~~~~~~
treatment.cpp:31:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     while (j < V[id*2+1].size()) V[id].push_back(V[id*2+1][j++]);
      |            ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 121 ms 100544 KB Output is correct
2 Correct 104 ms 100124 KB Output is correct
3 Correct 126 ms 99780 KB Output is correct
4 Correct 123 ms 99712 KB Output is correct
5 Correct 144 ms 101928 KB Output is correct
6 Correct 147 ms 100480 KB Output is correct
7 Correct 131 ms 100544 KB Output is correct
8 Correct 92 ms 99776 KB Output is correct
9 Correct 90 ms 99780 KB Output is correct
10 Correct 91 ms 99700 KB Output is correct
11 Correct 166 ms 102272 KB Output is correct
12 Correct 158 ms 102308 KB Output is correct
13 Correct 153 ms 101616 KB Output is correct
14 Correct 164 ms 101572 KB Output is correct
15 Correct 141 ms 100548 KB Output is correct
16 Correct 140 ms 100544 KB Output is correct
17 Correct 134 ms 99776 KB Output is correct
18 Correct 143 ms 101316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 3 ms 23132 KB Output is correct
3 Correct 3 ms 23132 KB Output is correct
4 Correct 4 ms 23388 KB Output is correct
5 Correct 3 ms 23132 KB Output is correct
6 Correct 3 ms 23180 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 3 ms 22968 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 3 ms 23132 KB Output is correct
12 Correct 3 ms 23208 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 3 ms 23132 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 3 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 3 ms 23132 KB Output is correct
19 Correct 3 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 3 ms 23132 KB Output is correct
3 Correct 3 ms 23132 KB Output is correct
4 Correct 4 ms 23388 KB Output is correct
5 Correct 3 ms 23132 KB Output is correct
6 Correct 3 ms 23180 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 3 ms 22968 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 3 ms 23132 KB Output is correct
12 Correct 3 ms 23208 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 3 ms 23132 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 3 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 3 ms 23132 KB Output is correct
19 Correct 3 ms 23132 KB Output is correct
20 Correct 8 ms 26716 KB Output is correct
21 Correct 8 ms 26716 KB Output is correct
22 Correct 9 ms 26712 KB Output is correct
23 Correct 9 ms 26676 KB Output is correct
24 Correct 9 ms 26732 KB Output is correct
25 Correct 9 ms 26804 KB Output is correct
26 Correct 9 ms 26756 KB Output is correct
27 Correct 9 ms 26808 KB Output is correct
28 Correct 9 ms 26668 KB Output is correct
29 Correct 10 ms 26800 KB Output is correct
30 Correct 8 ms 26716 KB Output is correct
31 Correct 7 ms 26716 KB Output is correct
32 Correct 9 ms 26796 KB Output is correct
33 Correct 9 ms 26712 KB Output is correct
34 Correct 9 ms 26716 KB Output is correct
35 Correct 9 ms 26800 KB Output is correct
36 Correct 10 ms 26716 KB Output is correct
37 Correct 10 ms 26644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 100544 KB Output is correct
2 Correct 104 ms 100124 KB Output is correct
3 Correct 126 ms 99780 KB Output is correct
4 Correct 123 ms 99712 KB Output is correct
5 Correct 144 ms 101928 KB Output is correct
6 Correct 147 ms 100480 KB Output is correct
7 Correct 131 ms 100544 KB Output is correct
8 Correct 92 ms 99776 KB Output is correct
9 Correct 90 ms 99780 KB Output is correct
10 Correct 91 ms 99700 KB Output is correct
11 Correct 166 ms 102272 KB Output is correct
12 Correct 158 ms 102308 KB Output is correct
13 Correct 153 ms 101616 KB Output is correct
14 Correct 164 ms 101572 KB Output is correct
15 Correct 141 ms 100548 KB Output is correct
16 Correct 140 ms 100544 KB Output is correct
17 Correct 134 ms 99776 KB Output is correct
18 Correct 143 ms 101316 KB Output is correct
19 Correct 3 ms 23132 KB Output is correct
20 Correct 3 ms 23132 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 4 ms 23388 KB Output is correct
23 Correct 3 ms 23132 KB Output is correct
24 Correct 3 ms 23180 KB Output is correct
25 Correct 3 ms 23132 KB Output is correct
26 Correct 3 ms 22968 KB Output is correct
27 Correct 3 ms 23132 KB Output is correct
28 Correct 3 ms 23132 KB Output is correct
29 Correct 3 ms 23132 KB Output is correct
30 Correct 3 ms 23208 KB Output is correct
31 Correct 3 ms 23132 KB Output is correct
32 Correct 3 ms 23132 KB Output is correct
33 Correct 3 ms 23132 KB Output is correct
34 Correct 3 ms 23132 KB Output is correct
35 Correct 3 ms 23132 KB Output is correct
36 Correct 3 ms 23132 KB Output is correct
37 Correct 3 ms 23132 KB Output is correct
38 Correct 8 ms 26716 KB Output is correct
39 Correct 8 ms 26716 KB Output is correct
40 Correct 9 ms 26712 KB Output is correct
41 Correct 9 ms 26676 KB Output is correct
42 Correct 9 ms 26732 KB Output is correct
43 Correct 9 ms 26804 KB Output is correct
44 Correct 9 ms 26756 KB Output is correct
45 Correct 9 ms 26808 KB Output is correct
46 Correct 9 ms 26668 KB Output is correct
47 Correct 10 ms 26800 KB Output is correct
48 Correct 8 ms 26716 KB Output is correct
49 Correct 7 ms 26716 KB Output is correct
50 Correct 9 ms 26796 KB Output is correct
51 Correct 9 ms 26712 KB Output is correct
52 Correct 9 ms 26716 KB Output is correct
53 Correct 9 ms 26800 KB Output is correct
54 Correct 10 ms 26716 KB Output is correct
55 Correct 10 ms 26644 KB Output is correct
56 Correct 137 ms 100288 KB Output is correct
57 Correct 142 ms 100328 KB Output is correct
58 Correct 148 ms 99748 KB Output is correct
59 Correct 137 ms 100252 KB Output is correct
60 Correct 154 ms 100808 KB Output is correct
61 Correct 126 ms 99780 KB Output is correct
62 Correct 132 ms 99836 KB Output is correct
63 Correct 113 ms 100560 KB Output is correct
64 Correct 113 ms 100548 KB Output is correct
65 Correct 120 ms 100808 KB Output is correct
66 Correct 132 ms 100956 KB Output is correct
67 Correct 199 ms 101316 KB Output is correct
68 Correct 180 ms 101312 KB Output is correct
69 Correct 165 ms 101248 KB Output is correct
70 Correct 199 ms 101232 KB Output is correct
71 Correct 179 ms 101312 KB Output is correct
72 Correct 165 ms 101312 KB Output is correct
73 Correct 198 ms 101312 KB Output is correct
74 Correct 100 ms 100804 KB Output is correct
75 Correct 100 ms 100612 KB Output is correct
76 Correct 176 ms 102596 KB Output is correct
77 Correct 176 ms 102852 KB Output is correct
78 Correct 192 ms 102080 KB Output is correct
79 Correct 201 ms 101396 KB Output is correct
80 Correct 192 ms 100800 KB Output is correct
81 Correct 106 ms 100544 KB Output is correct
82 Correct 182 ms 100032 KB Output is correct
83 Correct 182 ms 100292 KB Output is correct
84 Correct 186 ms 100544 KB Output is correct
85 Correct 150 ms 101400 KB Output is correct
86 Correct 155 ms 101312 KB Output is correct
87 Correct 172 ms 101408 KB Output is correct
88 Correct 165 ms 101312 KB Output is correct
89 Correct 163 ms 101312 KB Output is correct
90 Correct 182 ms 102812 KB Output is correct
91 Correct 174 ms 101404 KB Output is correct
92 Correct 153 ms 101312 KB Output is correct
93 Correct 190 ms 101312 KB Output is correct
94 Correct 182 ms 101316 KB Output is correct
95 Correct 196 ms 101500 KB Output is correct
96 Correct 187 ms 102780 KB Output is correct
97 Correct 181 ms 102852 KB Output is correct
98 Correct 177 ms 102876 KB Output is correct
99 Correct 217 ms 102896 KB Output is correct
100 Correct 172 ms 102784 KB Output is correct
101 Correct 177 ms 102848 KB Output is correct
102 Correct 175 ms 102952 KB Output is correct
103 Correct 149 ms 101312 KB Output is correct