Submission #773314

# Submission time Handle Problem Language Result Execution time Memory
773314 2023-07-04T21:18:05 Z shrimb Fruits (NOI22_fruits) C++17
0 / 100
130 ms 28120 KB
#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 400001;
const int N = exp2(ceil(log2(maxn)));

int seg[2 * N];

int Query (int Left, int Right, int l = 1, int r = N, int ind = 1) {
    if (l > Right || r < Left) return 0;
    if (l >= Left && r <= Right) return seg[ind];
    int m = (l + r) / 2;
    return max(Query(Left, Right, l, m, ind * 2), Query(Left, Right, m + 1, r, ind * 2 + 1));
}

void Update (int i, int v) {
    i += N - 1;
    seg[i] = max(seg[i], v);
    while (i /= 2) seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
}

int a[maxn], c[maxn], m[maxn], t[maxn], dp[maxn];
signed main () {
    cin.tie(0)->sync_with_stdio(0);

    int n;
    cin >> n;

    bool used[n +1] = {};

    for (int i = 0 ; i < n ; i++) {
        cin >> a[i];
        m[i] = a[i];
        if (a[i] == -1) t[i] = 1;
        if (i) m[i] = max(m[i-1], m[i]), t[i] += t[i-1];
        used[a[i]] = 1;
    }

    vector<int> missing;

    for (int i = 1 ; i <= n ; i++) {
        cin >> c[i];
        if (!used[i]) missing.push_back(i);
    }


    int px = 0;
    for (int i = 0 ; i < n ; i++) {
        dp[i] = 0;
        if (i) dp[i] = max(dp[i], dp[i-1]);

        if (a[i] != -1) {
            dp[i] = max(dp[i], Query(1, a[i] - 1) + 1);
            if (a[i] == m[i] && missing[t[i] - 1] < a[i])
                Update(a[i], dp[i]);
        } else {
            int X = min(n,max({m[i] + 1, missing[t[i] - 1], px + 1}));
            px = X;
            // cerr << "X: " << X << endl;
            if (missing.size() && X <= missing.back()) {
                dp[i] = max(dp[i], Query(1, X - 1) + 1);
                Update(X, dp[i]);
            }
        }
        cout << dp[i] << " ";
    }
}

Compilation message

Main.cpp:14:1: warning: multi-line comment [-Wcomment]
   14 | //\
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 28120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -