Fun with Even Subarrays
You are given an array
- Select some subarray from
a of even size2k that begins at positionl (1≤l≤l+2⋅k−1≤n ,k≥1 ) and for eachi between0 andk−1 (inclusive), assign the valueal+k+i toal+i .
For example, if
Find the minimum number of operations (possibly zero) needed to make all the elements of the array equal.
The input consists of multiple test cases. The first line contains a single integer
The first line of each test case contains an integer
The second line of each test case consists of
It is guaranteed that the sum of
Print
In the first test, all elements are equal, therefore no operations are needed.
In the second test, you can apply one operation with
In the third test, you can apply one operation with
In the fourth test, you can apply one operation with
In the fifth test, there is only one element, therefore no operations are needed.
- #include<bits/stdc++.h>
- using namespace std;
- #define pb emplace_back
- #define pob pop_back
- typedef long long int lli;
- #define test lli t; cin>>t; while(t--)
- #define ff first
- #define ss second
- #define F(n) for(lli i=0;i<n;i++)
- #define pf pop_front
- #define lb lower_bound
- #define ub upper_bound
- #define setbits(x) __builtin_popcountll(x)
- #define zerobits(x) __builtin_ctzll(x)
- #define bs binary_search
- #define all(x) x.begin(),x.end()
- #define nl "\n"
- #define loop(i,s,n) for(lli i=s;i<n;i++)
- #define pp(a) for(auto x : a) cout<<x<<" "; cout<<nl;
- #define mem(arr,x) memset(arr,x,sizeof(arr))
- #define mod 1000000007
- #define inf 1e18
- #define N 100005
- #define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i];
- #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- #define ps(x,y) fixed<<setprecision(y)<<x
- int main()
- {
- fast;
- // #ifndef ONLINE_JUDGE
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- // #endif
- lli n,i,j,k;
- test
- {
- cin>>n>>k;
- lli sum=0;
- loop(i,0,n)
- {
- if(i%2==0)
- {
- sum+=(i&(i+1));
- }
- }
- // cout<<sum<<" ";
- if(k>sum) cout<<-1<<nl;
- else
- {
- if(k==n-1)
- {
- cout<<n-2<<" "<<n-1<<nl;
- cout<<"1 3"<<nl;
- i=0;j=n-3;
- while(i<j)
- {
- if(i==1 || i==3) { i++; continue; }
- if(j==1 || j==3) { j--; continue; }
- cout<<i<<" "<<j<<nl;
- i++;j--;
- }
- }
- else
- {
- cout<<k<<" "<<n-1<<nl;
- if(k!=0)
- cout<<0<<" "<<n-1-k<<nl;
- i=1;j=n-2;
- while(i<j)
- {
- if(i==k || j==k)
- {
- i++;
- j--;
- }
- else
- {
- cout<<i<<" "<<j<<nl;
- i++;j--;
- }
- }
- }
- }
- // cout<<nl;
- }
- return 0;
- }
plss provide solution
ReplyDeleteSolution come within contest time .but you have to follow our blog to get notification of solution .if you follow our blog then get notification when answer in updated in blog.so click on follow button.also follow on our youtube channel for furture notification.
Delete