Submission #710173

# Submission time Handle Problem Language Result Execution time Memory
710173 2023-03-15T05:26:11 Z zyq_ Money (IZhO17_money) C++17
0 / 100
104 ms 125544 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N;
int dp[1000010];
deque<pair<int, int> > run;
int inp;
vector<int> v;
set<int> curvals;
int maxbefore[1000010];

struct node{ //range min
    int s, e, M;
    int val;
    node *l, *r;
    node(int S, int E){
        s = S;
        e = E;
        M = (S + E)/2;
        val = INT_MAX;
        if(s == e) return;
        l = new node(S, M);
        r = new node(M+1, E);
    }
    void update(int x, int k){
        if(s == e){
            val = min(val, k);
            return;
        }
        if(x <= M) l->update(x, k);
        else r->update(x, k);
    }
    int query(int x, int y){
        if(x <= s && e <= y){
            return val;
        }
        if(y <= M) return l->query(x, y);
        else if(x > M) return r->query(x, y);
        else return min(l->query(x, M), r->query(M+1, y));
    }
} *root;

int32_t main() {
    cin >> N;
    root = new node(1, 1000010);
    for(int a=0; a<N; a++){
        dp[a] = 0;
        cin >> inp;
        v.push_back(inp);
        if(a == 0){
            maxbefore[a] = 0;
        }
        else{
            if(v[a-1] <= v[a]){
                maxbefore[a] = maxbefore[a-1];
            }
            else{
                maxbefore[a] = a;
            }
        }
    }
    run.push_back({0, -1});
    for(int a=0; a<N; a++){
        //cout << "hi";
        //start the dp
        //eradicate imposs queue
        //cout << run.size();
        //cout << maxbefore[a];
        while(!run.empty()){
            if(run[0].second < maxbefore[a]-1) run.pop_front();
            else break;
        }
        //cout << "ok";
        //cout << run.size();
        //cout << run.back().second;
        while(!run.empty()){
            //check if current thing fits somewhere
            //range from v[run[0].first] to v[a]
            //cout << (curvals.upper_bound(v[run[0].second]) == curvals.end());
            //cout << (curvals.lower_bound(v[a]) == curvals.end());
            if(v[run[0].second+1] != v[a] && v[run[0].second+1]+1 != v[a] && root->query(v[run[0].second+1]+1, v[a]-1) < run[0].second+1) run.pop_front();
            else break;
        }
        //then start to do
        //cout << "again";
       // cout << run.size();
        dp[a] = run[0].first + 1;
        while(!run.empty()){
            if(run.back().first > dp[a]){
                run.pop_back();
            }
            else break;
        }
        //cout << "sup";
        run.push_back({dp[a], a});
        root->update(v[a], a);
        //cout << dp[a] << '\n';
    }
    cout << dp[N-1];
}

# Verdict Execution time Memory Grader output
1 Correct 86 ms 125484 KB Output is correct
2 Correct 84 ms 125428 KB Output is correct
3 Correct 89 ms 125452 KB Output is correct
4 Correct 88 ms 125536 KB Output is correct
5 Correct 89 ms 125452 KB Output is correct
6 Correct 90 ms 125432 KB Output is correct
7 Correct 88 ms 125512 KB Output is correct
8 Correct 85 ms 125512 KB Output is correct
9 Correct 102 ms 125544 KB Output is correct
10 Incorrect 104 ms 125516 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 125484 KB Output is correct
2 Correct 84 ms 125428 KB Output is correct
3 Correct 89 ms 125452 KB Output is correct
4 Correct 88 ms 125536 KB Output is correct
5 Correct 89 ms 125452 KB Output is correct
6 Correct 90 ms 125432 KB Output is correct
7 Correct 88 ms 125512 KB Output is correct
8 Correct 85 ms 125512 KB Output is correct
9 Correct 102 ms 125544 KB Output is correct
10 Incorrect 104 ms 125516 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 125484 KB Output is correct
2 Correct 84 ms 125428 KB Output is correct
3 Correct 89 ms 125452 KB Output is correct
4 Correct 88 ms 125536 KB Output is correct
5 Correct 89 ms 125452 KB Output is correct
6 Correct 90 ms 125432 KB Output is correct
7 Correct 88 ms 125512 KB Output is correct
8 Correct 85 ms 125512 KB Output is correct
9 Correct 102 ms 125544 KB Output is correct
10 Incorrect 104 ms 125516 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 125484 KB Output is correct
2 Correct 84 ms 125428 KB Output is correct
3 Correct 89 ms 125452 KB Output is correct
4 Correct 88 ms 125536 KB Output is correct
5 Correct 89 ms 125452 KB Output is correct
6 Correct 90 ms 125432 KB Output is correct
7 Correct 88 ms 125512 KB Output is correct
8 Correct 85 ms 125512 KB Output is correct
9 Correct 102 ms 125544 KB Output is correct
10 Incorrect 104 ms 125516 KB Output isn't correct
11 Halted 0 ms 0 KB -