-
Notifications
You must be signed in to change notification settings - Fork 9
/
CITY2 - A Famous City.cpp
43 lines (43 loc) · 1.11 KB
/
CITY2 - A Famous City.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
#include<bits/stdc++.h>
using namespace std;
#define mx 100002
int table[mx][17], arr[mx];
unordered_map<int, vector<int> >mp;
void build(int n)
{
for(int i=1; i<=n; i++)
table[i][0] = arr[i];
for(int j=1; (1<<j)<=n; j++){
for(int i=1; i + (1<<j) - 1<=n; i++){
table[i][j] = min(table[i][j-1], table[ i + (1<<(j-1)) ][j-1]);
}
}
}
int query(int low, int high)
{
int k = log2(high-low+1);
return min(table[low][k], table[high-(1<<k)+1][k] );
}
int main()
{
int n, cs =1;
while(scanf("%d",&n)!=EOF){
mp.clear();
for(int i=1; i<=n; i++){
scanf("%d",&arr[i]);
if(arr[i])mp[ arr[i] ].push_back(i);
}
build(n);
int ans = 0;
for(auto it = mp.begin(); it!=mp.end(); it++){
vector<int> v = it->second;
int now = it->first;
ans++;
for(int i=1; i<v.size(); i++){
if(query(v[i-1], v[i])<now)
ans++;
}
}
printf("Case %d: %d\n", cs++,ans);
}
}