#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
int L, N;
int M;
int get_pos(vector<int>& v, int i){
int res =0;
for(int step =(1<<20); step>=1; step/=2){
if(res + step < v.size() && v[res+step]<=i){
res += step;
}
}
return res;
}
struct Summer{
vector<vector<int>> ev;
Summer(int n){
ev.resize(n+1);
}
void add_inc(int l, int r){
ev[l].push_back(1);
ev[r+1].push_back(-1);
}
vector<int> calc(){
vector<int> res;
int cur_s = 0;
for(int i = 0; i<ev.size()-1; i++){
for(auto e: ev[i]){
cur_s += e;
}
res.push_back(cur_s);
}
return res;
}
};
signed main(){
cin>>N>>L;
M = N-L+1;
vector<int> a(N);
vector<int> vals;
for(int i= 0; i<N; i++){
cin>>a[i];
vals.push_back(a[i]);
}
sort(vals.begin(), vals.end());
for(int i = 0; i<N; i++){
a[i] = get_pos(vals, a[i]);
}
vector<vector<int>> next_oc(N, vector<int>(1, N));
vector<Summer> sums(N+1, N+1);
for(int i = N-1; i>=0; i--){
int cur_a = a[i];
for(auto e: next_oc[cur_a]){
sums[e-i].add_inc(max(0, i-L+1),i);
}
next_oc[cur_a].push_back(i);
}
int Q;
cin>>Q;
vector<int> lims(Q);
for(int i = 0; i<Q; i++){
cin>>lims[i];
}
vector<vector<int>> score(M, vector<int>(Q, 0));
for(int len = 1; len<N; len++){
vector<int> dists = sums[len].calc();
sums[len].ev.clear();
for(int i = 0; i+len<M; i++){
for(int q= 0; q<Q; q++){
if(dists[i]>=L-lims[q]){
score[i][q]++;
score[i+len][q]++;
}
}
}
}
for(int q = 0; q<Q; q++){
for(int i = 0; i<M; i++){
cout<<score[i][q]<<" ";
}
cout<<endl;
}
}
Compilation message
lot.cpp: In function 'int get_pos(std::vector<int>&, int)':
lot.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | if(res + step < v.size() && v[res+step]<=i){
| ~~~~~~~~~~~^~~~~~~~~~
lot.cpp: In member function 'std::vector<int> Summer::calc()':
lot.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 0; i<ev.size()-1; i++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
2472 KB |
Output is correct |
9 |
Correct |
2 ms |
2596 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
2472 KB |
Output is correct |
9 |
Correct |
2 ms |
2596 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
2472 KB |
Output is correct |
9 |
Correct |
2 ms |
2596 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |