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;
const int N = 5010;
struct fenwick {
int f[N];
void update(int i, int v) { ++i; while(i < N) f[i] += v, i += i & -i; }
int query(int i) {
++i;
int ret = 0;
while(i > 0) ret += f[i], i -= i & -i;
return ret;
}
int query(int l, int r) { return query(r) - query(l-1); }
};
int n, m, k;
bool state[N];
fenwick dp[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 0; i < n; i++) cin >> state[i];
for(int j = m-1; j >= 1; j--) for(int i = n-1; i >= 0; i--) {
if(state[(i+1) % n] == state[i])
dp[i].update(j, dp[(i+1) % n].query(min(m, j+1), min(m, j+k)) > 0);
else
dp[i].update(j, dp[(i+1) % n].query(min(m, j+1), min(m, j+k)) == 0);
}
for(int i = 0; i < n; i++) {
bool res = 0;
for(int j = 1; j <= min(m-1, k); j++) res |= dp[i].query(j, j) == 1;
cout << (res ^ 1 ^ state[i]) << ' ';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |