We think about this case:
input:10 8 1
2 1 8 3 1 8 9 1 8 2
Output:14
Explanation:-
2(1) 1(2) 8(3) 3(4) 1(5) 8(6) 9(7) 1(8) 8(9) 6(10)
When we work on 2 then no pair added
When we work on 1 then no pair added
When we work on 8 then 2 pair added
1 to 3
2 to 3
When we work on 3 then 2 pair added
1 to 4
2 to 4
When we work on 1 then 3 pair added
1 to 5
2 to 5
3 to 5
When we work on 8 then 2 pair added
1 to 6
2 to 6
3 to 6
4 to 6
5 to 6
When we work on 9(Special case)
Because any pair with this value will be incorrect because it is greater than X
It can also be if there are any value less than Y
When we work on 1 then no pair added
When we work on 8 then 1 pair added
8 to 9
When we work on 8 then 1 pair added
8 to 10
So all eligible pairs
Pair no 1(1 to 3)
Pair no 2(2 to 3)
Pair no 3(1 to 4)
Pair no 4(2 to 4)
Pair no 5(1 to 5)
Pair no 6(2 to 5)
Pair no 7(1 to 5)
Pair no 8(1 to 6)
Pair no 9(2 to 6)
Pair no 10(3 to 6)
Pair no 11(4 to 6)
Pair no 12(5 to 6)
Pair no 13(8 to 9)
Pair no 14(8 to 10)
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
ll n,x,y,pre=0,pre_x=-1,pre_y=-1,num,ans=0;
cin>>n>>x>>y;
for(ll i=1;i<=n;i++)
{
cin>>num;
if(y<=num && num<=x)
{
if(num==x) pre_x=i;
if(num==y) pre_y=i;
if(min(pre_x,pre_y)>pre && pre_x!=(-1) && pre_y!=(-1)) ans+=(min(pre_x,pre_y)-pre);
}
else pre=i;
}
cout<<ans<<endl;
return 0;
}
///Alhamdulillah
Problem link:https://atcoder.jp/contests/abc247/tasks/abc247_e
Comments
Post a Comment