Submission #973687

# Submission time Handle Problem Language Result Execution time Memory
973687 2024-05-02T09:38:35 Z Ooops_sorry Constellation 3 (JOI20_constellation3) C++14
35 / 100
1500 ms 52888 KB
#include<iostream>
#include<deque>
#include<algorithm>
#include<vector>
#include<map>
#include<random>
#include<time.h>
#include<cassert>
#include<chrono>
#include<set>
#include<unordered_set>
#include<array>
 
using namespace std;
 
#define ull unsigned long long
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()
#define ld long double 
#define int long long 

mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

struct SegTree {
  vector<pair<int, int>> t;
  int n;
  SegTree(int n_) {
    n = 1;
    while (n < n_) {
      n *= 2;
    }
    t.resize(2 * n);
  }
  void upd(int i, pair<int, int> val) {
    i += n;
    t[i] = val;
    for (; i > 1; i /= 2) {
      t[i / 2] = max(t[i], t[i ^ 1]);
    } 
  }
  pair<int, int> get(int l, int r) {
    l += n, r += n + 1;
    pair<int, int> ans{-1, -1};
    while (l < r) {
      if (l & 1) {
        ans = max(ans, t[l++]);
      }
      if (r & 1) {
        ans = max(ans, t[--r]);
      }
      l /= 2, r /= 2;
    }
    return ans;
  }
};

const int N = 2e5 + 10;
vector<pair<int, ll>> mas[N];
int a[N];
SegTree t(N);

vector<pair<int, ll>> solve(int l, int r) {
  if (l > r) return vector<pair<int, ll>> {};
  if (l == r) {
    sort(all(mas[l]));
    return mas[l];
  }
  int m = t.get(l, r).second;
  auto arr1 = solve(l, m - 1), arr2 = solve(m + 1, r);
  ll best1 = 0, best2 = 0;
  for (auto p : arr1) {
    if (p.first <= a[m]) {
      best1 = max(best1, p.second);
    }
  }
  for (auto p : arr2) {
    if (p.first <= a[m]) {
      best2 = max(best2, p.second);
    }
  }
  vector<pair<int, ll>> res;
  {
    int j = -1;
    ll best = 0;
    for (auto p : arr1) {
      while (j + 1 < arr2.size() && arr2[j + 1].first <= p.first) {
        j++;
        best = max(best, arr2[j].second);
      }
      if (p.first <= a[m]) {
        res.pb({p.first, p.second + best});
      } else {
        res.pb({p.first, p.second + best2});
      }
    }
  }
  {
    int j = -1;
    ll best = 0;
    for (auto p : arr2) {
      while (j + 1 < arr1.size() && arr1[j + 1].first <= p.first) {
        j++;
        best = max(best, arr1[j].second);
      }
      if (p.first <= a[m]) {
        res.pb({p.first, p.second + best});
      } else {
        res.pb({p.first, p.second + best1});
      }
    }
  }
  for (auto p : mas[m]) {
    res.pb({p.first, p.second + best1 + best2});
  }
  sort(all(res));
  return res;
}

signed main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif // LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    t.upd(i, {a[i], i});
  }
  int m;
  cin >> m;
  ll sum = 0;
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    if (y <= a[x]) continue;
    sum += c;
    mas[x].pb({y, c});
  }
  auto res = solve(0, n - 1);
  ll mx = 0;
  for (auto p : res) {
    mx = max(mx, p.second);
  }
  cout << sum - mx << endl;
  return 0; 
}

Compilation message

