//#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=i-(l-max({0,l-(i+1),l-(j+1)}))+1;
int R=i-max({0,l-(n-i),l-(n-j)});
if(L<0 or L>n or R<0 or R>n){
return 0;
}
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:qs[pos].s);
}
vector<vector<int>> ans(n,vector<int>(q));
for(int i=0;i<n;i++){
for(auto v:st[i]){
cnt[v+n]++;
}
for(auto v:en[i]){
cnt[v+n]--;
}
for(int j=-i;j<n-i-1;j++){
if(j==0) continue;
//cout<<cnt[n+j]<<' ';
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';
}
for(int j=0;j<q;j++){
for(int i=0;i<n-l+1;i++){
cout<<ans[i][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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |