-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD_Barisan_Intip.cpp
46 lines (35 loc) · 1.01 KB
/
D_Barisan_Intip.cpp
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
/*********************************HEADER**********************************
Topic : Data Structure
Problem : https://vjudge.net/contest/455106
https://tlx.toki.id/courses/competitive/chapters/08/problems/D
**************************************************************************/
/*
Data Structure:
- Vector -> an array (but dynamic)
- Queue -> FIFO (only access the first element)
- Priority_queue -> Priority (only access the priority)
- Stack -> LIFO (only access the last element)
- Set -> Non-duplicating
- Multiset -> Duplicating
*/
#include<iostream>
#include<stack>
using namespace std;
#define fi first
#define se second
typedef pair<int, int> ii;
const int INF = 1e9;
int main() {
int n; cin >> n;
int heights[n];
stack<ii> s; // Index, Height
long long ans = 0;
for(int i = 0; i < n; i++) cin >> heights[i];
s.push(ii(-1, INF));
for(int i = 0; i < n; i++) {
while(heights[i] >= s.top().se) s.pop();
ans += i - s.top().fi;
s.push(ii(i, heights[i]));
}
cout << ans << endl;
}