SHARE
TWEET

A

a guest Jul 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. typedef long long ll;
  7. typedef unsigned long long ull;
  8. typedef pair<ll,ll>pll;
  9. typedef pair<int,int>pii;
  10. //typedef pair<int,pair<int,int>>piii;
  11. typedef pair<ll,pair<ll,ll>>plll;
  12. typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> orderedSet;
  13. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  14. #define sf(a) scanf("%I64d",&a)
  15. #define pf(a) printf("%I64d\n",a)
  16. #define mem(a,b)     memset(a,b,sizeof(a))
  17. #define vll(v) v.begin(),v.end()
  18. #define all(x) x.rbegin(),x.rend()
  19. #define min3(a, b, c)   min(a, min(b, c))
  20. #define F first
  21. #define S second
  22. #define minheap int,vector<int>,greater<int>
  23. #define result(ans) cout<<"Case "<<cas++<<": "<<ans<<endl
  24. #define pb push_back
  25. #define pp pop_back
  26. #define eb emplace_back
  27. #define in  freopen("input.txt", "r", stdin)
  28. #define out  freopen("output.txt", "w", stdout)
  29. #define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
  30. #define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
  31. #define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
  32. const int Max = 2e6 + 10;
  33. const int Mod = 1e9 + 7;
  34. const double PI  =3.141592653589793238463;
  35. bool compare(const pair<int,int> &a, const pair<int,int> &b)
  36. {
  37.     return (a.first > b.first);
  38. }
  39. ll lcm(ll a,ll b)
  40. {
  41.     if(a==0 || b==0)
  42.         return 0;
  43.  
  44.     return a/__gcd(a,b)*b;
  45. }
  46. //___________________________________________________________________________________________________________________
  47. //                              CODE STARTS FROM HERE
  48. //                               MU_Codefighter2019
  49. //-------------------------------------------------------------------------------------------------------------------
  50.  
  51.  
  52. ll cnt=0;
  53.  
  54.  
  55. void input(ll ara[],ll n)
  56. {
  57.     for(int i=1; i<=n; i++)
  58.         cin>>ara[i];
  59. }
  60. map<ll,ll>mp;
  61.  
  62. void add(ll a)
  63. {
  64.     if(mp[a]==0)
  65.         cnt++;
  66.  
  67.     mp[a]++;
  68. }
  69.  
  70. void del(ll a)
  71. {
  72.     mp[a]--;
  73.  
  74.     if(mp[a]==0)
  75.         cnt--;
  76. }
  77. int main()
  78. {
  79.     fastread();
  80.  
  81.     ll t,cas=1,i,j,a,b,c,d,e,sum=0,k,n;
  82.  
  83.     cin>>n>>k;
  84.     ll ara[n+2];
  85.     map<ll,ll>mp;
  86.  
  87.     for(i=1; i<=n; i++)
  88.     {
  89.         cin>>ara[i];
  90.     }
  91.     i=1;
  92.     ll pre=1;
  93.  
  94.     ll mx=0;
  95.  
  96. pll ans;
  97.  
  98.     while(i<=n)
  99.     {
  100.        // cout<<cnt<<endl;
  101.        if(cnt<=k)
  102.        {
  103.            add(ara[i]);
  104.  
  105.  
  106.  
  107.            if(mx<(i-(pre-1)) && cnt<=k)
  108.           {
  109.  
  110.            ans.F=pre;
  111.  
  112.            ans.S=i;
  113.  
  114.            mx=(i-(pre-1));
  115.  
  116.           // cout<<mx<<endl<<i-(pre-1)<<endl<<endl;
  117.  
  118.           // cout<<ans.F<<" "<<ans.S<<endl;
  119.           }
  120.           i++;
  121.  
  122.  
  123.  
  124.  
  125.        }
  126.        else
  127.        {
  128.            del(ara[pre]);
  129.  
  130.            pre++;
  131.  
  132.        }
  133.     }
  134.  
  135.     cout<<ans.F<<" "<<ans.S<<endl;
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top