//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int main() {_
int n,l;
cin>>n>>l;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
vector<pair<pair<int,int>,int>> vec;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i]==a[j]) continue;
int L=max(0,i-(l-max({0,l-(i+1),l-(j+1)}))+1);
int R=i-max({0,l-(n-i),l-(n-j)});
if(R<L) continue;
//cout<<L<<' '<<R<<'\n';
vec.push_back({{L,R},j-i});
}
}
vector<vector<int>> st(n),en(n);
for(auto v:vec){
st[v.f.f].push_back(v.s);
if(v.f.s<n-1) en[v.f.s+1].push_back(v.s);
}
int q;
cin>>q;
vector<pair<int,int>> qs;
for(int i=0;i<q;i++){
int x;
cin>>x;
qs.push_back({x,i});
}
sort(all(qs));
sort(all(vec));
vector<int> cnt(3*n);
vector<int> id(l+1);
for(int i=0;i<=l;i++){
int pos=lower_bound(all(qs),make_pair(i,-1))-qs.begin();
id[i]=((pos==q)?-1:pos);
}
vector<vector<int>> ans(n,vector<int>(q));
for(int i=0;i<n-l+1;i++){
for(auto v:st[i]){
cnt[v+n]++;
}
for(auto v:en[i]){
cnt[v+n]--;
}
for(int j=-i;j<n-i-l+1;j++){
if(j==0) continue;
//cout<<cnt[n+j]<<' ';
assert(cnt[n+j]>=0 and cnt[n+j]<=l);
if(id[cnt[n+j]]!=-1){
ans[i][id[cnt[n+j]]]++;
}
}
for(int j=1;j<q;j++){
ans[i][j]+=ans[i][j-1];
}
//cout<<'\n';
}
vector<int> tmp(q);
for(int i=0;i<q;i++){
tmp[qs[i].s]=i;
}
for(int j=0;j<q;j++){
for(int i=0;i<n-l+1;i++){
cout<<ans[i][tmp[j]]<<' ';
}
cout<<'\n';
}
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message
lot.cpp: In function 'void setIO(std::string)':
lot.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lot.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
7 ms |
2008 KB |
Output is correct |
9 |
Correct |
6 ms |
2084 KB |
Output is correct |
10 |
Correct |
7 ms |
2516 KB |
Output is correct |
11 |
Correct |
7 ms |
2772 KB |
Output is correct |
12 |
Correct |
8 ms |
2620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
7 ms |
2008 KB |
Output is correct |
9 |
Correct |
6 ms |
2084 KB |
Output is correct |
10 |
Correct |
7 ms |
2516 KB |
Output is correct |
11 |
Correct |
7 ms |
2772 KB |
Output is correct |
12 |
Correct |
8 ms |
2620 KB |
Output is correct |
13 |
Runtime error |
73 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
76 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
76 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
7 ms |
2008 KB |
Output is correct |
9 |
Correct |
6 ms |
2084 KB |
Output is correct |
10 |
Correct |
7 ms |
2516 KB |
Output is correct |
11 |
Correct |
7 ms |
2772 KB |
Output is correct |
12 |
Correct |
8 ms |
2620 KB |
Output is correct |
13 |
Runtime error |
73 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |