Submission #93396

#TimeUsernameProblemLanguageResultExecution timeMemory
93396SpeedOfMagicLottery (CEOI18_lot)C++17
65 / 100
266 ms8184 KiB
/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
template<typename T, typename U>  using hmap = __gnu_pbds::gp_hash_table<T, U>;
//#define int long long
typedef long double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
#define check(a) put #a << ": " << a << endl;
void read() {}     template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){}     template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg  arg,Args...  args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here

void run() {
    int n, l;
    read(n, l);

    int a[n];
    rep(i, 0, n)
        get a[i];

    map<int, short> hsh;
    short p = 0;
    rep(i, 0, n) {
        if (!hsh.count(a[i]))
            hsh[a[i]] = p++;
        a[i] = hsh[a[i]];
    }

    int m = n - l + 1;

    int q;
    get q;

    if (q == 1) {
        map<int, int> buckets;
        const long long mod = 36028797018963913;
        long long hshes[m];
        rep(i, 0, m) {
            long long curHsh = 0;
            rep(j, 0, l) {
                long long t = a[i + j];
                curHsh = ((curHsh * 29ll) % mod + t) % mod;
            }
            buckets[curHsh]++;
            hshes[i] = curHsh;
        }
        rep(i, 0, m)
            print(buckets[hshes[i]] - 1);
    } else {
        short vals[m][m];
        rep(i, 0, m)
            rep(j, 0, m)
                vals[i][j] = l + (i == j);

        rep(i, 0, l) {
            v<short> buckets[p];
            rep(j, 0, m) {
                for (short k : buckets[a[i + j]]) {
                    vals[j][k]--;
                    vals[k][j]--;
                }

                buckets[a[i + j]].pb(j);
            }
        }

        rep(i, 0, m)
            sort(vals[i], vals[i] + m);

        for (; q; q--) {
            short k;
            get k;
            rep(i, 0, m)
                print((upper_bound(vals[i], vals[i] + m, k) - vals[i]));
            eol;
        }
    }
}

int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}
#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...