Submission #1091080

#TimeUsernameProblemLanguageResultExecution timeMemory
1091080TrinhKhanhDungLottery (CEOI18_lot)C++14
100 / 100
255 ms8304 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(1e9 + 7) using namespace std; 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 T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX_N = 1e4 + 10, MAX_Q = 1e2 + 10; int N, L, Q; int a[MAX_N]; int ans[MAX_Q][MAX_N], id[MAX_N]; vector<int> queries; void solve(){ cin >> N >> L; for(int i = 1; i <= N; i++) cin >> a[i]; cin >> Q; memset(id, -1, sizeof id); vector<int> b; for(int i = 1; i <= Q; i++){ int x; cin >> x; b.push_back(x); queries.push_back(x); } cps(b); for(int i = 0; i < sz(b); i++){ id[b[i]] = i; } for(int i = N; i >= 0; i--){ if(id[i] == -1) id[i] = id[i + 1]; } for(int d = -(N - L); d <= (N - L); d++){ if(d == 0) continue; int cur = 0; for(int i = 0; i < L; i++){ int p = 1 + max(0, d) + i; cur += a[p] != a[p - d]; } for(int i = 0; i < N - L + 1 - abs(d); i++){ int p = 1 + max(d, 0) + i; if(id[cur] != -1){ ans[id[cur]][p]++; } cur -= a[p] != a[p - d]; cur += a[p + L] != a[p + L - d]; } } for(int i = 1; i < sz(b); i++){ for(int j = 1; j <= N - L + 1; j++){ ans[i][j] += ans[i - 1][j]; } } for(auto k: queries){ for(int i = 1; i <= N - L + 1; i++){ cout << ans[id[k]][i] << ' '; } cout << '\n'; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("mst.inp","r",stdin); // freopen("mst.out","w",stdout); int t = 1; // cin >> t; while(t--){ solve(); } 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...