Submission #1291508

#TimeUsernameProblemLanguageResultExecution timeMemory
1291508nqcLottery (CEOI18_lot)C++20
100 / 100
193 ms8392 KiB
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define debug(x) cout << #x << " = " << x << '\n'
#define all(a) a.begin(), a.end()
#define SZ(a) (int)(a).size()

const int N = 1e4 + 5;
const int mod = 1e9 + 7;
const ll inf64 = 3e18;
const int inf32 = 2e9 + 5;

int n, L, a[N], q;
pii qr[105];
int pos[N], ans[N][105];

void solve() {
    cin >> n >> L;
    for(int i = 1; i <= n; i++) 
        cin >> a[i];
    cin >> q;
    for(int i = 1; i <= q; i++) 
        cin >> qr[i].fi, qr[i].se = i;

    sort(qr + 1, qr + 1 + q);

    qr[0].fi = -1;
    for(int i = 1; i <= q; i++) {
        int j = qr[i].fi;
        while(j >= 0 && j > qr[i - 1].fi) 
            pos[j] = i, j--;
    }

    for(int d = 1; d + L <= n; d++) {
        int cur = 0;
        for(int i = 1; i <= L; i++) 
            cur += a[i] != a[d + i];

        if(pos[cur]) {
            ans[1][pos[cur]]++;
            ans[1 + d][pos[cur]]++; 
        }

        for(int i = 2; i + d + L - 1 <= n; i++) {
            cur += a[i + L - 1] != a[i + d + L - 1];
            cur -= a[i - 1] != a[i - 1 + d];

            if(pos[cur]) {
                ans[i][pos[cur]]++;
                ans[i + d][pos[cur]]++;
            }
        }
    }

    for(int i = 1; i + L - 1 <= n; i++) {
        for(int j = 1; j <= q; j++) 
            ans[i][j] += ans[i][j - 1];
    }

    sort(qr + 1, qr + 1 + q, [](pii a, pii b) { return a.se < b.se; });

    for(int i = 1; i <= q; i++) {
        for(int j = 1; j + L - 1 <= n; j++) 
            cout << ans[j][pos[qr[i].fi]] << ' ';
        cout << '\n';
    }
}

int main() {
    auto start = chrono::steady_clock::now();

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    int test = 1; 
    // cin >> test;
    while(test--) solve();
    
    chrono::duration<double> elapsed {chrono::steady_clock::now() - start};
    cerr << "\n>> Runtime: " << elapsed.count() << "s\n";
}

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
lot.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...