답안 #172841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172841 2020-01-02T16:40:46 Z Swan Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("pcb.in","r",stdin)
#define OUTP freopen ("pcb.out","w",stdout)
using namespace std;

const int maxn = 1e6+2;

vector<int> v;
int dp[maxn];
int bit[maxn];

namespace fen{
    int bit[maxn];
    void upd(int id,int x){
        while(id < maxn){
            bit[id]+=x;
            id|=id+1;
        }
    }
    int sum(int x){
        int res = 0;
        while(x>=0){
            res+=bit[x];
            x&=x+1;x--;
        }
        return res;
    }
    int segm(int l,int r){
        int ans = sum(r);
        if(l)ans-=sum(l-1);
        return ans;
    }
}

main(){
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    vector<pair<int,int> > qwe;
    int last = -1;
    int cnt = 0;
    for(int i(0); i < n;i++){
        int x; cin >> x;
        v.push_back(x);
        if(x!=last && last!=-1){
            qwe.push_back({last,cnt});
            cnt = 0;
        }else if(last == -1){
            last = x;
            cnt = 0;
        }
        cnt++;
    }
    dp[0] = 1;
    int l = 0;
    for(int i(1);i < n;i++){
        if(v[i] < v[i-1]){
            for(int z(l); z < i;z++)fen::upd(v[z],1);
            l = i;
            dp[i] = dp[i-1]+1;
            continue;
        }
        while(1){
            if(v[i]-v[l]>1){
                int kek = fen::segm(v[l],v[i]);
                if(kek){
                    fen::upd(v[l],1);
                    l++;
                }else break;
            }else break;
        }
        dp[i] = dp[l-1]+1;
    }
    cout << dp[n-1];
}
/*
*/

Compilation message

money.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -