Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4. map<int,int>mp1,mp2,pp1,pp2,ch;
  5. int main()
  6. {
  7.     int t;
  8.     cin>>t;
  9.     while(t--)
  10.     {
  11.         int n,i,mx=-1,l1max=-1,l2max=-1,r1max=-1,r2max=-1;
  12.         int loc1=-1,loc2=-1,cnt=0,cnt1=0,cnt2=0;
  13.         vector<int>ans;
  14.         cin>>n;
  15.         int ar[n];
  16.         mp1.clear(); pp1.clear(); mp2.clear(), pp2.clear(),ch.clear();
  17.         bool f=true,f1=true,f2=true,no=true;
  18.         for(i=0;i<n;i++)
  19.         {
  20.             cin>>ar[i];
  21.             if(mp1[ar[i]]==0 && cnt==0)
  22.             {
  23.                // left1.push_back(ar[i]);
  24.                 l1max=max(l1max,ar[i]);
  25.                 loc1=i;
  26.                 mp1[ar[i]]++;
  27.             }
  28.             else
  29.             {
  30.                // left2.push_back(ar[i]);
  31.                 cnt++;
  32.                 l2max=max(l2max,ar[i]);
  33.                 mp2[ar[i]]++;
  34.             }
  35.             ch[ar[i]]++;
  36.             if(ch[ar[i]]==3)
  37.             {
  38.                 no=false;
  39.             }
  40.         }
  41.         cnt=0;
  42.         for(i=n-1;i>=0;i--)
  43.         {
  44.             if(pp1[ar[i]]==0 && cnt==0)
  45.             {
  46.                 //right1.push_back(ar[i]);
  47.                 r1max=max(r1max,ar[i]);
  48.                 loc2=i;
  49.                 pp1[ar[i]]++;
  50.             }
  51.             else
  52.             {
  53.                // right2.push_back(ar[i]);
  54.                  cnt++;
  55.                  r2max=max(r2max,ar[i]);
  56.                  pp2[ar[i]]++;
  57.             }
  58.         }
  59.         cnt=0;
  60.        // if(left1.size()+left2.size()!=n) f=false;
  61.        // else f=true;
  62.         if(no)
  63.         {
  64.             for(i=1;i<=l1max;i++)
  65.             {
  66.                 if(mp1[i]==0 || mp1[i]>=2)
  67.                 {
  68.                     f1=false;
  69.                     break;
  70.                 }
  71.             }
  72.             for(i=1;i<=l2max;i++)
  73.             {
  74.                 if(mp2[i]==0 || mp2[i]>=2)
  75.                 {
  76.                     f2=false;
  77.                     break;
  78.                 }
  79.             }
  80.             if(f1 && f2)
  81.             {
  82.                 cnt1++;
  83.                 ans.push_back(loc1+1);
  84.                 ans.push_back(n-(loc1+1));
  85.             }
  86.             f1=true; f2=true;
  87.             for(i=1;i<=r1max;i++)
  88.             {
  89.                 if(pp1[i]==0 || pp1[i]>=2)
  90.                 {
  91.                     f1=false;
  92.                     break;
  93.                 }
  94.             }
  95.             for(i=1;i<=r2max;i++)
  96.             {
  97.                 if(pp2[i]==0 || pp2[i]>=2)
  98.                 {
  99.                     f2=false;
  100.                     break;
  101.                 }
  102.             }
  103.             if(f1 && f2)
  104.             {
  105.                 cnt2++;
  106.                 ans.push_back(loc2);
  107.                 ans.push_back(n-(loc2));
  108.             }
  109.             if(cnt1==1 && cnt2==0)
  110.             {
  111.                 cout<<cnt1<<endl;
  112.                 cout<<ans[0]<<' '<<ans[1]<<endl;
  113.             }
  114.             else if(cnt2==1 && cnt1==0)
  115.             {
  116.                 cout<<cnt2<<endl;
  117.                 cout<<ans[0]<<' '<<ans[1]<<endl;
  118.             }
  119.             else if(cnt2==1 && cnt1==1)
  120.             {
  121.                 if(ans[0]!=ans[2] && ans[1]!=ans[3]){
  122.                 cout<<cnt2+cnt1<<endl;
  123.                 cout<<ans[0]<<' '<<ans[1]<<endl;
  124.                 cout<<ans[2]<<' '<<ans[3]<<endl;
  125.                 }
  126.                 else
  127.                 {
  128.                      cout<<cnt1<<endl;
  129.                     cout<<ans[0]<<' '<<ans[1]<<endl;
  130.                 }
  131.             }
  132.             else cout<<0<<endl;
  133.         }
  134.         else
  135.         {
  136.             cout<<0<<endl;
  137.         }
  138.     }
  139.     return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement