#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
int n, l, q, a[MAXN];
int mq[MAXN], nxt[MAXN] , ans[105][MAXN];
bool idx[MAXN];
vector<int> con;
void solve()
{
cin >> n >> l;
for(int i = 1; i <= n; i++) cin >> a[i];
cin >> q;
for(int i = 1; i <= q; i++)
{
cin >> mq[i];
idx[mq[i]] = 1;
con.push_back(mq[i]);
}
sort(con.begin(),con.end());
con.erase(unique(con.begin(),con.end()),con.end());
int k = con.size() + 1;
for(int i = n; i >= 0; i--)
{
if(idx[i])k--;
nxt[i] = k;
}
vector<int> f(n + 5,0);
for(int len = 1; len <= n; len++)
{
for(int i = 1; i <= n; i++)
{
f[i] = 0;
}
for(int i = 1; i + len <= n; i++)
{
f[i] = f[i - 1] + (a[i] != a[i + len]);
}
for(int i = 1; i + l - 1 <= n; i++)
{
if(i + len + l - 1 > n)break;
int cost = nxt[f[i + l - 1] - f[i - 1]];
ans[cost][i]++;
ans[cost][i + len]++;
}
}
for(int i = 1; i <= con.size(); i++)
{
for(int j = 1; j <= n; j++)
{
ans[i][j] += ans[i - 1][j];
}
}
// truy van
for(int i = 1; i <= q; i++)
{
int x = lower_bound(con.begin(),con.end(),mq[i]) - con.begin() + 1;
for(int j = 1; j <= n - l + 1; j++)
{
cout << ans[x][j] << " \n"[j == n - l + 1];
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
Compilation message
lot.cpp: In function 'void solve()':
lot.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i = 1; i <= con.size(); i++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
372 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
372 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
7 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
528 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
6 ms |
604 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
600 KB |
Output is correct |
2 |
Correct |
118 ms |
672 KB |
Output is correct |
3 |
Correct |
124 ms |
684 KB |
Output is correct |
4 |
Correct |
114 ms |
744 KB |
Output is correct |
5 |
Correct |
67 ms |
604 KB |
Output is correct |
6 |
Correct |
108 ms |
736 KB |
Output is correct |
7 |
Correct |
61 ms |
688 KB |
Output is correct |
8 |
Correct |
78 ms |
712 KB |
Output is correct |
9 |
Correct |
114 ms |
740 KB |
Output is correct |
10 |
Correct |
122 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
76 ms |
696 KB |
Output is correct |
13 |
Correct |
67 ms |
704 KB |
Output is correct |
14 |
Correct |
68 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
600 KB |
Output is correct |
2 |
Correct |
118 ms |
672 KB |
Output is correct |
3 |
Correct |
124 ms |
684 KB |
Output is correct |
4 |
Correct |
114 ms |
744 KB |
Output is correct |
5 |
Correct |
67 ms |
604 KB |
Output is correct |
6 |
Correct |
108 ms |
736 KB |
Output is correct |
7 |
Correct |
61 ms |
688 KB |
Output is correct |
8 |
Correct |
78 ms |
712 KB |
Output is correct |
9 |
Correct |
114 ms |
740 KB |
Output is correct |
10 |
Correct |
122 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
76 ms |
696 KB |
Output is correct |
13 |
Correct |
67 ms |
704 KB |
Output is correct |
14 |
Correct |
68 ms |
692 KB |
Output is correct |
15 |
Correct |
117 ms |
600 KB |
Output is correct |
16 |
Correct |
131 ms |
604 KB |
Output is correct |
17 |
Correct |
118 ms |
600 KB |
Output is correct |
18 |
Correct |
117 ms |
604 KB |
Output is correct |
19 |
Correct |
120 ms |
848 KB |
Output is correct |
20 |
Correct |
120 ms |
760 KB |
Output is correct |
21 |
Correct |
117 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
372 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
7 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
528 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
6 ms |
604 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
19 |
Correct |
126 ms |
600 KB |
Output is correct |
20 |
Correct |
118 ms |
672 KB |
Output is correct |
21 |
Correct |
124 ms |
684 KB |
Output is correct |
22 |
Correct |
114 ms |
744 KB |
Output is correct |
23 |
Correct |
67 ms |
604 KB |
Output is correct |
24 |
Correct |
108 ms |
736 KB |
Output is correct |
25 |
Correct |
61 ms |
688 KB |
Output is correct |
26 |
Correct |
78 ms |
712 KB |
Output is correct |
27 |
Correct |
114 ms |
740 KB |
Output is correct |
28 |
Correct |
122 ms |
860 KB |
Output is correct |
29 |
Correct |
7 ms |
344 KB |
Output is correct |
30 |
Correct |
76 ms |
696 KB |
Output is correct |
31 |
Correct |
67 ms |
704 KB |
Output is correct |
32 |
Correct |
68 ms |
692 KB |
Output is correct |
33 |
Correct |
117 ms |
600 KB |
Output is correct |
34 |
Correct |
131 ms |
604 KB |
Output is correct |
35 |
Correct |
118 ms |
600 KB |
Output is correct |
36 |
Correct |
117 ms |
604 KB |
Output is correct |
37 |
Correct |
120 ms |
848 KB |
Output is correct |
38 |
Correct |
120 ms |
760 KB |
Output is correct |
39 |
Correct |
117 ms |
768 KB |
Output is correct |
40 |
Correct |
132 ms |
1980 KB |
Output is correct |
41 |
Correct |
42 ms |
1360 KB |
Output is correct |
42 |
Correct |
128 ms |
2132 KB |
Output is correct |
43 |
Correct |
121 ms |
1880 KB |
Output is correct |
44 |
Correct |
120 ms |
1876 KB |
Output is correct |
45 |
Correct |
192 ms |
8336 KB |
Output is correct |
46 |
Correct |
47 ms |
4804 KB |
Output is correct |
47 |
Correct |
166 ms |
8276 KB |
Output is correct |
48 |
Correct |
160 ms |
6228 KB |
Output is correct |
49 |
Correct |
155 ms |
6740 KB |
Output is correct |