#include <bits/stdc++.h>
using namespace std;
int a[10005], s[10005], lb[10005], ans[105][10005], res[105][10005];
pair<int, int> k[10005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, l, q;
cin >> n >> l;
for (int i=1; i<=n; i++)
cin >> a[i];
cin >> q;
for (int i=1; i<=q; i++)
{
cin >> k[i].first;
k[i].second=i;
}
sort(k+1, k+q+1);
for (int i=1; i<=q; i++)
if (!lb[k[i].first])
lb[k[i].first]=i;
lb[l+1]=1e9;
for (int i=l; i>=0; i--)
if (!lb[i])
lb[i]=lb[i+1];
for (int i=1; i<n-l+1; i++)
{
for (int j=1; j<=n-l+1-i; j++)
s[j]=0;
for (int u=1, v=i+1; v<=n; u++, v++)
if (a[u]-a[v])
s[max(1, u-l+1)]++, s[min(n-l+2-i, u+1)]--;
for (int j=1; j<=n-l+1-i; j++)
{
s[j]+=s[j-1];
if (lb[s[j]]!=1e9)
{
ans[lb[s[j]]][j]++;
ans[lb[s[j]]][j+i]++;
}
}
}
for (int i=1; i<=n-l+1; i++)
for (int j=2; j<=q; j++)
ans[j][i]+=ans[j-1][i];
for (int i=1; i<=q; i++)
for (int j=1; j<=n-l+1; j++)
res[k[i].second][j]=ans[lb[k[i].first]][j];
for (int i=1; i<=q; i++)
{
for (int j=1; j<=n-l+1; j++)
cout << res[i][j] << ' ';
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
8 ms |
724 KB |
Output is correct |
15 |
Correct |
7 ms |
596 KB |
Output is correct |
16 |
Correct |
10 ms |
852 KB |
Output is correct |
17 |
Correct |
9 ms |
852 KB |
Output is correct |
18 |
Correct |
11 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
444 KB |
Output is correct |
2 |
Correct |
378 ms |
440 KB |
Output is correct |
3 |
Correct |
230 ms |
448 KB |
Output is correct |
4 |
Correct |
194 ms |
444 KB |
Output is correct |
5 |
Correct |
90 ms |
340 KB |
Output is correct |
6 |
Correct |
193 ms |
460 KB |
Output is correct |
7 |
Correct |
71 ms |
444 KB |
Output is correct |
8 |
Correct |
111 ms |
432 KB |
Output is correct |
9 |
Correct |
190 ms |
448 KB |
Output is correct |
10 |
Correct |
193 ms |
444 KB |
Output is correct |
11 |
Correct |
12 ms |
340 KB |
Output is correct |
12 |
Correct |
133 ms |
408 KB |
Output is correct |
13 |
Correct |
126 ms |
400 KB |
Output is correct |
14 |
Correct |
129 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
444 KB |
Output is correct |
2 |
Correct |
378 ms |
440 KB |
Output is correct |
3 |
Correct |
230 ms |
448 KB |
Output is correct |
4 |
Correct |
194 ms |
444 KB |
Output is correct |
5 |
Correct |
90 ms |
340 KB |
Output is correct |
6 |
Correct |
193 ms |
460 KB |
Output is correct |
7 |
Correct |
71 ms |
444 KB |
Output is correct |
8 |
Correct |
111 ms |
432 KB |
Output is correct |
9 |
Correct |
190 ms |
448 KB |
Output is correct |
10 |
Correct |
193 ms |
444 KB |
Output is correct |
11 |
Correct |
12 ms |
340 KB |
Output is correct |
12 |
Correct |
133 ms |
408 KB |
Output is correct |
13 |
Correct |
126 ms |
400 KB |
Output is correct |
14 |
Correct |
129 ms |
428 KB |
Output is correct |
15 |
Correct |
233 ms |
444 KB |
Output is correct |
16 |
Correct |
183 ms |
432 KB |
Output is correct |
17 |
Correct |
204 ms |
440 KB |
Output is correct |
18 |
Correct |
198 ms |
428 KB |
Output is correct |
19 |
Correct |
197 ms |
460 KB |
Output is correct |
20 |
Correct |
195 ms |
460 KB |
Output is correct |
21 |
Correct |
209 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
8 ms |
724 KB |
Output is correct |
15 |
Correct |
7 ms |
596 KB |
Output is correct |
16 |
Correct |
10 ms |
852 KB |
Output is correct |
17 |
Correct |
9 ms |
852 KB |
Output is correct |
18 |
Correct |
11 ms |
748 KB |
Output is correct |
19 |
Correct |
427 ms |
444 KB |
Output is correct |
20 |
Correct |
378 ms |
440 KB |
Output is correct |
21 |
Correct |
230 ms |
448 KB |
Output is correct |
22 |
Correct |
194 ms |
444 KB |
Output is correct |
23 |
Correct |
90 ms |
340 KB |
Output is correct |
24 |
Correct |
193 ms |
460 KB |
Output is correct |
25 |
Correct |
71 ms |
444 KB |
Output is correct |
26 |
Correct |
111 ms |
432 KB |
Output is correct |
27 |
Correct |
190 ms |
448 KB |
Output is correct |
28 |
Correct |
193 ms |
444 KB |
Output is correct |
29 |
Correct |
12 ms |
340 KB |
Output is correct |
30 |
Correct |
133 ms |
408 KB |
Output is correct |
31 |
Correct |
126 ms |
400 KB |
Output is correct |
32 |
Correct |
129 ms |
428 KB |
Output is correct |
33 |
Correct |
233 ms |
444 KB |
Output is correct |
34 |
Correct |
183 ms |
432 KB |
Output is correct |
35 |
Correct |
204 ms |
440 KB |
Output is correct |
36 |
Correct |
198 ms |
428 KB |
Output is correct |
37 |
Correct |
197 ms |
460 KB |
Output is correct |
38 |
Correct |
195 ms |
460 KB |
Output is correct |
39 |
Correct |
209 ms |
444 KB |
Output is correct |
40 |
Correct |
396 ms |
2764 KB |
Output is correct |
41 |
Correct |
23 ms |
716 KB |
Output is correct |
42 |
Correct |
207 ms |
2724 KB |
Output is correct |
43 |
Correct |
198 ms |
2292 KB |
Output is correct |
44 |
Correct |
202 ms |
2452 KB |
Output is correct |
45 |
Correct |
437 ms |
11956 KB |
Output is correct |
46 |
Correct |
30 ms |
2260 KB |
Output is correct |
47 |
Correct |
256 ms |
12164 KB |
Output is correct |
48 |
Correct |
242 ms |
10224 KB |
Output is correct |
49 |
Correct |
240 ms |
11000 KB |
Output is correct |