Submission #129120

#TimeUsernameProblemLanguageResultExecution timeMemory
129120arnold518Lottery (CEOI18_lot)C++14
100 / 100
1146 ms8352 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e4;

int N, L, Q, A[MAXN+10], query[MAXN+10], ans[110][MAXN+10];
vector<int> V;

int main()
{
    int i, j;

    scanf("%d%d", &N, &L);
    for(i=1; i<=N; i++) scanf("%d", &A[i]);
    scanf("%d", &Q);
    for(i=1; i<=Q; i++) scanf("%d", &query[i]), V.push_back(query[i]);
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());

    for(i=L+1; i<=N; i++)
    {
        int now=0;
        for(j=1; j<=L; j++) now+=(A[j]!=A[i-L+j]);

        int it=lower_bound(V.begin(), V.end(), now)-V.begin();
        if(it!=V.size()) ans[it][1]++, ans[it][i-L+1]++;

        for(j=i+1; j<=N; j++)
        {
            now-=(A[j-i]!=A[j-L]);
            now+=(A[L+j-i]!=A[j]);

            int it=lower_bound(V.begin(), V.end(), now)-V.begin();
            if(it!=V.size()) ans[it][1+j-i]++, ans[it][j-L+1]++;
        }
    }

    for(i=1; i<V.size(); i++)
    {
        for(j=1; j<=N-L+1; j++) ans[i][j]+=ans[i-1][j];
    }

    for(i=1; i<=Q; i++)
    {
        int it=lower_bound(V.begin(), V.end(), query[i])-V.begin();
        for(j=1; j<=N-L+1; j++) printf("%d ", ans[it][j]);
        printf("\n");
    }
}

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:30:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(it!=V.size()) ans[it][1]++, ans[it][i-L+1]++;
            ~~^~~~~~~~~~
lot.cpp:38:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(it!=V.size()) ans[it][1+j-i]++, ans[it][j-L+1]++;
                ~~^~~~~~~~~~
lot.cpp:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=1; i<V.size(); i++)
              ~^~~~~~~~~
lot.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &L);
     ~~~~~^~~~~~~~~~~~~~~~
lot.cpp:18:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%d", &A[i]);
                         ~~~~~^~~~~~~~~~~~~
lot.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
     ~~~~~^~~~~~~~~~
lot.cpp:20:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=Q; i++) scanf("%d", &query[i]), V.push_back(query[i]);
                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...