Submission #161379

#TimeUsernameProblemLanguageResultExecution timeMemory
161379rama_pangLottery (CEOI18_lot)C++14
100 / 100
1425 ms8376 KiB
#include <bits/stdc++.h>
using namespace std;

int N, L, q, A[10005];
int ans[105][10005];
int true_ans[105][10005];
pair<int, int> Q[105];
int pos[105];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> L; for (int i = 0; i < N; i++) cin >> A[i];
    cin >> q; for (int i = 0; i < q; i++) cin >> Q[i].first;
    for (int i = 0; i < q; i++) Q[i].second = i;
    sort(Q, Q + q);
    for (int i = 0; i < q; i++) pos[Q[i].second] = i;

    /* The segment compared is segment i...(i + L - 1) and (i + shift)...(i + L + shift - 1) */
    for (int shift = 1, similiar = 0; shift + L - 1 < N; shift++, similiar = 0) {
        for (int i = 0; i < L; i++) 
            if (A[i] == A[i + shift]) similiar++;
        
        for (int i = 0; i + shift + L - 1 < N; i++) { // then sliding window can be used
            int j = lower_bound(Q, Q + q, make_pair(L - similiar, -1)) - Q;
            ans[j][i]++, ans[j][i + shift]++; // Add 1 to the answer for the lowest Q possible

            if (A[i] == A[i + shift]) similiar--;
            if (A[i + L] == A[i + shift + L]) similiar++;
        }
    }

    /* If Q[i] <= Q[j], then all answers from Q[i] can be used in Q[j] */
    for (int i = 0; i < N - L + 1; i++) 
        for (int j = 1; j < q; j++) 
            ans[j][i] += ans[j - 1][i];

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < N - L + 1; j++) 
            cout << ans[pos[i]][j] << " ";

        cout << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...