Problem description
To simplify the building process, Xadillax built some template on the ground. The template is a very big wall and the height of each unit may be different.
8Mao and Hungar has to choose any part of this wall as their own wall.
The part (I, j) means the wall between unit (i) and unit (j) with their heights.
What Hungar thinks a beautiful wall is and the height of each unit is unique.
Now give you a wall-template, do should tell Hungar so how many ways he can choose to copy his own wall?
Input
This problem contains several cases, ends with EOF.
The first line of all case is one integer N (0 n≤100000) which indicates the side length (number of units) of the Wal L-template.
The second line contains N integers which indicate the height of each unit. (0 < height <= 100000)
Output
For each case, you should output the number of ways that Hungar can choose.
Sample input
5
3 4 5) 5 2
3
1 2 3
Sample output
9
6
Tips
No
Source
Cjl
Operation
Wine93 out of a problem I was done with a ruler, as long as the record of each of the last occurrence of the position on the line
/************************************************************************* > File Name:NOJ1553.cpp > Auth Or:alex > Mail: [email protected] > Created time:2015 April 16 Thursday 19:36 28 seconds ******************************** ****************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Static Const intN =100100;intHeight[n];intLast[n];int_hash[n];intMain () {intN while(~scanf("%d", &n)) {memset(Last,-1,sizeof(last));memset(_hash,-1,sizeof(_hash)); for(inti =1; I <= N; ++i) {scanf("%d", &height[i]);intx = _hash[height[i]]; Last[i] = x; _hash[height[i]] = i; } LL ans =0;intL =1, r =1, Len =0; while(1) { while(r <= N && last[r] < L) {++len; ++r; } ans + = Len; --len; ++l;if(L > R) { Break; } }cout<< ans << Endl; }return 0;}
NOJ1553---Beautiful Walls (ruler)