답안 #710128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710128 2023-03-15T05:01:39 Z zyq_ Money (IZhO17_money) C++17
0 / 100
0 ms 212 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];

int32_t main() {
    cin >> N;
    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
        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(curvals.upper_bound(v[run[0].second+1]) != curvals.lower_bound(v[a])) 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});
        curvals.insert(v[a]);
        //cout << dp[a] << '\n';
    }
    cout << dp[N-1];
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -