My issue
The testcases for the problem are too weak. The brute force solution give accepted. You should provide stronger test cases.
One of these cases should be:
1 \\
10^5 \\
10^5 \, 10^5-1 \, 10^5-2 \, ... \, 10^5-2 \, 10^5-1 \, 10^5
My code
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;cin >> t;
while(t--){
int n;cin >> n;
vector<int> v(n);
vector<int> ans(n,0);
for(int i = 0;i < n;i++)cin >> v[i];
for(int i = 0;i < n;i++){
int j = i+1;
int k = i-1;
while(j < n){
if(v[j] > v[i])break;
if(v[j] == v[i])ans[i]++;
j++;
}
while(k >= 0){
if(v[k] > v[i])break;
if(v[k] == v[i])ans[i]++;
k--;
}
}
for(int i = 0;i < n;i++)cout << ans[i] << " ";
cout << "\n";
}
return 0;
}
Problem Link: https://www.codechef.com/problems/LUNCHTIM