#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define int long long
const ll INF = 1e18;
const int maxn = 1e4 + 5;
const int A = 937521937;
const int B = 998244353;
int n, l;
int a[maxn];
int nxt[maxn];
vector<int> val;
signed main(void){
fastio;
cin>>n>>l;
for(int i = 0; i < n; i++) cin>>a[i];
int q;
cin>>q;
vector<int> qry(q);
for(int i = 0; i < q; i++){
cin>>qry[i];
val.pb(qry[i]);
}
sort(val.begin(), val.end());
val.erase(unique(val.begin(), val.end()), val.end());
int cur = 0;
for(int i = 0; i <= n; i++){
nxt[i] = cur;
if(i == val[cur]) cur++;
if(cur == val.size()){
i++;
while(i <= n) nxt[i] = INF, i++;
}
}
vector<vector<int>> d(n, vector<int>(val.size()));
for(int dist = 1; dist < n; dist++){
int cur = 0;
for(int i = 0; i + dist + l - 1 < n; i++){
if(i == 0){
for(int k = 0; k < l; k++) if(a[i + k] != a[i + dist + k]) cur++;
}
else{
cur = cur - (a[i - 1] != a[i + dist - 1]) + (a[i + l - 1] != a[i + dist + l - 1]);
}
if(nxt[cur] == INF) continue;
d[i][nxt[cur]] ++, d[i + dist][nxt[cur]] ++;
}
}
for(int i = 0; i < n - l + 1; i++) for(int j = 1; j < val.size(); j++) d[i][j] += d[i][j - 1];
for(int i = 0; i < q; i++){
for(int j = 0; j < n - l + 1; j++) cout<<d[j][nxt[qry[i]]]<<" ";
cout<<"\n";
}
}
Compilation message
lot.cpp: In function 'int main()':
lot.cpp:37:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(cur == val.size()){
| ~~~~^~~~~~~~~~~~~
lot.cpp:56:54: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < n - l + 1; i++) for(int j = 1; j < val.size(); j++) d[i][j] += d[i][j - 1];
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
11 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
876 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
7 ms |
1112 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
4 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
1180 KB |
Output is correct |
2 |
Correct |
90 ms |
1116 KB |
Output is correct |
3 |
Correct |
79 ms |
1180 KB |
Output is correct |
4 |
Correct |
75 ms |
1260 KB |
Output is correct |
5 |
Correct |
38 ms |
1116 KB |
Output is correct |
6 |
Correct |
69 ms |
1116 KB |
Output is correct |
7 |
Correct |
78 ms |
1248 KB |
Output is correct |
8 |
Correct |
152 ms |
1244 KB |
Output is correct |
9 |
Correct |
86 ms |
1240 KB |
Output is correct |
10 |
Correct |
79 ms |
1112 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
43 ms |
1116 KB |
Output is correct |
13 |
Correct |
40 ms |
1108 KB |
Output is correct |
14 |
Correct |
40 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
1180 KB |
Output is correct |
2 |
Correct |
90 ms |
1116 KB |
Output is correct |
3 |
Correct |
79 ms |
1180 KB |
Output is correct |
4 |
Correct |
75 ms |
1260 KB |
Output is correct |
5 |
Correct |
38 ms |
1116 KB |
Output is correct |
6 |
Correct |
69 ms |
1116 KB |
Output is correct |
7 |
Correct |
78 ms |
1248 KB |
Output is correct |
8 |
Correct |
152 ms |
1244 KB |
Output is correct |
9 |
Correct |
86 ms |
1240 KB |
Output is correct |
10 |
Correct |
79 ms |
1112 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
43 ms |
1116 KB |
Output is correct |
13 |
Correct |
40 ms |
1108 KB |
Output is correct |
14 |
Correct |
40 ms |
1116 KB |
Output is correct |
15 |
Correct |
158 ms |
1172 KB |
Output is correct |
16 |
Correct |
67 ms |
1116 KB |
Output is correct |
17 |
Correct |
85 ms |
1112 KB |
Output is correct |
18 |
Correct |
74 ms |
1252 KB |
Output is correct |
19 |
Correct |
77 ms |
1116 KB |
Output is correct |
20 |
Correct |
75 ms |
1248 KB |
Output is correct |
21 |
Correct |
75 ms |
1264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
11 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
876 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
7 ms |
1112 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
4 ms |
860 KB |
Output is correct |
19 |
Correct |
172 ms |
1180 KB |
Output is correct |
20 |
Correct |
90 ms |
1116 KB |
Output is correct |
21 |
Correct |
79 ms |
1180 KB |
Output is correct |
22 |
Correct |
75 ms |
1260 KB |
Output is correct |
23 |
Correct |
38 ms |
1116 KB |
Output is correct |
24 |
Correct |
69 ms |
1116 KB |
Output is correct |
25 |
Correct |
78 ms |
1248 KB |
Output is correct |
26 |
Correct |
152 ms |
1244 KB |
Output is correct |
27 |
Correct |
86 ms |
1240 KB |
Output is correct |
28 |
Correct |
79 ms |
1112 KB |
Output is correct |
29 |
Correct |
6 ms |
600 KB |
Output is correct |
30 |
Correct |
43 ms |
1116 KB |
Output is correct |
31 |
Correct |
40 ms |
1108 KB |
Output is correct |
32 |
Correct |
40 ms |
1116 KB |
Output is correct |
33 |
Correct |
158 ms |
1172 KB |
Output is correct |
34 |
Correct |
67 ms |
1116 KB |
Output is correct |
35 |
Correct |
85 ms |
1112 KB |
Output is correct |
36 |
Correct |
74 ms |
1252 KB |
Output is correct |
37 |
Correct |
77 ms |
1116 KB |
Output is correct |
38 |
Correct |
75 ms |
1248 KB |
Output is correct |
39 |
Correct |
75 ms |
1264 KB |
Output is correct |
40 |
Correct |
279 ms |
3352 KB |
Output is correct |
41 |
Correct |
8 ms |
2652 KB |
Output is correct |
42 |
Correct |
117 ms |
3156 KB |
Output is correct |
43 |
Correct |
81 ms |
2916 KB |
Output is correct |
44 |
Correct |
80 ms |
3020 KB |
Output is correct |
45 |
Correct |
372 ms |
12680 KB |
Output is correct |
46 |
Correct |
15 ms |
9200 KB |
Output is correct |
47 |
Correct |
389 ms |
12704 KB |
Output is correct |
48 |
Correct |
119 ms |
10036 KB |
Output is correct |
49 |
Correct |
121 ms |
10576 KB |
Output is correct |