[] Select Inn luoguP1311

 

Title Description

Lijiang river has the n- the n-home very unique inn, the inn according to their position in order from  1 1 to the n- the n-number. Each inn are carried out in accordance with a certain kind of tone decorative (total  k k kinds integer  0 0 ~ k-1 k - 1 represents), and each inn has a coffee shop, each has its own coffee shop Minimum consumption.

To go along with two tourists in Lijiang tourism, they like the same tone, want to try two different inn, it was decided were living in the same two-tone inn. At night, they intend to select a coffee shop drinking coffee, the coffee shop is located in requirements (including the inn they lived) between two inn both live, and the lowest consumption of coffee shops does not exceed  the p- the p-.

They want to know how many there are in total choice of accommodation programs, to ensure that at night you can find a minimum consumption does not exceed p coffee shop p yuan-together.

Input Format

Total row n + 1.

The first row of three integers n-, K, P n- , K , P, between each two integers separated by a space, respectively, the highest number, and the number of tones of the lowest acceptable inn;

Following the n- the n-th,  i + 1 i + 1 line two integers, separated by a space between, respectively i i No. inn decorated with pastel colors and i minimum consumption of coffee shop number i inn.

Output Format

An integer, the total number of alternative accommodation plan representation.

Sample input and output

Input # 1
5 2 3 
0 5 
1 3 
0 2 
1 4 
1 5 
Output # 1
3

Description / Tips

Example Description [O]

2 people want to live in the same tone of the inn, all alternative accommodation programs include: live inn ①③, ②④, ②⑤, ④⑤, but if you choose to live 4 4 and 5 , then 5 inn 4 4 and 5 between 5 inn minimum consumption of coffee shops is 4 4 and the lowest consumer is able to withstand two 3 $ 3, it does not meet the requirements. Therefore, only the first  3 three schemes optional.

【data range】

For 30 \% . 3 0 % of the data, there are n-≦ 100 n- . 1 0 0;

For 50 \% . 5 0 % of the data, there are n-1, 000 n- . 1 , 0 0 0;

For 100 \% . 1 0 0 % of the data, there are  2 ≤200,000,0 ≤n <K ≤50,0≤p ≦ 100, 0 ≤ 2 n- 2 0 0 , 0 0 0 , 0 < K . 5 0 , 0 the p- 1 0 0 , 0 ≤ minimum consumption ≤100 1 0 0.

Ideas:

  Linear seek every record maintenance last, for the position of the last occurrence of a certain style, a record for the number of each color cnt arise, if the current price is in line with

  And it had appeared before, the number of updates to the color of this style in value every time the cumulative answer

Code:

#include<cstdio>
#include<iostream>
using namespace std;
const int N = 100000;
int last[N],sum[N],cnt[N],ans,now;
int n,k,p;
int main()
{
	int color,price;
	scanf("%d%d%d",&n,&k,&p);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&color,&price);
		if(price<=p)now=i;
		if(last[color]<=now) sum[color]=cnt[color];
		last[color]=i;
		ans+=sum[color];
		cnt[color]++;
	}
	printf("%d\n",ans);
	return 0;
}

  

 

Guess you like

Origin www.cnblogs.com/yelir/p/11535489.html