Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //teja349
- #include <bits/stdc++.h>
- #include <vector>
- #include <set>
- #include <map>
- #include <string>
- #include <cstdio>
- #include <cstdlib>
- #include <climits>
- #include <utility>
- #include <algorithm>
- #include <cmath>
- #include <queue>
- #include <stack>
- #include <iomanip>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- //setbase - cout << setbase (16); cout << 100 << endl; Prints 64
- //setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
- //setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
- //cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val
- using namespace std;
- using namespace __gnu_pbds;
- #define f(i,a,b) for(i=a;i<b;i++)
- #define rep(i,n) f(i,0,n)
- #define fd(i,a,b) for(i=a;i>=b;i--)
- #define pb push_back
- #define mp make_pair
- #define vi vector< int >
- #define vl vector< ll >
- #define ss second
- #define ff first
- #define ll long long
- #define pii pair< int,int >
- #define pll pair< ll,ll >
- #define sz(a) a.size()
- #define inf (1000*1000*1000+5)
- #define all(a) a.begin(),a.end()
- #define tri pair<int,pii>
- #define vii vector<pii>
- #define vll vector<pll>
- #define viii vector<tri>
- #define mod (1000*1000*1000+7)
- #define pqueue priority_queue< int >
- #define pdqueue priority_queue< int,vi ,greater< int > >
- #define flush fflush(stdout)
- #define primeDEN 727999983
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- // find_by_order() // order_of_key
- typedef tree<
- int,
- null_type,
- less<int>,
- rb_tree_tag,
- tree_order_statistics_node_update>
- ordered_set;
- int p[1234567];
- vi oper1,oper2,ord;
- int check(int l,int r,int st,int en){
- //cout<<l<<" "<<r<<" "<<st<<" "<<en<<endl;
- if(l==r){
- return 1;
- }
- int i,j;
- ll sum1,sum2,poss1,poss2,ind;
- i=l;
- j=r;
- sum1=0;
- sum2=0;
- poss1=0;
- poss2=0;
- ind=0;
- int found=0,left;
- while(i<j){
- sum1+=p[i];
- sum2+=p[j];
- poss1+=st+ind;
- poss2+=en-ind;
- if(poss1==sum1 || poss2==sum1){
- found=1;
- left=1;
- break;
- }
- if(poss1==sum2 || poss2==sum2){
- found=1;
- left=0;
- break;
- }
- ind++;
- i++;
- j--;
- }
- if(!found)
- return 0;
- int val1,val2;
- int gg=0;
- if(left){
- if(poss1==sum1){
- val1=check(l,i,st,st+ind);
- val2=check(i+1,r,st+ind+1,en);
- gg=1;
- }
- else{
- val1=check(l,i,en-ind,en);
- val2=check(i+1,r,st,en-ind-1);
- gg=2;
- }
- }
- else{
- if(poss2==sum2){
- gg=1;
- val1=check(l,j-1,st,en-ind-1);
- val2=check(j,r,en-ind,en);
- }
- else{
- gg=2;
- val1=check(l,j-1,st+ind+1,en);
- val2=check(j,r,st,st+ind);
- }
- }
- if(val1==0 || val2==0){
- return 0;
- }
- oper1.pb(val1);
- oper2.pb(val2);
- ord.pb(gg);
- return (int)oper1.size()+1;
- }
- int main(){
- std::ios::sync_with_stdio(false); cin.tie(NULL);
- int t;
- cin>>t;
- while(t--){
- oper1.clear();
- oper2.clear();
- ord.clear();
- int n;
- cin>>n;
- int i;
- rep(i,n){
- cin>>p[i];
- }
- if(check(0,n-1,1,n)){
- //cout<<"YES"<<endl;
- printf("YES\n");
- }
- else{
- printf("NO\n");
- continue;
- }
- //cout<<oper1.size()<<endl;
- printf("%d\n",(int)oper1.size());
- rep(i,oper1.size()){
- //cout<<oper1[i]<<" "<<oper2[i]<<" "<<ord[i]<<endl;
- printf("%d %d %d\n",oper1[i],oper2[i],ord[i]);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment