#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int n,v[10005],l,q;
int sol[105][10005];
int cnt[10005];
struct date
{
int poz,val;
} query[105];
bool comp(date a, date b)
{
return a.val>b.val;
}
int where[10005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>l;
for(int i=1;i<=n;i++)
cin>>v[i];
cin>>q;
for(int i=1;i<=q;i++)
{
query[i].poz=i;
cin>>query[i].val;
query[i].val=l-query[i].val;
}
sort(query+1,query+q+1,comp);
for(int i=0;i<=l;i++)
{
where[i]=q+1;
for(int j=1;j<=q;j++)
if(i>=query[j].val)
{
where[i]=j;
break;
}
}
for(int dist=1;dist<=n;dist++)
{
for(int i=1;i<=n;i++)
cnt[i]=0;
for(int i=1;i<=n;i++)
{
int j=i+dist;
if(j>n)
break;
if(v[i]==v[j])
{
int lft=max(1,i-l+1);
int rgt=j;
if(j+l-1>n)
rgt=n-l+1;
rgt-=dist;
if(lft<=rgt)
{
cnt[lft]++;
cnt[rgt+1]--;
}
}
}
for(int i=1;i<=n;i++)
cnt[i]+=cnt[i-1];
for(int i=1;i+l-1<=n;i++)
{
int j=i+dist;
if(j+l-1>n)
break;
int val=cnt[i];
int poz=where[val];
sol[poz][i]++;
sol[poz][j]++;
}
}
for(int poz=1;poz<=q;poz++)
for(int i=1;i+l-1<=n;i++)
sol[poz][i]+=sol[poz-1][i];
for(int i=1;i<=q;i++)
{
int who=0;
for(int j=1;j<=q;j++)
if(query[j].poz==i)
{
who=j;
break;
}
for(int j=1;j+l-1<=n;j++)
cout<<sol[who][j]<<' ';
cout<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
27 ms |
464 KB |
Output is correct |
14 |
Correct |
19 ms |
508 KB |
Output is correct |
15 |
Correct |
18 ms |
460 KB |
Output is correct |
16 |
Correct |
24 ms |
584 KB |
Output is correct |
17 |
Correct |
22 ms |
552 KB |
Output is correct |
18 |
Correct |
22 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
500 KB |
Output is correct |
2 |
Correct |
832 ms |
504 KB |
Output is correct |
3 |
Correct |
618 ms |
504 KB |
Output is correct |
4 |
Correct |
559 ms |
596 KB |
Output is correct |
5 |
Correct |
381 ms |
588 KB |
Output is correct |
6 |
Correct |
528 ms |
568 KB |
Output is correct |
7 |
Correct |
413 ms |
540 KB |
Output is correct |
8 |
Correct |
489 ms |
532 KB |
Output is correct |
9 |
Correct |
549 ms |
588 KB |
Output is correct |
10 |
Correct |
553 ms |
596 KB |
Output is correct |
11 |
Correct |
43 ms |
376 KB |
Output is correct |
12 |
Correct |
379 ms |
516 KB |
Output is correct |
13 |
Correct |
386 ms |
552 KB |
Output is correct |
14 |
Correct |
402 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
500 KB |
Output is correct |
2 |
Correct |
832 ms |
504 KB |
Output is correct |
3 |
Correct |
618 ms |
504 KB |
Output is correct |
4 |
Correct |
559 ms |
596 KB |
Output is correct |
5 |
Correct |
381 ms |
588 KB |
Output is correct |
6 |
Correct |
528 ms |
568 KB |
Output is correct |
7 |
Correct |
413 ms |
540 KB |
Output is correct |
8 |
Correct |
489 ms |
532 KB |
Output is correct |
9 |
Correct |
549 ms |
588 KB |
Output is correct |
10 |
Correct |
553 ms |
596 KB |
Output is correct |
11 |
Correct |
43 ms |
376 KB |
Output is correct |
12 |
Correct |
379 ms |
516 KB |
Output is correct |
13 |
Correct |
386 ms |
552 KB |
Output is correct |
14 |
Correct |
402 ms |
468 KB |
Output is correct |
15 |
Correct |
605 ms |
508 KB |
Output is correct |
16 |
Correct |
507 ms |
580 KB |
Output is correct |
17 |
Correct |
573 ms |
596 KB |
Output is correct |
18 |
Correct |
559 ms |
588 KB |
Output is correct |
19 |
Correct |
561 ms |
580 KB |
Output is correct |
20 |
Correct |
547 ms |
596 KB |
Output is correct |
21 |
Correct |
546 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
27 ms |
464 KB |
Output is correct |
14 |
Correct |
19 ms |
508 KB |
Output is correct |
15 |
Correct |
18 ms |
460 KB |
Output is correct |
16 |
Correct |
24 ms |
584 KB |
Output is correct |
17 |
Correct |
22 ms |
552 KB |
Output is correct |
18 |
Correct |
22 ms |
588 KB |
Output is correct |
19 |
Correct |
831 ms |
500 KB |
Output is correct |
20 |
Correct |
832 ms |
504 KB |
Output is correct |
21 |
Correct |
618 ms |
504 KB |
Output is correct |
22 |
Correct |
559 ms |
596 KB |
Output is correct |
23 |
Correct |
381 ms |
588 KB |
Output is correct |
24 |
Correct |
528 ms |
568 KB |
Output is correct |
25 |
Correct |
413 ms |
540 KB |
Output is correct |
26 |
Correct |
489 ms |
532 KB |
Output is correct |
27 |
Correct |
549 ms |
588 KB |
Output is correct |
28 |
Correct |
553 ms |
596 KB |
Output is correct |
29 |
Correct |
43 ms |
376 KB |
Output is correct |
30 |
Correct |
379 ms |
516 KB |
Output is correct |
31 |
Correct |
386 ms |
552 KB |
Output is correct |
32 |
Correct |
402 ms |
468 KB |
Output is correct |
33 |
Correct |
605 ms |
508 KB |
Output is correct |
34 |
Correct |
507 ms |
580 KB |
Output is correct |
35 |
Correct |
573 ms |
596 KB |
Output is correct |
36 |
Correct |
559 ms |
588 KB |
Output is correct |
37 |
Correct |
561 ms |
580 KB |
Output is correct |
38 |
Correct |
547 ms |
596 KB |
Output is correct |
39 |
Correct |
546 ms |
596 KB |
Output is correct |
40 |
Correct |
835 ms |
1996 KB |
Output is correct |
41 |
Correct |
279 ms |
680 KB |
Output is correct |
42 |
Correct |
580 ms |
2064 KB |
Output is correct |
43 |
Correct |
560 ms |
1740 KB |
Output is correct |
44 |
Correct |
536 ms |
1728 KB |
Output is correct |
45 |
Correct |
901 ms |
8240 KB |
Output is correct |
46 |
Correct |
287 ms |
1572 KB |
Output is correct |
47 |
Correct |
626 ms |
8304 KB |
Output is correct |
48 |
Correct |
596 ms |
6568 KB |
Output is correct |
49 |
Correct |
596 ms |
7116 KB |
Output is correct |