#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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 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 |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 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 |
432 KB |
Output is correct |
13 |
Correct |
11 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
724 KB |
Output is correct |
15 |
Correct |
8 ms |
580 KB |
Output is correct |
16 |
Correct |
10 ms |
848 KB |
Output is correct |
17 |
Correct |
10 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
420 KB |
Output is correct |
2 |
Correct |
370 ms |
444 KB |
Output is correct |
3 |
Correct |
226 ms |
460 KB |
Output is correct |
4 |
Correct |
195 ms |
520 KB |
Output is correct |
5 |
Correct |
97 ms |
484 KB |
Output is correct |
6 |
Correct |
189 ms |
504 KB |
Output is correct |
7 |
Correct |
67 ms |
556 KB |
Output is correct |
8 |
Correct |
101 ms |
508 KB |
Output is correct |
9 |
Correct |
191 ms |
524 KB |
Output is correct |
10 |
Correct |
199 ms |
512 KB |
Output is correct |
11 |
Correct |
13 ms |
340 KB |
Output is correct |
12 |
Correct |
132 ms |
476 KB |
Output is correct |
13 |
Correct |
127 ms |
468 KB |
Output is correct |
14 |
Correct |
119 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
420 KB |
Output is correct |
2 |
Correct |
370 ms |
444 KB |
Output is correct |
3 |
Correct |
226 ms |
460 KB |
Output is correct |
4 |
Correct |
195 ms |
520 KB |
Output is correct |
5 |
Correct |
97 ms |
484 KB |
Output is correct |
6 |
Correct |
189 ms |
504 KB |
Output is correct |
7 |
Correct |
67 ms |
556 KB |
Output is correct |
8 |
Correct |
101 ms |
508 KB |
Output is correct |
9 |
Correct |
191 ms |
524 KB |
Output is correct |
10 |
Correct |
199 ms |
512 KB |
Output is correct |
11 |
Correct |
13 ms |
340 KB |
Output is correct |
12 |
Correct |
132 ms |
476 KB |
Output is correct |
13 |
Correct |
127 ms |
468 KB |
Output is correct |
14 |
Correct |
119 ms |
468 KB |
Output is correct |
15 |
Correct |
235 ms |
444 KB |
Output is correct |
16 |
Correct |
189 ms |
468 KB |
Output is correct |
17 |
Correct |
203 ms |
520 KB |
Output is correct |
18 |
Correct |
197 ms |
468 KB |
Output is correct |
19 |
Correct |
195 ms |
520 KB |
Output is correct |
20 |
Correct |
199 ms |
468 KB |
Output is correct |
21 |
Correct |
199 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 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 |
432 KB |
Output is correct |
13 |
Correct |
11 ms |
468 KB |
Output is correct |
14 |
Correct |
9 ms |
724 KB |
Output is correct |
15 |
Correct |
8 ms |
580 KB |
Output is correct |
16 |
Correct |
10 ms |
848 KB |
Output is correct |
17 |
Correct |
10 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
724 KB |
Output is correct |
19 |
Correct |
424 ms |
420 KB |
Output is correct |
20 |
Correct |
370 ms |
444 KB |
Output is correct |
21 |
Correct |
226 ms |
460 KB |
Output is correct |
22 |
Correct |
195 ms |
520 KB |
Output is correct |
23 |
Correct |
97 ms |
484 KB |
Output is correct |
24 |
Correct |
189 ms |
504 KB |
Output is correct |
25 |
Correct |
67 ms |
556 KB |
Output is correct |
26 |
Correct |
101 ms |
508 KB |
Output is correct |
27 |
Correct |
191 ms |
524 KB |
Output is correct |
28 |
Correct |
199 ms |
512 KB |
Output is correct |
29 |
Correct |
13 ms |
340 KB |
Output is correct |
30 |
Correct |
132 ms |
476 KB |
Output is correct |
31 |
Correct |
127 ms |
468 KB |
Output is correct |
32 |
Correct |
119 ms |
468 KB |
Output is correct |
33 |
Correct |
235 ms |
444 KB |
Output is correct |
34 |
Correct |
189 ms |
468 KB |
Output is correct |
35 |
Correct |
203 ms |
520 KB |
Output is correct |
36 |
Correct |
197 ms |
468 KB |
Output is correct |
37 |
Correct |
195 ms |
520 KB |
Output is correct |
38 |
Correct |
199 ms |
468 KB |
Output is correct |
39 |
Correct |
199 ms |
588 KB |
Output is correct |
40 |
Correct |
393 ms |
2672 KB |
Output is correct |
41 |
Correct |
26 ms |
844 KB |
Output is correct |
42 |
Correct |
209 ms |
2732 KB |
Output is correct |
43 |
Correct |
211 ms |
2412 KB |
Output is correct |
44 |
Correct |
203 ms |
2444 KB |
Output is correct |
45 |
Correct |
454 ms |
11940 KB |
Output is correct |
46 |
Correct |
30 ms |
2252 KB |
Output is correct |
47 |
Correct |
266 ms |
12108 KB |
Output is correct |
48 |
Correct |
248 ms |
10316 KB |
Output is correct |
49 |
Correct |
247 ms |
10952 KB |
Output is correct |