제출 #208684

#제출 시각아이디문제언어결과실행 시간메모리
208684bensonlzlTelefoni (COCI17_telefoni)C++14
80 / 80
33 ms3368 KiB
#include <bits/stdc++.h>

using namespace std;

int PURQ_fenwick[600010], arr[600010];

void add(int x, int v){
  for (;x <= 600000; x += (x & -x)){
    PURQ_fenwick[x] += v;
  }
}

int query(int x){
  if (x == 0) return 0;
  int sum = 0;
  for (;x;x -= (x & -x)){
    sum += PURQ_fenwick[x];
  }
  return sum;
}

int rquery(int l, int r){
  return query(r) - query(l-1);
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie();
  int N, D;
  cin >> N >> D;
  for (int i = 1; i <= N; ++i){
    cin >> arr[i];
    if (arr[i]) add(i,arr[i]);
  }
  int pt = 1, tot = 0;
  while (1){
    if (pt == N) break;
    if (rquery(pt+1,pt+D) == 0){
      arr[pt+D] = 1;
      add(pt+D,1);
      tot++;
    }
    pt++;
  }
  cout << tot << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...