#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Lottery"
int n, l, q;
int a[10001];
int to[10001];
short ans[10001][101];
int r[101];
pair <int, int> k[101];
deque <int> dq;
int main(){
#ifdef Aria
if(fopen(taskname".in", "r"))
freopen(taskname".in", "r", stdin);
#endif // Aria
read(n);
read(l);
FOR(i, 1, n) read(a[i]);
read(q);
FOR(i, 1, q){
read(k[i].first);
k[i].second=i;
}
sort(k+1, k+q+1);
DFOR(i, q, 1){
r[k[i].second]=i;
FOR(j, 1, k[i].first) to[j]=i;
}
FOR(d, 1, n){
if(d+l>n) break;
dq.clear();
FFOR(i, 1, l) dq.pb(a[i]!=a[i+d]);
int sum=accumulate(dq.begin(), dq.end(), 0);
FOR(i, l, n){
if(i+d>n) break;
dq.pb(a[i]!=a[i+d]);
sum+=dq.back();
ans[i][to[sum]]++;
ans[i+d][to[sum]]++;
sum-=dq.front();
dq.pop_front();
}
}
FOR(i, 1, n) FOR(j, 1, q) ans[i][j]+=ans[i][j-1];
sort(k+1, k+q+1, [](pair <int, int> A, pair <int, int> B){
return A.second<B.second;
});
FOR(i, 1, q) FOR(j, l, n) write(ans[j][r[k[i].second]]), putchar(" \n"[j==n]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
753 ms |
2380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
753 ms |
2380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |