Submission #522081

#TimeUsernameProblemLanguageResultExecution timeMemory
522081LoboLottery (CEOI18_lot)C++17
25 / 100
54 ms40152 KiB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 2020

int n, l, a[maxn], ps[maxn][maxn], qtd[maxn][maxn];
vector<int> pos[maxn];

void solve() {
    cin >> n >> l;

    vector<int> cc;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        cc.pb(a[i]);
    }
    sort(all(cc));
    cc.erase(unique(all(cc)),cc.end());

    for(int i = 1; i <= n; i++) {
        a[i] = upper_bound(all(cc),a[i]) - cc.begin();
        pos[a[i]].pb(i-l+1);
    }

    for(int i = 1; i <= n; i++) {
        for(auto x : pos[i]) {
            for(auto y : pos[i]) {
                if(x == y) continue;

                // cout << " " << x << " " << y << endl;

                int x1 = x;
                int y1 = y;
                int x2 = x+l;
                int y2 = y+l;

                if(x1 <= 0) {
                    y1+= 1-x1;
                    x1 = 1;
                }
                if(y1 <= 0) {
                    x1+= 1-y1;
                    y1 = 1;
                }

                ps[x1][y1]++;
                if(x2 <= n && y2 <= n) ps[x2][y2]--;

                // cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
            }
        }
    }

    for(int i = 1; i <= n; i++) {
        //coordenada que comeca em (1,i);

        int x = 2;
        int y = i+1;

        while(y <= n) {
            ps[x][y]+= ps[x-1][y-1];
            x++;
            y++;
        }
    }

    

    for(int i = 2; i <= n; i++) {
        //coordenada que comeca em (i,1);

        int x = i+1;
        int y = 2;

        while(x <= n) {
            ps[x][y]+= ps[x-1][y-1];
            x++;
            y++;
        }
    }

    // for(int i = 1; i <= n; i++) {
    //     for(int j = 1; j <= n; j++) {
    //         cout << i << " " << j << " " << ps[i][j] << " " << endl;
    //     }
    // }

    for(int i = 1; i <= n-l+1; i++) {
        for(int j = 1; j <= n-l+1; j++) {
            if(i == j) continue;
            qtd[i][l-ps[i][j]]++;
        }
        for(int j = 1; j <= l; j++) {
            qtd[i][j]+= qtd[i][j-1];
        }
    }

    int q; cin >> q;
    while(q--) {
        int val; cin >> val;
        
        for(int i = 1; i <= n-l+1; i++) {
            cout << qtd[i][val] << " ";
        }cout << endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
    
    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}
#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...