Submission #882074

# Submission time Handle Problem Language Result Execution time Memory
882074 2023-12-02T14:41:43 Z skywwla Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
72 ms 14248 KB
#include <bits/stdc++.h>

using namespace std ;
using ll = long long ;

struct SegTree {
   int _n ;
   struct Node {
      ll value = 0 ;
      Node() {}
      Node(ll x) {
         value = x ;
      }
   };
   Node combine(Node l, Node r) {
      if (l.value > r.value) return l ;
      return r ;
   }
   vector<Node> t ;
   SegTree(int len) {
      _n = len ;
      t.assign(len * 4 + 1, Node(0)) ;
   }
   void modify(int i, ll x, int v, int tl, int tr) {
      if (tl == tr) {
         t[v] = combine(t[v], x) ;
    } else {
         int tm = (tl + tr) >> 1 ;
         if (i <= tm)
            modify(i, x, v << 1, tl, tm) ;
         else
            modify(i, x, v << 1 | 1, tm + 1, tr) ;
         t[v] = combine(t[v * 2], t[v * 2 + 1]) ;
      }
   }
   void modify(int i, ll x) {
      modify(i, x, 1, 1, _n) ;
   }
   Node get(int l, int r, int v, int tl, int tr) {
      if (l > tr || r < tl) return Node(0) ;
      if (l <= tl && tr <= r) return t[v] ;
      int tm = (tl + tr) >> 1 ;
      Node L = get(l, r, v << 1, tl, tm) ;
      Node R = get(l ,r, v << 1 | 1, tm + 1, tr) ;
      return combine(L, R) ;
   }
   Node get(int l, int r) {
       if (l > r) return 0 ;
      return get(l, r, 1, 1, _n) ;
   }
};

int32_t main() {
    ios::sync_with_stdio(false) ;
    cin.tie(nullptr) ;
    int n , m ; cin >> n >> m ;
    vector<ll> a(n) ;
    for (ll &i : a) cin >> i ;
    vector<ll> b ;
    for (int i = 0 ; i < n ; i++) {
        ll cur = (i + 1) * m - a[i] ;
        if (cur >= 0) {
            b.push_back(cur) ;
        }
    }
    auto calc = [&](vector<ll>& v) -> int {
        if (!v.size()) return 0;
        vector<ll> c(v.begin(), v.end()) ;
        sort(c.begin(), c.end()) ;
        c.erase(unique(c.begin(), c.end()), c.end()) ;
        auto get = [&](int i) -> int {
            return (lower_bound(c.begin(), c.end(), i) - c.begin() + 1) ;
        };
        SegTree s(c.size()) ;
        vector<ll> dp(v.size(), 1) ;
        for (int i = 0 ; i < v.size() ; i++) {
            dp[i] = max(dp[i], s.get(1, get(v[i])).value + 1) ;
            s.modify(get(v[i]), dp[i]) ;
        }
        return *max_element(dp.begin(), dp.end()) ;
    };
    cout << n - calc(b) ;
    return 0 ;
}

Compilation message

triusis.cpp: In lambda function:
triusis.cpp:76:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int i = 0 ; i < v.size() ; i++) {
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 400 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 500 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 400 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 500 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 656 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 672 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 680 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 656 KB Output is correct
5 Correct 2 ms 856 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 400 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 500 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 2 ms 648 KB Output is correct
43 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 656 KB Output is correct
15 Correct 2 ms 856 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 672 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 400 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 500 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 62 ms 13520 KB Output is correct
45 Correct 21 ms 4308 KB Output is correct
46 Correct 66 ms 9420 KB Output is correct
47 Correct 66 ms 9488 KB Output is correct
48 Correct 66 ms 13896 KB Output is correct
49 Correct 66 ms 14248 KB Output is correct
50 Correct 22 ms 7484 KB Output is correct
51 Correct 28 ms 8644 KB Output is correct
52 Correct 52 ms 10788 KB Output is correct
53 Correct 17 ms 3160 KB Output is correct
54 Correct 68 ms 14024 KB Output is correct
55 Correct 72 ms 14036 KB Output is correct