Submission #1068714

#TimeUsernameProblemLanguageResultExecution timeMemory
1068714PotatoTheWarriorFRTTLottery (CEOI18_lot)C++14
20 / 100
104 ms1380 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
ll p1 = 27644437;
ll p2 = 1000000007;
 
// ll power(ll x, ll y) {
//     y = y%MOD;
//     x = x%MOD;
//     ll res = 1;
//     while(y != 0) {
//         if(y%2) {
//             res = (res*x)%MOD;
//         }
//         x = (x*x)%MOD;
//         y/=2;
//     }
//     return res;
// }
 
void solve() {
    int n, l; cin >> n >> l;
    int a[n+1];
    set<ll> s;
    map<ll, vector<int>> mape;
    for(int i=0;i<n;i++) {
        int x; cin >> x;
        s.insert(x);
        mape[x].push_back(i);
    }
    int k = 0;
    for(ll l: s) {
        for(int i=0;i<mape[l].size();i++) {
            a[mape[l][i]] = k;
        }
        k++;
    }
    ll powers[l+1];
    powers[0] = 1;
    for(int i=0;i<l-1;i++) {
        powers[i+1] = (powers[i] * p1)%p2;
    }


    unordered_map<ll, ll> m;
    ll hashes[n+1];
    for(int i=0;i<n-l+1;i++) {
        ll hash = 0;
        for(int j=0;j<l;j++) {
            hash = (hash + (a[i+j] * powers[j]))%p2;
        }
        hashes[i] = hash;
        m[hash]++;
    }
 
 
    int q; cin >> q;
    int ki; cin >> ki; // q=0;k=1;
 
    for(int i=0;i<n-l+1;i++) {
        cout << m[hashes[i]]-1 << " ";
    }
    cout << endl;
 
}
int main()   {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // int t; cin >> t;
    // while(t--) 
        solve();
 
    char dksfjn;
    cin >> dksfjn;
}

Compilation message (stderr)

lot.cpp: In function 'void solve()':
lot.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i=0;i<mape[l].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...