constellation3.cpp: In function 'std::vector<std::pair<long long int, long long int> > solve(long long int, long long int)':
constellation3.cpp:87:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |       while (j + 1 < arr2.size() && arr2[j + 1].first <= p.first) {
      |              ~~~~~~^~~~~~~~~~~~~
constellation3.cpp:102:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |       while (j + 1 < arr1.size() && arr1[j + 1].first <= p.first) {
      |              ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14680 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Correct 4 ms 14684 KB Output is correct
4 Correct 4 ms 14684 KB Output is correct
5 Correct 4 ms 14684 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 4 ms 14684 KB Output is correct
8 Correct 4 ms 14804 KB Output is correct
9 Correct 4 ms 14684 KB Output is correct
10 Correct 5 ms 14684 KB Output is correct
11 Correct 5 ms 14824 KB Output is correct
12 Correct 4 ms 14684 KB Output is correct
13 Correct 5 ms 14704 KB Output is correct
14 Correct 4 ms 14684 KB Output is correct
15 Correct 5 ms 14684 KB Output is correct
16 Correct 7 ms 14684 KB Output is correct
17 Correct 4 ms 14684 KB Output is correct
18 Correct 4 ms 14684 KB Output is correct
19 Correct 4 ms 14684 KB Output is correct
20 Correct 5 ms 14684 KB Output is correct
21 Correct 5 ms 14684 KB Output is correct
22 Correct 4 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14680 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Correct 4 ms 14684 KB Output is correct
4 Correct 4 ms 14684 KB Output is correct
5 Correct 4 ms 14684 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 4 ms 14684 KB Output is correct
8 Correct 4 ms 14804 KB Output is correct
9 Correct 4 ms 14684 KB Output is correct
10 Correct 5 ms 14684 KB Output is correct
11 Correct 5 ms 14824 KB Output is correct
12 Correct 4 ms 14684 KB Output is correct
13 Correct 5 ms 14704 KB Output is correct
14 Correct 4 ms 14684 KB Output is correct
15 Correct 5 ms 14684 KB Output is correct
16 Correct 7 ms 14684 KB Output is correct
17 Correct 4 ms 14684 KB Output is correct
18 Correct 4 ms 14684 KB Output is correct
19 Correct 4 ms 14684 KB Output is correct
20 Correct 5 ms 14684 KB Output is correct
21 Correct 5 ms 14684 KB Output is correct
22 Correct 4 ms 14684 KB Output is correct
23 Correct 5 ms 15192 KB Output is correct
24 Correct 6 ms 14760 KB Output is correct
25 Correct 6 ms 14940 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 6 ms 14824 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 6 ms 14940 KB Output is correct
30 Correct 6 ms 14940 KB Output is correct
31 Correct 6 ms 14940 KB Output is correct
32 Correct 45 ms 15248 KB Output is correct
33 Correct 42 ms 14940 KB Output is correct
34 Correct 32 ms 14940 KB Output is correct
35 Correct 29 ms 14940 KB Output is correct
36 Correct 36 ms 15196 KB Output is correct
37 Correct 37 ms 15196 KB Output is correct
38 Correct 62 ms 15376 KB Output is correct
39 Correct 6 ms 14940 KB Output is correct
40 Correct 53 ms 15492 KB Output is correct
41 Correct 7 ms 14940 KB Output is correct
42 Correct 6 ms 14940 KB Output is correct
43 Correct 53 ms 15196 KB Output is correct
44 Correct 7 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14680 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Correct 4 ms 14684 KB Output is correct
4 Correct 4 ms 14684 KB Output is correct
5 Correct 4 ms 14684 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 4 ms 14684 KB Output is correct
8 Correct 4 ms 14804 KB Output is correct
9 Correct 4 ms 14684 KB Output is correct
10 Correct 5 ms 14684 KB Output is correct
11 Correct 5 ms 14824 KB Output is correct
12 Correct 4 ms 14684 KB Output is correct
13 Correct 5 ms 14704 KB Output is correct
14 Correct 4 ms 14684 KB Output is correct
15 Correct 5 ms 14684 KB Output is correct
16 Correct 7 ms 14684 KB Output is correct
17 Correct 4 ms 14684 KB Output is correct
18 Correct 4 ms 14684 KB Output is correct
19 Correct 4 ms 14684 KB Output is correct
20 Correct 5 ms 14684 KB Output is correct
21 Correct 5 ms 14684 KB Output is correct
22 Correct 4 ms 14684 KB Output is correct
23 Correct 5 ms 15192 KB Output is correct
24 Correct 6 ms 14760 KB Output is correct
25 Correct 6 ms 14940 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 6 ms 14824 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 6 ms 14940 KB Output is correct
30 Correct 6 ms 14940 KB Output is correct
31 Correct 6 ms 14940 KB Output is correct
32 Correct 45 ms 15248 KB Output is correct
33 Correct 42 ms 14940 KB Output is correct
34 Correct 32 ms 14940 KB Output is correct
35 Correct 29 ms 14940 KB Output is correct
36 Correct 36 ms 15196 KB Output is correct
37 Correct 37 ms 15196 KB Output is correct
38 Correct 62 ms 15376 KB Output is correct
39 Correct 6 ms 14940 KB Output is correct
40 Correct 53 ms 15492 KB Output is correct
41 Correct 7 ms 14940 KB Output is correct
42 Correct 6 ms 14940 KB Output is correct
43 Correct 53 ms 15196 KB Output is correct
44 Correct 7 ms 14940 KB Output is correct
45 Correct 300 ms 32568 KB Output is correct
46 Correct 271 ms 31148 KB Output is correct
47 Correct 302 ms 30808 KB Output is correct
48 Correct 292 ms 32328 KB Output is correct
49 Correct 296 ms 32760 KB Output is correct
50 Correct 296 ms 32112 KB Output is correct
51 Correct 284 ms 30392 KB Output is correct
52 Correct 301 ms 31512 KB Output is correct
53 Correct 285 ms 32584 KB Output is correct
54 Execution timed out 1541 ms 52888 KB Time limit exceeded
55 Halted 0 ms 0 KB -