#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define ld long double
using namespace std;
const int N = 1e4 + 2;
const int INF = 1e9 + 500;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int n, l, q;
vector<int> a(N, 0);
vector<array<int, 2> > qu;
vector<int> mpp;
vector<vector<int> > prec;
void solve() {
cin >> n >> l;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> q;
qu.resize(q);
REP(i, q) {
cin >> qu[i][0];
qu[i][1] = i;
}
sort(all(qu));
mpp.assign(l + 1, 0);
int ind = 0;
for(int i = 0; i <= l; i++) {
if(ind < qu.size() && qu[ind][0] < i) {
ind++;
}
mpp[i] = ind;
} ind++;
// cerr << ind << "\n";
prec.assign(n + 1, vector<int>(ind, 0));
int beg = 1;
for(int s = 2; s <= n - l + 1; s++) {
int sum = 0;
for(int i = 0; i < l; i++) {
if(a[beg + i] != a[s + i]) {
sum++;
}
}
// cerr << "sum:" << sum << endl;
prec[1][mpp[sum]]++;
prec[s][mpp[sum]]++;
for(int i = l; i <= n; i++) {
if(s + i > n) break;
if(a[beg + i] != a[s + i]) {
sum++;
}
if(a[beg + i - l] != a[s + i - l]) {
sum--;
}
prec[beg + i - l + 1][mpp[sum]]++;
prec[s + i - l + 1][mpp[sum]]++;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j < ind; j++) {
prec[i][j] += prec[i][j - 1];
}
}
for(int z = 0; z < q; z++) {
swap(qu[z][0], qu[z][1]);
}
sort(all(qu));
for(auto c : qu) {
for(int i = 1; i <= n - l + 1; i++) {
cout << prec[i][mpp[c[1]]] << " ";
}
cout << "\n";
}
}
signed main() {
fastio();
solve();
}
Compilation message
lot.cpp: In function 'void solve()':
lot.cpp:41:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(ind < qu.size() && qu[ind][0] < i) {
| ~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
500 KB |
Output is correct |
13 |
Correct |
9 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
5 ms |
604 KB |
Output is correct |
16 |
Correct |
9 ms |
604 KB |
Output is correct |
17 |
Correct |
8 ms |
768 KB |
Output is correct |
18 |
Correct |
8 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
349 ms |
1104 KB |
Output is correct |
2 |
Correct |
500 ms |
860 KB |
Output is correct |
3 |
Correct |
202 ms |
1072 KB |
Output is correct |
4 |
Correct |
170 ms |
1116 KB |
Output is correct |
5 |
Correct |
61 ms |
1116 KB |
Output is correct |
6 |
Correct |
155 ms |
1112 KB |
Output is correct |
7 |
Correct |
69 ms |
1168 KB |
Output is correct |
8 |
Correct |
99 ms |
1112 KB |
Output is correct |
9 |
Correct |
161 ms |
1132 KB |
Output is correct |
10 |
Correct |
166 ms |
1116 KB |
Output is correct |
11 |
Correct |
11 ms |
600 KB |
Output is correct |
12 |
Correct |
91 ms |
1068 KB |
Output is correct |
13 |
Correct |
83 ms |
1152 KB |
Output is correct |
14 |
Correct |
82 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
349 ms |
1104 KB |
Output is correct |
2 |
Correct |
500 ms |
860 KB |
Output is correct |
3 |
Correct |
202 ms |
1072 KB |
Output is correct |
4 |
Correct |
170 ms |
1116 KB |
Output is correct |
5 |
Correct |
61 ms |
1116 KB |
Output is correct |
6 |
Correct |
155 ms |
1112 KB |
Output is correct |
7 |
Correct |
69 ms |
1168 KB |
Output is correct |
8 |
Correct |
99 ms |
1112 KB |
Output is correct |
9 |
Correct |
161 ms |
1132 KB |
Output is correct |
10 |
Correct |
166 ms |
1116 KB |
Output is correct |
11 |
Correct |
11 ms |
600 KB |
Output is correct |
12 |
Correct |
91 ms |
1068 KB |
Output is correct |
13 |
Correct |
83 ms |
1152 KB |
Output is correct |
14 |
Correct |
82 ms |
1144 KB |
Output is correct |
15 |
Correct |
229 ms |
1108 KB |
Output is correct |
16 |
Correct |
164 ms |
1116 KB |
Output is correct |
17 |
Correct |
185 ms |
1112 KB |
Output is correct |
18 |
Correct |
168 ms |
1364 KB |
Output is correct |
19 |
Correct |
170 ms |
1132 KB |
Output is correct |
20 |
Correct |
169 ms |
1112 KB |
Output is correct |
21 |
Correct |
171 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
500 KB |
Output is correct |
13 |
Correct |
9 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
5 ms |
604 KB |
Output is correct |
16 |
Correct |
9 ms |
604 KB |
Output is correct |
17 |
Correct |
8 ms |
768 KB |
Output is correct |
18 |
Correct |
8 ms |
604 KB |
Output is correct |
19 |
Correct |
349 ms |
1104 KB |
Output is correct |
20 |
Correct |
500 ms |
860 KB |
Output is correct |
21 |
Correct |
202 ms |
1072 KB |
Output is correct |
22 |
Correct |
170 ms |
1116 KB |
Output is correct |
23 |
Correct |
61 ms |
1116 KB |
Output is correct |
24 |
Correct |
155 ms |
1112 KB |
Output is correct |
25 |
Correct |
69 ms |
1168 KB |
Output is correct |
26 |
Correct |
99 ms |
1112 KB |
Output is correct |
27 |
Correct |
161 ms |
1132 KB |
Output is correct |
28 |
Correct |
166 ms |
1116 KB |
Output is correct |
29 |
Correct |
11 ms |
600 KB |
Output is correct |
30 |
Correct |
91 ms |
1068 KB |
Output is correct |
31 |
Correct |
83 ms |
1152 KB |
Output is correct |
32 |
Correct |
82 ms |
1144 KB |
Output is correct |
33 |
Correct |
229 ms |
1108 KB |
Output is correct |
34 |
Correct |
164 ms |
1116 KB |
Output is correct |
35 |
Correct |
185 ms |
1112 KB |
Output is correct |
36 |
Correct |
168 ms |
1364 KB |
Output is correct |
37 |
Correct |
170 ms |
1132 KB |
Output is correct |
38 |
Correct |
169 ms |
1112 KB |
Output is correct |
39 |
Correct |
171 ms |
1108 KB |
Output is correct |
40 |
Correct |
557 ms |
2448 KB |
Output is correct |
41 |
Correct |
11 ms |
1880 KB |
Output is correct |
42 |
Correct |
217 ms |
2464 KB |
Output is correct |
43 |
Correct |
202 ms |
2128 KB |
Output is correct |
44 |
Correct |
196 ms |
2132 KB |
Output is correct |
45 |
Correct |
629 ms |
8416 KB |
Output is correct |
46 |
Correct |
17 ms |
5212 KB |
Output is correct |
47 |
Correct |
280 ms |
8788 KB |
Output is correct |
48 |
Correct |
255 ms |
6996 KB |
Output is correct |
49 |
Correct |
289 ms |
7452 KB |
Output is correct |