Submission #827625

#TimeUsernameProblemLanguageResultExecution timeMemory
827625Ronin13Lottery (CEOI18_lot)C++17
100 / 100
1617 ms8292 KiB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#define ll long long 
#define ull unsigned ll
#define f first
#define s second 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back

using namespace std;
const int nmax = 15001;

int ans[nmax];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int l; cin >> l;
    int a[n + 1];
    int b[n + 1];
    fill(b, b + n + 1, 0);
    for(int i  = 1; i <= n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    int cnt[n + 1][q];
    vector <int> vec;
    int k[q + 1];
    for(int i = 1; i <= q; i++){
        int x; cin >> x;
        k[i] = x;
        vec.pb(x);
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    for(int i = 1; i <= n; i++){
        for(int j =0; j < q; j++)
            cnt[i][j] = 0;
    }
    for(int d = 1; d <= n; d++){
        fill(b, b + n + 1, 0);
        for(int j = 1; j <= n - d; j++){
            b[j] = (a[j] != a[j + d]);
            b[j] += b[j - 1];
        }
        for(int i = 1; i <= n - l - d + 1; i++){
            int val = b[i + l - 1] - b[i - 1];
            int  x= lower_bound(vec.begin(), vec.end(), val) - vec.begin();
            if(x == vec.size()) continue;
            cnt[i][x]++;
        }
    }
    for(int d = 1; d <= n; d++){
        fill(b, b + n + 1, 0);
        for(int j = d + 1; j <= n; j++){
            b[j] = (a[j] != a[j - d]);
            b[j] += b[j - 1];
        }
        for(int i = d + 1; i <= n - l + 1; i++){
            int val = b[i + l - 1] - b[i - 1];
            int  x= lower_bound(vec.begin(), vec.end(), val) - vec.begin();
            if(x == vec.size()) continue;
            cnt[i][x]++;
        }
    }
    for(int j = 1; j < q; j++){
        for(int i = 1; i <= n; i++)
        cnt[i][j] += cnt[i][j - 1];
    }
    for(int j = 1; j <= q; j++){
        int ind = 0;
        for(int i = 0; i < vec.size(); i++)
            if(k[j] == vec[i]) ind = i;
        for(int i = 1; i <= n - l + 1; i++){
            cout << cnt[i][ind] << ' ';
        }
        cout << "\n";
    }
    return 0;
}

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             if(x == vec.size()) continue;
      |                ~~^~~~~~~~~~~~~
lot.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if(x == vec.size()) continue;
      |                ~~^~~~~~~~~~~~~
lot.cpp:84:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(int i = 0; i < vec.size(); 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...