LOJ#6047. 「雅礼集训 2017 Day10」决斗(set)

题面

传送门

题解

这么简单一道题我考试的时候居然只打了\(40\)分暴力?

如果我们把每个点的\(a_i\)记为\(deg_i-1\),其中\(deg_i\)表示有\(deg_i\)个数的\(A_i\)\(i\),那么很明显所有数的\(a_i\)之和为\(0\)

于是,必然存在一个点\(k\),满足从\((k,k+1)\)把环断掉之后,且以\(k+1\)为开头,整个数列的前缀和不小于\(0\),也就是说精灵永远不会跨过\(k\)去找别的侏儒打架

这个\(k\)的话,只要找到前缀和最小值的地方就可以了

然后之后直接大力模拟就可以了

//minamoto
#include<bits/stdc++.h>
#define R register
#define IT set<int>::iterator
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=5e5+5;
struct eg{int v,nx;}e[N];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int a[N],b[N],c[N],d[N],n,res,sum,mn,k;set<int>s;IT it;
int main(){
//  freopen("testdata.in","r",stdin);
    n=read(),mn=0x3f3f3f3f;
    fp(i,1,n)a[i]=read(),++d[a[i]],add(a[i],i);
    fp(i,1,n)b[i]=read();fp(i,1,n)c[i]=read();
    fp(i,1,n)if(cmin(mn,(sum+=d[i])-i))k=i;
    fp(i,1,n){
        if(++k>n)k=1;
        go(k)s.insert(c[v]);
        if(b[k]>*--s.end())s.erase(s.begin());
        else it=s.lower_bound(b[k]),s.erase(it),++res;
    }
    printf("%d\n",res);
    return 0;
}

转载于:https://www.cnblogs.com/bztMinamoto/p/10712245.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值