Submission #208684

# Submission time Handle Problem Language Result Execution time Memory
208684 2020-03-12T02:04:04 Z bensonlzl Telefoni (COCI17_telefoni) C++14
80 / 80
33 ms 3368 KB
#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 time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 31 ms 3320 KB Output is correct
9 Correct 33 ms 3324 KB Output is correct
10 Correct 31 ms 3368 KB Output is correct