-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDateHour.cpp
More file actions
58 lines (46 loc) · 921 Bytes
/
DateHour.cpp
File metadata and controls
58 lines (46 loc) · 921 Bytes
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
// problem: "https://www.hackerrank.com/contests/practice-contest-iet/challenges/date-hour"
#include<bits/stdc++.h>
#define ll long long
#define p (ll)(1e9+7)
using namespace std;
ll Fear(vector<ll>&V)
{
stack<ll>S;
ll i,ans,x;
ans = 1;
for(i=0;i!=V.size();i++)
{
if(S.empty())
S.push(i);
else
{
if(V[S.top()] <= V[i])
S.push(i);
else
{
while(!S.empty() && V[S.top()]>V[i])
{
x = S.top();
S.pop();
ans = (ans*(i-x+1))%p;
}
S.push(i);
}
}
}
return ans;
}
int main()
{
int x,n,k;
cin>>n>>k;
vector<ll>V;
int i;
for(i=0;i!=n;i++)
{
cin>>x;
V.push_back(x);
}
cout<<Fear(V); // define
return 0;
}