제출 #966918

#제출 시각아이디문제언어결과실행 시간메모리
966918Charizard2021Lottery (CEOI18_lot)C++17
45 / 100
32 ms1116 KiB
#include<bits/stdc++.h> using namespace std; const int p = 1e9 + 7; const int MOD = 1e9 + 21; const int MODInverse = 928571448; int main(){ int n, l; cin >> n >> l; long long powers[1 + n]; powers[0] = 1; long long invPowers[1 + n]; invPowers[0] = 1; for(int i = 1; i <= n; i++){ powers[i] = powers[i - 1] * p % MOD; invPowers[i] = invPowers[i - 1] * MODInverse % MOD; } vector<int> a(1 + n); vector<long long> hashing(1 + n, 0); for(int i = 1; i <= n; i++){ cin >> a[i]; hashing[i] = (hashing[i - 1] + powers[i] * a[i]) % MOD; } int q; cin >> q; if(n <= 300){ while(q--){ int val; cin >> val; vector<int> ans(1 + n, 0); for(int i = 1; i + l - 1 <= n; i++){ for(int j = i + 1; j + l - 1 <= n; j++){ int thing = 0; for(int k = 0; k < l; k++){ if(a[i + k] != a[j + k]){ thing++; } } if(thing <= val){ ans[i]++; ans[j]++; } } } for(int i = 1; i + l - 1 <= n; i++){ cout << ans[i] << " "; } cout << "\n"; } } else if(q == 1){ int k; cin >> k; if(k == 0){ map<long long, int> freq; for(int i = 1; i + l - 1 <= n; i++){ long long num = hashing[i + l - 1] - hashing[i - 1]; num %= MOD; if(num < 0){ num += MOD; } num = (num * invPowers[i]) % MOD; freq[num]++; } for(int i = 1; i + l - 1 <= n; i++){ long long num = hashing[i + l - 1] - hashing[i - 1]; num %= MOD; if(num < 0){ num += MOD; } num = (num * invPowers[i]) % MOD; cout << freq[num] - 1 << " "; } cout << "\n"; } } }
#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...