We'd like to thank you all for participating in the contest, and hope you enjoyed it. Hope to see you again soon!
Author: JainWinn
There are $$$26$$$ lowercase alphabets, and we want $$$7$$$ as maximum frequency among all these characters. What would be maximum length of a Thala substring?
We will use two-pointer approach to solve the problem.Left pointer can be fixed (say $$$i$$$).
There are $$$26$$$ lowercase alphabets, and we want $$$7$$$ as maximum frequency among all these characters. So in worst case we will check for at most $$$26 \times 7 = 182$$$ size substring.
So for each $$$i$$$, our right pointer(say $$$j$$$) will iterate from $$$i$$$ to $$$min(i+26 \times 7,n)$$$ i.e $$(i \leq j < min(i+26 \times 7,n)
Unable to parse markup [type=CF_MATHJAX]
and increment answer whenever maximum frequency equals $$$7$$$.#include<bits/stdc++.h>
using namespace std;
//=======================================================================
#define ll long long
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define all(x) (x).begin(),(x).end()
#define countbits(x) __builtin_popcount(x)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
int mod = 1e9+7;
//int mod = 998244353;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
int ans=0;
//stores freq of characters
vi mp(26,0);
for(int i=0 ; i<n ; i++){
//stores maximum frequency among all characters
int maxi=0;
for(int j=i ; j<min(i+26*7,n) ; j++){
mp[s[j]-'a']++;
maxi=max(maxi,mp[s[j]-'a']);
//increasing answer if maximum frequency is 7
ans+=(maxi==7);
}
for(int j=i ; j<min(i+26*7,n) ; j++){
mp[s[j]-'a']--;
}
}
cout<<ans<<endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
E – Geometric Progression Subsequence
Author: JainWinn
Fixing one among $$$(l,r)$$$, could you find the other one?
#include<bits/stdc++.h>
using namespace std;
//=======================================================================
#define ll long long
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define all(x) (x).begin(),(x).end()
#define countbits(x) __builtin_popcount(x)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
int mod = 1e9+7;
//int mod = 998244353;
void solve(){
int n, ans = 0;
cin >> n;
vector<int> vec(n);
for (auto &ele : vec){
cin >> ele;
}
//stores rightmost index for each element(1 to 30 inclusive) while iterating for each index
vector<vector<int>> closest;
//stores rightmost index for each element(1 to 30 inclusive) while iterating for last index
vector<int> prevdata(31, -1);
//stores max left pointer(l) for each r.
vector<int> maxl(n, -1);
for (int r = 0; r < n; r++)
{
closest.push_back(prevdata);
//finding maxl for current r by checking all possible Geometric Progressions(size 3) ending at r.
//It could also be the maxl of previous index(i.e (r-1)).
int maxind = -1;
if (r > 1)
{
maxind = maxl[r - 1];
for (int mid = 1; mid < 31; mid++)
{
if ((mid * mid) % vec[r] == 0 && (mid * mid) / vec[r] < 31 && closest[r][mid] != -1)
{
int midind = closest[r][mid];
int first = (mid * mid) / vec[r];
maxind = max(maxind, closest[midind][first]);
}
}
}
//there would be (maxind+1) l,r pairs, so adding this to answer
ans = ans + (maxind + 1);
//storing maxl for r
maxl[r] = maxind;
//updating rightmost index for vec[r]
prevdata[vec[r]] = r;
}
cout << ans << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
while(t--){
solve();
}
return 0;
}



