https://ac.nowcoder.com/acm/problem/16594
两个人,每个客栈有颜色和价格,问两个人住一样的颜色并且中间有价格<=有的钱的客栈问有多少种住法;
枚举左边的人的位置,统计右边的人可以在的位置的数量
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+7;
const int M = 1e9+7;
int cnt[maxn],lst[maxn],tot[maxn];
//tot左边能取的位置数
signed main()
{
int n,k,p,a,b;
cin>>n>>k>>p;
int ans = 0,r = 0;
for(int i = 1; i <= n; i++)
{
cin>>a>>b;
if(b <= p) r = i;//最右的能去的店
if(r >= lst[a])//可消费的店在这个颜色最右记录的右面,颜色之前数量的店 左面的人就都能去
tot[a] = cnt[a];
lst[a] = i;
ans += tot[a];//加上左面的人能去的数量
cnt[a]++;
}
cout<<ans<<endl;
return 0;
} 


京公网安备 11010502036488号