选择客栈

选择客栈

https://ac.nowcoder.com/acm/problem/16594

分析

对于每种颜色单独考虑,从左往右扫,记录最后出现的小于 p 的位置,对于贡献,我们枚举右端点,当记录的位置大于前一次出现的的位置时,更新可用左端点的数量。

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+7;
const int M = 1e9+7;

int a[maxn],b[maxn],cnt[maxn],lst[maxn],tot[maxn];

signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k,p;
    cin>>n>>k>>p;
    for(int i = 1; i <= n; i++) 
    {
        cin>>a[i]>>b[i];
    }
    int ans = 0,r = 0;
    for(int i = 1; i <= n; i++) 
    {
        if(b[i] <= p) r = i;
        if(r >= lst[a[i]]) tot[a[i]] = cnt[a[i]];
        lst[a[i]] = i;
        ans += tot[a[i]];
        cnt[a[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}
全部评论

相关推荐

05-19 15:21
已编辑
门头沟学院 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
把实习生当正职使昨天第一天就加班,晚上连口饭都没吃上,以后日子咋过,我不想干了
码农索隆:实习不怕忙,就怕干的活重复且没难度,要干就干那种有深度有难度的任务,这样才能快速的提升
实习吐槽大会
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务