# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208684 | bensonlzl | Telefoni (COCI17_telefoni) | C++14 | 33 ms | 3368 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |