結果

問題 No.711 競技レーティング単調増加
ユーザー CleyLCleyL
提出日時 2024-02-14 13:45:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 3,920 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 142,084 KB
実行使用メモリ 22,092 KB
最終ジャッジ日時 2024-02-14 13:45:24
合計ジャッジ時間 8,122 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 161 ms
11,856 KB
testcase_19 AC 150 ms
11,728 KB
testcase_20 AC 161 ms
12,112 KB
testcase_21 AC 174 ms
12,368 KB
testcase_22 AC 185 ms
11,856 KB
testcase_23 AC 183 ms
12,752 KB
testcase_24 AC 178 ms
12,624 KB
testcase_25 AC 145 ms
11,472 KB
testcase_26 AC 163 ms
11,984 KB
testcase_27 AC 141 ms
11,472 KB
testcase_28 AC 45 ms
6,676 KB
testcase_29 AC 58 ms
6,676 KB
testcase_30 AC 204 ms
14,416 KB
testcase_31 AC 255 ms
15,440 KB
testcase_32 AC 271 ms
15,952 KB
testcase_33 AC 155 ms
11,344 KB
testcase_34 AC 144 ms
10,832 KB
testcase_35 AC 165 ms
12,624 KB
testcase_36 AC 31 ms
6,676 KB
testcase_37 AC 256 ms
22,092 KB
testcase_38 AC 199 ms
21,220 KB
testcase_39 AC 67 ms
8,272 KB
testcase_40 AC 71 ms
7,120 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 34 ms
6,676 KB
testcase_43 AC 152 ms
18,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
*/

template< typename T, typename F>
struct SegmentTree{
  private:
    int n;
    vector<T> node;

    F f;
    T initer;

  public:
    SegmentTree(int n_, F f, T initer) : f(f),initer(initer) {
      n = 1;
      while(n < n_)n*=2;
      node.resize(2*n-1, initer);
    }

    SegmentTree(int n_, F f,T initer, vector<T> x) : f(f),initer(initer) {
      n = 1;
      while(n < n_)n*=2;
      node.resize(2*n-1, initer);
      set(x);
    }

    void set(vector<T> x){
      for(int i = 0; (int)x.size() > i; i++){
        update(i,x[i]);
      }
    }

    void update(int x, T val){
      x += (n-1);

      node[x] = val;

      while(x > 0){
        x = (x-1)/2;
        node[x] = f(node[2*x+1],node[2*x+2]);
      }
    }

    void add(int x, T val){
      x += (n-1);
      
      node[x] += val;
      while(x > 0){
        x = (x-1)/2;
        node[x] = f(node[2*x+1],node[2*x+2]);
      }
    }

    T getf(int a,int b, int k=0, int l=0, int r=-1){
      
      if(r < 0){
        r = n-1;
      }
      if(r < a || b < l){
        return initer;
      }
      if(a <= l && r <= b){
        return node[k];
      }

      T vl = getf(a,b,2*k+1,l,(l+r)/2);
      T vr = getf(a,b,2*k+2,(l+r)/2+1,r);
      return f(vl,vr);
    }

    void debug(){
      int nw = 1;
      int curr = 1;
      cout << "---begin---" << endl;
      for(int i = 0; 2*n-1 > i; i++){
        cout << node[i] << " ";
        if(nw == curr)cout << endl,nw *= 2, curr=1;
        else curr++;
      }
      cout << "---end---" << endl;
    }
};

template <typename T, typename F>
SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer){
  return SegmentTree<T,F>{N,f,initer};
}

template <typename T, typename F>
SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer, vector<T> x){
  return SegmentTree<T,F>{N,f,initer,x};
}
int dp[200010];

int main(){
  int n;cin>>n;
  vector<long long> A;
  vector<long long> B;
  int ans = 0;
  for(int i = 0; n > i; i++){
    int x;cin>>x;
    x-=i;
    if(x > 0){
      A.push_back(x);
      B.push_back(x);
    }else ans++;
  }
  int m = B.size();
  sort(B.begin(), B.end());
  B.erase(unique(B.begin(), B.end()), B.end());
  map<long long, long long> Bc;
  for(int i = 0; B.size() > i; i++){
    Bc[B[i]] = i;
  }
  auto seg = get_segment_tree(B.size(), [](long long a, long long b){return max(a,b);}, 0LL);
  for(int i = 0; m > i; i++){
    auto z = seg.getf(0, Bc[A[i]]);
    seg.update(Bc[A[i]], z+1);
  }
  cout << m-seg.getf(0, B.size()-1)+ans << endl;
  
  return 0;
}
0