Submission #86093

#TimeUsernameProblemLanguageResultExecution timeMemory
86093zubecLottery (CEOI18_lot)C++14
100 / 100
835 ms9352 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int n, l, a[20010], dp[110][10010], pos[10010], b[110], c[110];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);

    cin >> n >> l;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        a[i+n] = a[i];
    }
    int q;
    cin >> q;

    for (int i = 1; i <= q; i++){
        cin >> b[i];
        c[i] = b[i];
    }
    sort(c+1, c+q+1);
    for (int i = 1; i <= q; i++){
        pos[c[i]] = i;
    }
    pos[n+1] = q+1;
    for (int i = n; i >= 0; i--){
        if (pos[i] == 0)
            pos[i] = pos[i+1];
    }
    int cnt = 0;
    for (int sz = 1; sz <= n; sz++){
        int curans = 0;
        if (l+sz > n)
            break;
        for (int i = 1; i < l; i++){
            if (a[i] != a[i+sz])
                ++curans;
        }
        for (int i = 1; i <= n; i++){
            if (i+l-1+sz > n)
                break;
            if (i != 1 && a[i-1] != a[i+sz-1])
                --curans;
            if (a[i+l-1] != a[i+l-1+sz])
                ++curans;
            //cout << sz << ' ' << i << ' ' << curans << endl;
            /*if (curans <= 28 && i == 1){
                cout << "kek " << curans << ' ' << pos[curans] << ' ' << pos[28] << endl;
            }*/
            ++dp[pos[curans]][i];
            ++dp[pos[curans]][i+sz];
        }
    }
    /*cout << cnt;
    return 0;*/
    for (int i = 1; i <= q; i++){
        for (int j = 1; j <= n; j++)
            dp[i][j] += dp[i-1][j];
    }
    for (int i = 1; i <= q; i++){
        for (int j = 1; j <= n-l+1; j++){
            cout << dp[pos[b[i]]][j] << ' ';
        }
        cout << "\n";
    }

}

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:32:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt = 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...