Submission #892161

# Submission time Handle Problem Language Result Execution time Memory
892161 2023-12-25T02:26:05 Z therealpain Financial Report (JOI21_financial) C++17
33 / 100
40 ms 12748 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x) (((x) >> (i)) & 1)
#define TASK ""

using namespace std;

template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
    if (a < b) a = b; else return false; return true;
}

template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
    if (a > b) a = b; else return false; return true;
}

const long long inf = 1e18;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;

int n;
int d;
int a[N];

namespace subtask2 {
    int dp[405][405];
    vector <int> value;

    void solve() {
        for (int i = 1; i <= n; ++i) value.push_back(a[i]);

        sort(all(value));
        value.erase(unique(all(value)), value.end());
        int m = (int) value.size();

        for (int i = 1; i <= n; ++i) {
            a[i] = lower_bound(all(value), a[i]) - value.begin() + 1;
        }

        memset(dp, -0x3f, sizeof dp);

        for (int i = 1; i <= n; ++i) dp[i][a[i]] = 1;

        for (int i = 1; i <= n; ++i) {
            for (int j = i - 1; j >= max(i - d, 1); --j) {
                for (int mx = 1; mx <= m; ++mx) {
                    maxi(dp[i][max(mx, a[i])], dp[j][mx] + (mx < a[i]));
                }
            }
        }

        cout << *max_element(dp[n] + 1, dp[n] + m + 1);
    }
};

namespace subtask4 {
    vector <int> value;

    struct IntervalTree {
        int st[N << 2];
        int lazy[N << 2];

        void init() {
            memset(st, 0, sizeof st);
            memset(lazy, -1, sizeof lazy);
        }

        void fix(int id, int l, int r) {
            if (lazy[id] == -1) return;
            st[id] += lazy[id] * (r - l + 1);
            if (l < r) {
                lazy[id << 1] += lazy[id];
                lazy[id << 1 | 1] += lazy[id];
            }

            lazy[id] = -1;
            return;
        }

        void update(int id, int l, int r, int u, int v, int value) {
            fix(id, l, r);
            if (l > v || r < u) return;
            if (u <= l && r <= v) {
                lazy[id] = value;
                fix(id, l, r);
                return;
            }

            int mid = l + r >> 1;
            update(id << 1, l, mid, u, v, value);
            update(id << 1 | 1, mid + 1, r, u, v, value);
            st[id] = st[id << 1] + st[id << 1 | 1];
        }

        int get(int id, int l, int r, int u, int v) {
            fix(id, l, r);
            if (l > v || r < u) return 0;
            if (u <= l && r <= v) return st[id];

            int mid = l + r >> 1;
            return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v);
        }
    } IT;

    void solve() {
        for (int i = 1; i <= n; ++i) {
            value.push_back(a[i]);
        }

        sort(all(value));
        value.erase(unique(all(value)), value.end());
        int m = value.size();

        for (int i = 1; i <= n; ++i) {
            a[i] = lower_bound(all(value), a[i]) - value.begin() + 1;
        }

        int mx = 0;
        int ans = 0;
        int temp = 0;


        IT.init();
        for (int i = n; i >= 1; --i) {
            ++temp;
            maxi(mx, a[i]);
            temp -= IT.get(1, 1, m, 1, a[i]);
            IT.update(1, 1, m, 1, a[i], 0);
            IT.update(1, 1, m, a[i], a[i], 1);
            maxi(ans, temp);
        }

        cout << ans;
    }
};

namespace subtask5 {
    void solve() {
        vector <int> dp;

        for (int i = 1; i <= n; ++i) {
            int p = lower_bound(all(dp), a[i]) - dp.begin();
            if (p == dp.size()) dp.push_back(a[i]);
            else dp[p] = a[i];
        }

        cout << (int) dp.size() << '\n';
    }
};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);
    cin >> n >> d;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    if (n <= 400) subtask2::solve();
    else if (d == 1) subtask4::solve();
    else if (d == n) subtask5::solve();
}

Compilation message

Main.cpp: In member function 'void subtask4::IntervalTree::update(int, int, int, int, int, int)':
Main.cpp:90:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |             int mid = l + r >> 1;
      |                       ~~^~~
Main.cpp: In member function 'int subtask4::IntervalTree::get(int, int, int, int, int)':
Main.cpp:101:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |             int mid = l + r >> 1;
      |                       ~~^~~
Main.cpp: In function 'void subtask5::solve()':
Main.cpp:144:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |             if (p == dp.size()) dp.push_back(a[i]);
      |                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2480 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2480 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 3 ms 2516 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 39 ms 2396 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2396 KB Output is correct
35 Correct 2 ms 2396 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 4 ms 2396 KB Output is correct
40 Correct 5 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2480 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 3 ms 2516 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 39 ms 2396 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2396 KB Output is correct
35 Correct 2 ms 2396 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 4 ms 2396 KB Output is correct
40 Correct 5 ms 2396 KB Output is correct
41 Incorrect 5 ms 10844 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3160 KB Output is correct
2 Correct 35 ms 3160 KB Output is correct
3 Correct 40 ms 3164 KB Output is correct
4 Correct 37 ms 3156 KB Output is correct
5 Correct 38 ms 3796 KB Output is correct
6 Correct 36 ms 3124 KB Output is correct
7 Correct 28 ms 5328 KB Output is correct
8 Correct 23 ms 3164 KB Output is correct
9 Correct 30 ms 3796 KB Output is correct
10 Correct 34 ms 3284 KB Output is correct
11 Correct 38 ms 3276 KB Output is correct
12 Correct 24 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2480 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 3 ms 2516 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 39 ms 2396 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2396 KB Output is correct
35 Correct 2 ms 2396 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 4 ms 2396 KB Output is correct
40 Correct 5 ms 2396 KB Output is correct
41 Incorrect 5 ms 10844 KB Output isn't correct
42 Halted 0 ms 0 KB -