Submission #1122293

#TimeUsernameProblemLanguageResultExecution timeMemory
1122293steveonalexLottery (CEOI18_lot)C++17
100 / 100
253 ms8308 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return __lg(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n"){ for(auto item: container) cout << item << separator; cout << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } void solve(){ int n, l; cin >> n >> l; vector<int> a(n); for(int i = 0; i<n; ++i) cin >> a[i]; int q; cin >> q; vector<int> query(q); for(int i = 0; i < q; ++i) cin >> query[i]; vector<int> pickle = query; remove_dup(pickle); int m = pickle.size(); vector<int> lmao(n+1, -1); for(int i = 0; i < m; ++i) lmao[pickle[i]] = i; for(int i = n - 1; i >= 0; --i) if (lmao[i] == -1) lmao[i] = lmao[i+1]; int cnt[n][m]; memset(cnt, 0, sizeof cnt); for(int L = 1; L < n - l + 1; ++L){ int cu = 0; for(int j = L; j < L + l - 1; ++j){ int i = j - L; cu += (a[i] != a[j]); } for(int j = L + l - 1; j < n; ++j){ int i = j - L; cu += (a[i] != a[j]); int idx = lmao[cu]; if (idx != -1){ cnt[i][idx]++; cnt[j][idx]++; } cu -= (a[i - l + 1] != a[j - l + 1]); } } for(int i = 0; i < n; ++i) for(int j = 1; j < m; ++j) cnt[i][j] += cnt[i][j-1]; for(int i: query){ int idx = lower_bound(ALL(pickle), i) - pickle.begin(); for(int j = l-1; j < n; ++j) cout << cnt[j][idx] << " "; cout << "\n"; } } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << "ms!\n"; 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...