[bzoj3578]GTY的人类基因组计划2(hash+STL)

18 篇文章 0 订阅

题目:

我是超链接

题解:

set用来维护哪几个房间有人,在区间操作时可以直接跳转
map判重
hash表判断这个房间里的团体有没有经验值

代码:

#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#define ull unsigned long long
using namespace std;;
const int N=1e5;
const ull p=1310000001ull;
set<int>s;
map<ull,bool>mp;
ull mi[N+5],hah[N+5];
int cnt[N+5],loc[N+5];
int main()
{
    int n,m,q,i;
    scanf("%d%d%d",&n,&m,&q);
    mi[0]=1;
    for (i=1;i<=n;i++)
    {
        mi[i]=mi[i-1]*p;
        hah[1]+=(ull)i*mi[i];
        loc[i]=1;
    }
    s.insert(0); s.insert(m+1); s.insert(1);
    cnt[1]=n;
    while (q--)
    {
        char st[5];int l,r;
        scanf("%s",st);scanf("%d%d",&l,&r);
        if (st[0]=='C')
        {   
            cnt[loc[l]]--;cnt[r]++;
            s.erase(loc[l]); s.erase(r);
            hah[loc[l]]-=(ull)l*mi[l];
            hah[r]+=(ull)l*mi[l];
            if (!mp[hah[loc[l]]]) s.insert(loc[l]);
            if (!mp[hah[r]]) s.insert(r);
            loc[l]=r;
        }
        else
        {
            set<int>::iterator it,ll,rr;
            int ans=0;
            ll=s.lower_bound(l); rr=s.upper_bound(r);
            for (it=ll;it!=rr;it=s.lower_bound(l))
            {
                mp[hah[*it]]=1;
                ans+=cnt[*it];
                s.erase(it);
            }
            printf("%d\n",ans);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值