#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MOD = 1e9 + 7;
const int MAXN = 1e6+1;
int main(){
int n, l;
cin >> n >> l;
vector<int> v(n,0);
for(int i = 0; i < n; i++)
cin >> v[i];
int q;
cin >> q;
vector<pii> queries(q);
vector<int> order(q);
for(int i = 0; i < q; i++){
cin >> queries[i].ff;
queries[i].ss = i;
}
sort(queries.begin(),queries.end(),[&](pii& a, pii& b){
if(a.ff == b.ff)
return a.ss < b.ss;
return a.ff < b.ff;
});
for(int i = 0; i < q; i++){
order[queries[i].ss] = i;
}
vector<vector<int>> resp(q,vector<int>(n,0));
function<void(int,int,int)> update = [&](int a, int b, int val){
int ini = 0, fim = q;
while(ini!=fim){
int m = (ini+fim)>>1;
if(queries[m].ff >= val)
fim = m;
else ini = m+1;
}
if(ini!=q){
resp[ini][a]++;
resp[ini][b]++;
}
};
vector<int> diff(n-l+1,0);//vamos calcular a diferença do atual para todos os outros intervalos
//base: caso do intervalo [0,l-1]
for(int i = 0; i < l; i++){ // para cada membro do intervalo
for(int j = i+1; j-i < n-l+1 ; j++){ // para cada um dos outros indices
diff[j-i]+= v[i]!=v[j]; //adicionamos ao intervalo que corresponde àquela diferença
}
}
for(int i = 1; i <= n-l; i++){ // atualizando resposta para o caso base
update(0,i,diff[i]);
}
for(int i = 1; i < n-l; i++){ // recorrência
for(int j = n-l; j > i; j--){ // para cada intervalo após o atual
diff[j] = diff[j-1] - (v[j-1]!=v[i-1]) + (v[i+l-1]!=v[j+l-1]);
// [ ( ] ) [ ( ] ) quando passamos para o próximo intervalo podemos ver que toda a parte do meio já era comparada anteriormente, então só temos que mudar as bordas
update(i,j,diff[j]);
}
}
for(int i = 1; i < q; i++){
for(int j = 0; j < n-l+1; j++){
resp[i][j]+=resp[i-1][j];
}
}
for(int i = 0; i < q; i++){
for(int j = 0; j < n-l+1; j++){
cout << resp[order[i]][j] << ' ';
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
216 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
216 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
44 ms |
352 KB |
Output is correct |
14 |
Correct |
21 ms |
476 KB |
Output is correct |
15 |
Correct |
17 ms |
408 KB |
Output is correct |
16 |
Correct |
32 ms |
464 KB |
Output is correct |
17 |
Correct |
27 ms |
460 KB |
Output is correct |
18 |
Correct |
27 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
428 KB |
Output is correct |
2 |
Correct |
441 ms |
460 KB |
Output is correct |
3 |
Correct |
435 ms |
460 KB |
Output is correct |
4 |
Correct |
425 ms |
592 KB |
Output is correct |
5 |
Correct |
140 ms |
496 KB |
Output is correct |
6 |
Correct |
375 ms |
484 KB |
Output is correct |
7 |
Correct |
229 ms |
484 KB |
Output is correct |
8 |
Correct |
416 ms |
460 KB |
Output is correct |
9 |
Correct |
457 ms |
480 KB |
Output is correct |
10 |
Correct |
433 ms |
492 KB |
Output is correct |
11 |
Correct |
20 ms |
332 KB |
Output is correct |
12 |
Correct |
226 ms |
460 KB |
Output is correct |
13 |
Correct |
179 ms |
436 KB |
Output is correct |
14 |
Correct |
180 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
428 KB |
Output is correct |
2 |
Correct |
441 ms |
460 KB |
Output is correct |
3 |
Correct |
435 ms |
460 KB |
Output is correct |
4 |
Correct |
425 ms |
592 KB |
Output is correct |
5 |
Correct |
140 ms |
496 KB |
Output is correct |
6 |
Correct |
375 ms |
484 KB |
Output is correct |
7 |
Correct |
229 ms |
484 KB |
Output is correct |
8 |
Correct |
416 ms |
460 KB |
Output is correct |
9 |
Correct |
457 ms |
480 KB |
Output is correct |
10 |
Correct |
433 ms |
492 KB |
Output is correct |
11 |
Correct |
20 ms |
332 KB |
Output is correct |
12 |
Correct |
226 ms |
460 KB |
Output is correct |
13 |
Correct |
179 ms |
436 KB |
Output is correct |
14 |
Correct |
180 ms |
424 KB |
Output is correct |
15 |
Correct |
927 ms |
420 KB |
Output is correct |
16 |
Correct |
393 ms |
480 KB |
Output is correct |
17 |
Correct |
461 ms |
484 KB |
Output is correct |
18 |
Correct |
432 ms |
484 KB |
Output is correct |
19 |
Correct |
471 ms |
460 KB |
Output is correct |
20 |
Correct |
426 ms |
488 KB |
Output is correct |
21 |
Correct |
435 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
216 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
44 ms |
352 KB |
Output is correct |
14 |
Correct |
21 ms |
476 KB |
Output is correct |
15 |
Correct |
17 ms |
408 KB |
Output is correct |
16 |
Correct |
32 ms |
464 KB |
Output is correct |
17 |
Correct |
27 ms |
460 KB |
Output is correct |
18 |
Correct |
27 ms |
472 KB |
Output is correct |
19 |
Correct |
548 ms |
428 KB |
Output is correct |
20 |
Correct |
441 ms |
460 KB |
Output is correct |
21 |
Correct |
435 ms |
460 KB |
Output is correct |
22 |
Correct |
425 ms |
592 KB |
Output is correct |
23 |
Correct |
140 ms |
496 KB |
Output is correct |
24 |
Correct |
375 ms |
484 KB |
Output is correct |
25 |
Correct |
229 ms |
484 KB |
Output is correct |
26 |
Correct |
416 ms |
460 KB |
Output is correct |
27 |
Correct |
457 ms |
480 KB |
Output is correct |
28 |
Correct |
433 ms |
492 KB |
Output is correct |
29 |
Correct |
20 ms |
332 KB |
Output is correct |
30 |
Correct |
226 ms |
460 KB |
Output is correct |
31 |
Correct |
179 ms |
436 KB |
Output is correct |
32 |
Correct |
180 ms |
424 KB |
Output is correct |
33 |
Correct |
927 ms |
420 KB |
Output is correct |
34 |
Correct |
393 ms |
480 KB |
Output is correct |
35 |
Correct |
461 ms |
484 KB |
Output is correct |
36 |
Correct |
432 ms |
484 KB |
Output is correct |
37 |
Correct |
471 ms |
460 KB |
Output is correct |
38 |
Correct |
426 ms |
488 KB |
Output is correct |
39 |
Correct |
435 ms |
460 KB |
Output is correct |
40 |
Correct |
1462 ms |
1916 KB |
Output is correct |
41 |
Correct |
26 ms |
1252 KB |
Output is correct |
42 |
Correct |
878 ms |
1932 KB |
Output is correct |
43 |
Correct |
738 ms |
1620 KB |
Output is correct |
44 |
Correct |
732 ms |
1740 KB |
Output is correct |
45 |
Correct |
2570 ms |
8120 KB |
Output is correct |
46 |
Correct |
38 ms |
4556 KB |
Output is correct |
47 |
Correct |
1451 ms |
8256 KB |
Output is correct |
48 |
Correct |
1093 ms |
6416 KB |
Output is correct |
49 |
Correct |
1055 ms |
7052 KB |
Output is correct |