#include<bits/stdc++.h>
using namespace std;
int n,lun,cntq;
int a[10005];
int cntd[10005];
vector<pair<int,int>> qrys;
int unde[105];
int rez[105][10005];
int ultima[10005];
void solve()
{
for(int i=0;i<=n;i++)
{
ultima[i]=cntq;
for(int j=cntq-1;j>=0;j--)
if(i <= qrys[j].first && (j==0 || i > qrys[j-1].first))
ultima[i] = j;
}
for(int dif=-n;dif<=n;dif++)
{
if(dif==0)
continue;
for(int i=max(1,-dif+1 - 1);i<=n;i++)
{
cntd[i] = cntd[i-1];
if(i+dif>0 && i+dif<=n && a[i]!=a[i+dif])
cntd[i]++;
}
for(int i=max(1,-dif+1);i<=min(n-lun+1,n-dif-lun+1);i++)
{
rez[ultima[cntd[i+lun-1] - cntd[i-1]]][i]++;
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<cntq;j++)
rez[j][i] += rez[j-1][i];
}
signed main()
{
cin>>n>>lun;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
cin>>cntq;
qrys.resize(cntq);
for(int i=0;i<cntq;i++)
{
cin>>qrys[i].first;
qrys[i].second = i;
}
sort(qrys.begin(),qrys.end());
for(int i=0;i<cntq;i++)
unde[qrys[i].second] = i;
solve();
for(int i=0;i<cntq;i++)
{
for(int j=1;j+lun-1<=n;j++)
cout<<rez[unde[i]][j]<<" ";
cout<<"\n";
}
return 0;
}
/**
cntd[dif][poz] = numarul de mismatches a[x] != a[x+dif], unde x = 1..poz
cntc[dif][i] = cntd[dif][i+lun-1] - cntd[dif][i-1] = distanta de la intervalul i..i+lun-1 la i+dif..i+dif+lun-1 este
distanta de la intervalul i..i+lun-1 la i+dif..i+dif+lun-1 este:
cntd[dif][i+lun-1] - cntd[dif][i-1]
ne fixam dif
vedem cum influenteaza dif cele q queryuri
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2804 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2804 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
20 ms |
2576 KB |
Output is correct |
14 |
Correct |
19 ms |
2528 KB |
Output is correct |
15 |
Correct |
18 ms |
2528 KB |
Output is correct |
16 |
Correct |
21 ms |
2652 KB |
Output is correct |
17 |
Correct |
23 ms |
2392 KB |
Output is correct |
18 |
Correct |
20 ms |
2524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
715 ms |
828 KB |
Output is correct |
2 |
Correct |
728 ms |
544 KB |
Output is correct |
3 |
Correct |
476 ms |
560 KB |
Output is correct |
4 |
Correct |
476 ms |
608 KB |
Output is correct |
5 |
Correct |
373 ms |
564 KB |
Output is correct |
6 |
Correct |
471 ms |
800 KB |
Output is correct |
7 |
Correct |
353 ms |
540 KB |
Output is correct |
8 |
Correct |
385 ms |
812 KB |
Output is correct |
9 |
Correct |
470 ms |
596 KB |
Output is correct |
10 |
Correct |
493 ms |
548 KB |
Output is correct |
11 |
Correct |
36 ms |
504 KB |
Output is correct |
12 |
Correct |
353 ms |
600 KB |
Output is correct |
13 |
Correct |
394 ms |
348 KB |
Output is correct |
14 |
Correct |
398 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
715 ms |
828 KB |
Output is correct |
2 |
Correct |
728 ms |
544 KB |
Output is correct |
3 |
Correct |
476 ms |
560 KB |
Output is correct |
4 |
Correct |
476 ms |
608 KB |
Output is correct |
5 |
Correct |
373 ms |
564 KB |
Output is correct |
6 |
Correct |
471 ms |
800 KB |
Output is correct |
7 |
Correct |
353 ms |
540 KB |
Output is correct |
8 |
Correct |
385 ms |
812 KB |
Output is correct |
9 |
Correct |
470 ms |
596 KB |
Output is correct |
10 |
Correct |
493 ms |
548 KB |
Output is correct |
11 |
Correct |
36 ms |
504 KB |
Output is correct |
12 |
Correct |
353 ms |
600 KB |
Output is correct |
13 |
Correct |
394 ms |
348 KB |
Output is correct |
14 |
Correct |
398 ms |
344 KB |
Output is correct |
15 |
Correct |
465 ms |
612 KB |
Output is correct |
16 |
Correct |
462 ms |
592 KB |
Output is correct |
17 |
Correct |
497 ms |
548 KB |
Output is correct |
18 |
Correct |
482 ms |
600 KB |
Output is correct |
19 |
Correct |
477 ms |
596 KB |
Output is correct |
20 |
Correct |
483 ms |
608 KB |
Output is correct |
21 |
Correct |
479 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2804 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
20 ms |
2576 KB |
Output is correct |
14 |
Correct |
19 ms |
2528 KB |
Output is correct |
15 |
Correct |
18 ms |
2528 KB |
Output is correct |
16 |
Correct |
21 ms |
2652 KB |
Output is correct |
17 |
Correct |
23 ms |
2392 KB |
Output is correct |
18 |
Correct |
20 ms |
2524 KB |
Output is correct |
19 |
Correct |
715 ms |
828 KB |
Output is correct |
20 |
Correct |
728 ms |
544 KB |
Output is correct |
21 |
Correct |
476 ms |
560 KB |
Output is correct |
22 |
Correct |
476 ms |
608 KB |
Output is correct |
23 |
Correct |
373 ms |
564 KB |
Output is correct |
24 |
Correct |
471 ms |
800 KB |
Output is correct |
25 |
Correct |
353 ms |
540 KB |
Output is correct |
26 |
Correct |
385 ms |
812 KB |
Output is correct |
27 |
Correct |
470 ms |
596 KB |
Output is correct |
28 |
Correct |
493 ms |
548 KB |
Output is correct |
29 |
Correct |
36 ms |
504 KB |
Output is correct |
30 |
Correct |
353 ms |
600 KB |
Output is correct |
31 |
Correct |
394 ms |
348 KB |
Output is correct |
32 |
Correct |
398 ms |
344 KB |
Output is correct |
33 |
Correct |
465 ms |
612 KB |
Output is correct |
34 |
Correct |
462 ms |
592 KB |
Output is correct |
35 |
Correct |
497 ms |
548 KB |
Output is correct |
36 |
Correct |
482 ms |
600 KB |
Output is correct |
37 |
Correct |
477 ms |
596 KB |
Output is correct |
38 |
Correct |
483 ms |
608 KB |
Output is correct |
39 |
Correct |
479 ms |
596 KB |
Output is correct |
40 |
Correct |
745 ms |
3360 KB |
Output is correct |
41 |
Correct |
363 ms |
2588 KB |
Output is correct |
42 |
Correct |
483 ms |
3408 KB |
Output is correct |
43 |
Correct |
487 ms |
3384 KB |
Output is correct |
44 |
Correct |
481 ms |
3212 KB |
Output is correct |
45 |
Correct |
806 ms |
8128 KB |
Output is correct |
46 |
Correct |
369 ms |
4728 KB |
Output is correct |
47 |
Correct |
535 ms |
8532 KB |
Output is correct |
48 |
Correct |
524 ms |
6664 KB |
Output is correct |
49 |
Correct |
520 ms |
7256 KB |
Output is correct |