【Codeforces 739 B. Alyona and a tree】树上二分+树上差分

20 篇文章 0 订阅
3 篇文章 0 订阅

CF 739 B

• 给定一个带点权及边权的有根树
• v被u控制定义为
• 1. v在u的子树内(v != u)
• 2. u - v的距离小于等于v的点权
• 1 ≤ n ≤ 2 * 1e5

这题也是够骚的 自己马上想出来一个树上倍增的写法 但是树上倍增估计有点难写
这题如果是子树 这类问题可以在dfs的时候单纯抽出那条子树队列
我只要找 disx - arrx 我们想一下 如果这个值是负数 那么他要减任何他祖先的距离都满足条件这时候我们找dis最小的也就是离根最近的
如果这个值是正数 那么我们找第一个比他大的减一下是不是就是负数或 0 了 满足题意的小于等于
但是我们找到以后还不能直接减去 要让pos–
因为这里用到了树上差分 想让 u - v路径都加 1 那么v+1 u的祖先-1 这样再统计贡献
也是十分的骚了

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
typedef long long ll;
const int MAX_N = 200025;
ll arr[MAX_N],dis[MAX_N];
int ans[MAX_N];
vector<pair<int ,int > > vt[MAX_N];
vector<pair<long long ,int > >q;
void dfs(int x,int FA)
{
    ans[x] = 1;
    ll tmp = dis[x] - arr[x];
    int pos = upper_bound(q.begin(),q.end(),make_pair(tmp,0))-q.begin();
    pos--;
    if(pos>=0) ans[q[pos].second]--;
    q.push_back(make_pair(dis[x],x));
    int sz = vt[x].size();
    for(int i = 0;i<sz;++i)
    {
        int v = vt[x][i].first;
        if(v==FA) continue;
        dis[v] = dis[x]+vt[x][i].second;
        dfs(v,x);
        ans[x]+=ans[v];
    }
    q.pop_back();
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i) scanf("%lld",&arr[i]);
    for(int i = 2;i<=n;++i)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        vt[a].push_back(make_pair(i,b));
        vt[i].push_back(make_pair(a,b));
    }
    dfs(1,0);
    for(int i = 1;i<=n;++i) i==n?printf("%d\n",ans[i]-1):printf("%d ",ans[i]-1);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用的内容,CodeForces的初始分由1500改为了1400,并且前六场的初始分配如下:第一场500分,第二场350分,第三场250分,第四场150分,第五场100分,第六场50分。所以,根据你在第一场的表现分为368,你的总分应为868(1400+368)。接下来的五场比赛,你的表现分将根据具体情况来决定。每场比赛的表现分会对你的总分产生影响。 关于其他引用和的代码,它们似乎是一些针对不同情况进行计算和输出的算法,并不直接涉及到CodeForces上的分数计算。所以,如果你有关于CodeForces上分的具体问题,请提供更多详细信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [CodeForces前六场定级赛赋分规则(2020.5修订)及各段位对应分数段](https://blog.csdn.net/Sunshine_xiaohao/article/details/112106625)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [CodeForces上分日记 (思维题)(A. Garland)1809A (Educational Round 145 For Div.2)](https://blog.csdn.net/weixin_60375636/article/details/130243342)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [【codeforces】一切为了上分:骚操作合集](https://blog.csdn.net/weixin_45497996/article/details/109157711)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值