E - 本棚の整理 / Organizing the Bookshelf 解説 by physics0523


GNU C++ ext/rope を利用することができます。

実装例 (C++):

#include<bits/stdc++.h>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

int main(){
  int n,q;
  cin >> n >> q;
  rope<int> rp;
  for(int i=0;i<n;i++){
    int d;
    cin >> d;
    rp.push_back(d);
  }
  while(q--){
    int t;
    cin >> t;
    t--;
    if(t<n){
      int val=rp[t];
      rp.erase(t,1);
      if(val>1){
        rp.insert(t,val-1);
      }
      else{
        n--;
      }
    }
    cout << n << "\n";
  }
  return 0;
}

投稿日時:
最終更新: