제출 #1091881

#제출 시각아이디문제언어결과실행 시간메모리
1091881gygLottery (CEOI18_lot)C++17
80 / 100
3061 ms2636 KiB
#include <bits/stdc++.h>
using namespace std;
#define arr array
#define vct vector
const int MX_N = 1e4 + 5, MX_Q = 1e2 + 5;

int n, l;
arr<int, MX_N> vl;
int q;
arr<int, MX_Q> qry;

arr<arr<int, MX_N>, 2> sm;
vct<int> sms;
arr<arr<int, MX_N>, MX_Q> ans;
void cmp() {
    for (int i = n; i >= 1; i--) {
        int prt = i % 2, opp_prt = (i + 1) % 2;
        
        for (int j = 1; j <= n; j++) sm[prt][j] = (vl[i] == vl[j]) + sm[opp_prt][j + 1];
        
        sms.clear();
        for (int j = 1; j <= n - l + 1; j++)
            if (j != i) sms.push_back(sm[prt][j]);
        
        for (int j = 1; j <= q; j++) 
            ans[j][i] = count_if(sms.begin(), sms.end(), [j](int x) { return x >= l - qry[j]; } );   
        
        for (int j = 1; j <= n; j++) {
            int nw_i = i + l - 1, nw_j = j + l - 1;
            if (max(nw_i, nw_j) > n) continue;
            sm[prt][j] -= (vl[nw_i] == vl[nw_j]);
        }
    }
}

int main() {
    // freopen("lttry.in", "r", stdin);
    cin >> n >> l;
    for (int i = 1; i <= n; i++) cin >> vl[i];
    cin >> q;
    for (int i = 1; i <= q; i++) cin >> qry[i];

    cmp();

    for (int i = 1; i <= q; i++) {
        for (int j = 1; j <= n - l + 1; j++) cout << ans[i][j] << " ";
        cout << endl;
    }
}
#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...