#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int N=1e4+1;
int a[N],l,n,cpy[N];
bool posa=0;
map<int,int> ans[N];
vector<vector<int>> hp;
void level_up()
{
if(posa)
return;
for(int i=0;i<(n-l+1);i++)
{
for(int j=i+1;j<(n-l+1);j++)
{
int c=0;
for(int dl=0;dl<l;dl++)
{
c+=(hp[i][dl]!=hp[j][dl]);
}
ans[i][c]++;
ans[j][c]++;
}
}
posa=1;
}
int main()
{
cin>>n>>l;
for(int i=0;i<n;i++)
{
cin>>a[i];
cpy[i]=a[i];
}
sort(cpy,cpy+n);
for(int i=0;i<n;i++)
a[i]=lower_bound(cpy,cpy+n,a[i])-cpy;
int q;
cin>>q;
if(q==1)
{
int k;
cin>>k;
if(k==0)
{
map<long long,int> cnt;
for(int i=0;(i+l-1)<n;i++)
{
long long hash=0,base=717,mod=1e9+9;
for(int j=0;j<l;j++)
{
hash=(hash*base)%mod;
hash+=a[j+i];
hash%=mod;
}
cnt[hash]++;
}
for(int i=0;(i+l-1)<n;i++)
{
long long hash=0,base=717,mod=1e9+9;
for(int j=0;j<l;j++)
{
hash=(hash*base)%mod;
hash+=a[j+i];
hash%=mod;
}
cout<<cnt[hash]-1<<' ';
}
cout<<'\n';
}
else
{
for(int i=0;(i+l-1)<n;i++)
{
vector<int> ap;
for(int j=0;j<l;j++)
ap.push_back(a[i+j]);
hp.push_back(ap);
}
vector<int> ans(n);
for(int i=0;(i+l-1)<n;i++)
{
for(int j=i+1;(j+l-1)<n;j++)
{
int dif=0;
bool pos=1;
for(int lp=0;lp<l;lp++)
{
if((l-lp+dif)<=k)
break;
dif+=(hp[i][lp]!=hp[j][lp]);
if(dif>k)
{
pos=0;
break;
}
}
ans[i]+=pos;
ans[j]+=pos;
}
}
for(int i=0;(i+l-1)<n;i++)
cout<<ans[i]<<' ';
cout<<endl;
}
}
else
{
for(int i=0;(i+l-1)<n;i++)
{
vector<int> ap;
for(int j=0;j<l;j++)
ap.push_back(a[i+j]);
hp.push_back(ap);
}
level_up();
while(q--)
{
int k;
cin>>k;
for(int i=0;(i+l-1)<n;i++)
{
int sp=0;
for(int lp=0;lp<=k;lp++)
if(ans[i].find(lp)!=ans[i].end())
sp+=ans[i][lp];
cout<<sp<<' ';
}
cout<<'\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
856 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
856 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
31 ms |
1368 KB |
Output is correct |
14 |
Correct |
457 ms |
4440 KB |
Output is correct |
15 |
Correct |
459 ms |
4944 KB |
Output is correct |
16 |
Correct |
327 ms |
5180 KB |
Output is correct |
17 |
Correct |
359 ms |
3408 KB |
Output is correct |
18 |
Correct |
357 ms |
3700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
38 ms |
1232 KB |
Output is correct |
5 |
Correct |
403 ms |
1356 KB |
Output is correct |
6 |
Correct |
112 ms |
1508 KB |
Output is correct |
7 |
Correct |
404 ms |
856 KB |
Output is correct |
8 |
Correct |
341 ms |
1072 KB |
Output is correct |
9 |
Correct |
57 ms |
1104 KB |
Output is correct |
10 |
Correct |
37 ms |
1116 KB |
Output is correct |
11 |
Correct |
34 ms |
1020 KB |
Output is correct |
12 |
Correct |
233 ms |
1360 KB |
Output is correct |
13 |
Correct |
391 ms |
1716 KB |
Output is correct |
14 |
Correct |
393 ms |
1440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
38 ms |
1232 KB |
Output is correct |
5 |
Correct |
403 ms |
1356 KB |
Output is correct |
6 |
Correct |
112 ms |
1508 KB |
Output is correct |
7 |
Correct |
404 ms |
856 KB |
Output is correct |
8 |
Correct |
341 ms |
1072 KB |
Output is correct |
9 |
Correct |
57 ms |
1104 KB |
Output is correct |
10 |
Correct |
37 ms |
1116 KB |
Output is correct |
11 |
Correct |
34 ms |
1020 KB |
Output is correct |
12 |
Correct |
233 ms |
1360 KB |
Output is correct |
13 |
Correct |
391 ms |
1716 KB |
Output is correct |
14 |
Correct |
393 ms |
1440 KB |
Output is correct |
15 |
Execution timed out |
3013 ms |
13972 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
856 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
31 ms |
1368 KB |
Output is correct |
14 |
Correct |
457 ms |
4440 KB |
Output is correct |
15 |
Correct |
459 ms |
4944 KB |
Output is correct |
16 |
Correct |
327 ms |
5180 KB |
Output is correct |
17 |
Correct |
359 ms |
3408 KB |
Output is correct |
18 |
Correct |
357 ms |
3700 KB |
Output is correct |
19 |
Correct |
3 ms |
856 KB |
Output is correct |
20 |
Correct |
4 ms |
856 KB |
Output is correct |
21 |
Correct |
4 ms |
856 KB |
Output is correct |
22 |
Correct |
38 ms |
1232 KB |
Output is correct |
23 |
Correct |
403 ms |
1356 KB |
Output is correct |
24 |
Correct |
112 ms |
1508 KB |
Output is correct |
25 |
Correct |
404 ms |
856 KB |
Output is correct |
26 |
Correct |
341 ms |
1072 KB |
Output is correct |
27 |
Correct |
57 ms |
1104 KB |
Output is correct |
28 |
Correct |
37 ms |
1116 KB |
Output is correct |
29 |
Correct |
34 ms |
1020 KB |
Output is correct |
30 |
Correct |
233 ms |
1360 KB |
Output is correct |
31 |
Correct |
391 ms |
1716 KB |
Output is correct |
32 |
Correct |
393 ms |
1440 KB |
Output is correct |
33 |
Execution timed out |
3013 ms |
13972 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |