Submission #397347

#TimeUsernameProblemLanguageResultExecution timeMemory
397347abdzagLottery (CEOI18_lot)C++17
25 / 100
387 ms644 KiB
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=int(a);i<int(b);i++) #define rrep(i,a,b) for(int i=int(a);i>int(b);i--) #define all(v) v.begin(),v.end() #define trav(a,v) for(auto&a:v) using namespace std; const long long inf = 1e15; typedef long long ll; int main() { cin.sync_with_stdio(false); ll n, l; cin >> n >> l; vector<ll> v(n); rep(i, 0, n)cin >> v[i]; ll q; cin >> q; ll mx = 1000; ll sz = min(n - l + 1,mx); vector<ll> dist(n - l + 1); vector<vector<short>> howmany(sz,vector<short>(l+1)); rep(i, 0,sz) { rep(j, 0, l) { if (v[i + j] != v[j])dist[i]++; } } rep(j, 0, dist.size()) howmany[0][dist[j]] ++; rep(i, 1, sz) { rrep(j, sz - 1, 0) { dist[j] = dist[j - 1]; } dist[0] = 0; rep(j, 0, l) { if (v[j] != v[i + j])dist[0]++; } rep(j, 0, sz - 1) { dist[j + 1] -= (v[i - 1] != v[j]); dist[j + 1] += (v[i + l - 1] != v[j + l]); } rep(j, 0, dist.size()) howmany[i][dist[j]] ++; } vector<vector<short>> prefix(sz, vector<short>(l + 2)); rep(i, 0, sz) { rep(j, 1, l + 2) { prefix[i][j] = prefix[i][j - 1] + howmany[i][j - 1]; } } rep(Q, 0, q){ ll k; cin >> k; vector<ll> res(n-l+1); rep(i, 0, sz) { res[i] = prefix[i][k+1]-1; } rep(i, sz, n - l+1) { rep(j, 0, l) { if (v[i + j] != v[j])dist[i]++; } } if (sz < n - l + 1) { rep(j, 0, n - l + 1) { res[sz + 1] += (dist[j] <= k); } } rep(i, sz+1, n - l + 1) { rrep(j, n - l, 0) { dist[j] = dist[j - 1]; } dist[0] = 0; rep(j, 0, l) { if (v[j] != v[i + j])dist[0]++; } rep(j, 0, n - l) { dist[j+1] -= (v[i - 1] != v[j]); dist[j + 1] += (v[i + l-1] != v[j + l]); } rep(j, 0, n - l + 1) { res[i] += (dist[j] <= k); } } trav(a, res)cout << a << " "; cout << endl; } return 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...