-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRightMaximum.cpp
More file actions
63 lines (54 loc) · 1.07 KB
/
RightMaximum.cpp
File metadata and controls
63 lines (54 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
AUTHOR: Antarikshya Mitra
TIME:
PROBLEM NO:- Right Maximum
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
void solve(vector<int> &arr)
{
int n = arr.size();
vector<pair<int,int>> prefix;
int maxi = INT_MIN;
int index = -1;
for(int i=0;i<n;i++)
{
if(arr[i] >= maxi) {
maxi = arr[i];
index = i;
}
prefix.push_back({maxi,index});
}
struct pair_hash {
size_t operator()(const pair<int,int>& p) const {
return hash<int>()(p.first) ^ (hash<int>()(p.second) << 1);
}
};
unordered_set<pair<int,int>, pair_hash> st;
for(int i=0;i<n;i++)
{
st.insert(prefix[i]);
}
cout << st.size() << endl;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int> arr(n);
for (auto &a:arr)
cin>>a;
solve(arr);
}
return 0;
}