Codeforces 1046C. Space Formula(类似并查集实现类似链表的删除操作)

题目:传送门

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define deg(x) cout<< #x"=" << x << endl;
#define degg(x,y) cout<< #x"="<< x <<","<< #y"="<< y <<endl;
#define deggg(x,y,z) cout<<#x"="<<x<<","<<#y"="<<y<<","<<#z"="<<z<<endl;
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define scaaa(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define ptf(x) printf("%d\n",x)
#define ptff(x,y) printf("%d %d\n",x,y)
#define ptfff(x,y,z) printf("%d %d %d\n",x,y,z)
#define space(x) printf("%d ",x)
#define mes(a,x) memset(a,x,sizeof(a))
#define PI acos(-1)
#define lowbit(x) x&-x
#define ALL(X) (X).begin(), (X).end()
#define PB push_back
#define MP make_pair
#define ls rt<<1
#define rs rt<<1|1
#define Mid(l,r) (l+r)/2
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > xqueue;
typedef priority_queue<int> dqueue;

const ll mod=1e9+7;
const ll INF=9e18;
const int inf=2147483647;

const int N=2e5+5;
int s[N],p[N];
int r[N];

int F(int x)
{
    return x==r[x]?x:r[x]=F(r[x]);
}

void work()
{
    int n,d;
    scaa(n,d);
    for(int i=0; i<n; i++)
        sca(s[n-i]);
    for(int i=0; i<n; i++)
        sca(p[n-i]),r[i+1]=i+1;
    s[n-d+1]+=p[n]; r[0]=n-1;
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        if(i==n-d+1) continue;
        if(s[i]>s[n-d+1])
        {
            ans++;
            continue;
        }
        int t=upper_bound(p+1,p+n,s[n-d+1]-s[i])-p-1;
        if(t>=n) t--;
        t=F(t);
        if(s[i]+p[r[t]]>s[n-d+1]) ans++;
        r[t]=t-1;
    }
    ptf(ans);
}

int main()
{
#ifdef Local
    freopen("1.txt","r",stdin);
#endif // mm
    //IOS;
    //int t; sca(t); while(t--)
    work();
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值