Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <functional>
- using namespace std;
- using namespace __gnu_pbds;
- #define ll long long int
- #define ld long double
- #define line cout<<"-------------"<<endl;
- #define F first
- #define S second
- #define P pair<ll,ll>
- #define PP pair<pair<ll,ll>,ll>
- #define V vector<ll>
- #define VP vector<pair<ll,ll>>
- #define VS vector<string>
- #define VV vector<vector<ll>>
- #define VVP vector<vector<pair<ll,ll>>>
- #define pb push_back
- #define pf push_front
- #define PQ priority_queue<ll>
- #define PQ_G priority_queue<ll,vector<ll>,greater<ll>>
- #define line cout<<"-------------"<<endl;
- #define mod 1000000007
- #define inf 1e18
- #define setbits(x) __builtin_popcount(x)
- #define zerobits(x) __builtin_ctzll(x)
- #define ps(x,y) fixed<<setprecision(y)<<x
- #define w(x) ll x; cin>>x; while(x--)
- #define FOR(i,a,b) for(ll i=a;i<b;i++)
- #define ma(arr,n,type) type *arr=new type[n]
- //here we are using an ordered set of pairs
- #define pbds tree<P,null_type,less<P>,rb_tree_tag,tree_order_statistics_node_update>
- void init()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- //freopen("input.txt","r",stdin);
- //freopen("output.txt","w",stdout);
- }
- int main()
- {
- init();
- ll t; cin>>t;
- while(t--){
- ll n,k; cin>>n>>k;
- V v(n);
- FOR(i,0,n)
- cin>>v[i];
- ll ans=0;
- //now iterate over all possible subarrays
- FOR(i,0,n){
- V hash(2001,0);
- pbds st;
- FOR(j,i,n){
- //This is the correct way to insert duplicates in a set
- //by storing the element along with its frequency
- st.insert({v[j],hash[v[j]]++});
- ll m=ceil(((double)k)/(j-i+1));
- ll pos=ceil((double)k/m);
- pos--;
- auto it=st.find_by_order(pos);
- ll val=(*it).F;
- //finding f which is the frequency of x in S(the subarray)
- ll f =hash[val];
- if(hash[f]>0)
- ans++;
- }
- }
- cout<<ans<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement