首页 > 其他分享 >[CF1870F] Lazy Numbers

[CF1870F] Lazy Numbers

时间:2023-10-10 22:00:54浏览次数:33  
标签:va Lazy int res ll mid UP Numbers CF1870F

Lazy Numbers
我觉得本题难度在于银剑的构造......
我们把 k 进制下的数去掉前导零放在 Trie 树上,并且越高位的深度越小,这样我们看出某个节点的 dfs 序就是排名,称排名减数值为 va。我们需要求 va=0 的点数。

不难发现某一深度从左往右的 va 单调不降,所以可以二分求出每层的点数。

然后求 dfs 序可以手玩,于是就没了。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll __int128_t
const int UP=65;
int T,dep;
ll n,k,LL[UP],RR[UP],b[UP],Ans;
ll read(){
    ll x=0;
    char s=getchar();
    while(s<'0'||s>'9'){
    	s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		s=getchar();
	}
	return x;
}
void prt(ll va){
    if(va>(ll)9) prt(va/10);
    putchar(va%10+'0');
}
ll calc(ll x){
    ll res=0,tmp=0;int de=0;
    while(x){b[++de]=x%k;x/=k;}
    for(int i=1;i<=de/2;i++) swap(b[i],b[de-i+1]);
    for(int i=1;i<=de;i++){
        tmp=tmp*k+b[i];
        res+=min(tmp,RR[i])-LL[i]+1;
    }
    for(int i=de+1;i<=dep;i++){
        tmp*=k;
        res+=min(tmp-1,RR[i])-LL[i]+1;
    }
    return res;
}
int main (){
    T=(int)read();
    while (T--){
        n=read();k=read();dep=0;
        Ans=(ll)0;
        for(ll va=1;va<=n;va*=k){
        	dep++;
            LL[dep]=va;RR[dep]=min(va*k-(ll)1,n);
        }
        ll mid,res,res1,res2,L,R;
        for (ll i=1;i<=dep;i++){
            L=LL[i];R=RR[i];
            res1=0;res2=0;
            while(L<=R){
                mid=(L+R)>>(ll)1;
                res=calc(mid)-mid;
                if(res==(ll)0) res1=mid;
                if(res<(ll)0) L=mid+1;
                else R=mid-1;
            }
            if(res1==(ll)0) continue;
            L=LL[i];R=RR[i];
            while (L<=R){
                mid=(L+R)>>(ll)1;
                res=calc(mid)-mid;
                if(res==(ll)0) res2=mid;
                if(res>(ll)0) R=mid-1;
                else L=mid+1;
            }
            Ans+=res2-res1+(ll)1;
        }
        prt(Ans);printf("\n");
    }
    return 0;
}
 

标签:va,Lazy,int,res,ll,mid,UP,Numbers,CF1870F
From: https://www.cnblogs.com/StranGePants/p/17755842.html

相关文章

  • Travelling Salesman and Special Numbers
    prologue模拟赛的一道题,结果没做出来,丢大人,败大兴。所以过来糊一篇题解。analysis我们看到数据范围这么大,那么肯定不可以一个一个遍历(废话),所以就要考虑这个题目的性质。我们先假设,极端数据\(2^{1000}-1\),这个数字中包含了\(999\)个1(正好感冒了能不能让我喝了)。下一次......
  • Androidstudio中 unable to execute Clang-tidy clazy-standalone is not found or ca
    这个问题可能是因为AndroidStudio不支持clazy,但是在设置菜单中仍然提供了这个选项,并且在这种情况下,它似乎被启用了¹。当通过clangd启用clang-tidy时,没有什么需要做的。当通过clangd禁用clang-tidy时,如果启用了clazy,就会出现这个错误¹。要解决这个问题,你可以尝试以下步骤:1.转......
  • vulnhub - lazySysAdmin - writeup
    信息收集可以看到目标开放了常见的22,80,139,445,3306这个6667的服务少见。root@kalitmp/lazySysAdmin»arp-scan-Ieth1-lInterface:eth1,type:EN10MB,MAC:00:0c:29:02:72:37,IPv4:192.168.56.102Startingarp-scan1.10.0with256hosts(https://github.com/r......
  • [LeetCode] 1352. Product of the Last K Numbers 最后 K 个数的乘积
    Designanalgorithmthatacceptsastreamofintegersandretrievestheproductofthelast k integersofthestream.Implementthe ProductOfNumbers class:ProductOfNumbers() Initializestheobjectwithanemptystream.voidadd(intnum) Appendsthei......
  • SQL Server: How to insert million numbers to table fast?
    YesterdayIattendedatlocalcommunityeveningwhereoneofthemostfamousEstonianMVPs–HennSarv–spokeaboutSQLServerqueriesandperformance.DuringthissessionwesawverycooldemosandinthispostingIwillintroduceyo......
  • 2023-09-08 小程序之启用组件按需注入 ==》 添加一行代码:"lazyCodeLoading": "require
    在manifest.json文件里面的mp-weix对象添加代码:"lazyCodeLoading":"requiredComponents"可实现组件按需注入,引用官方说法就是:启用按需注入后,小程序仅注入当前访问页面所需的自定义组件和页面代码。未访问的页面、当前页面未声明的自定义组件不会被加载和初始化,对应代码文件将不被......
  • React项目笔记-环境搭建、路由封装(跳转Navigate、懒加载lazy)、模块化样式引入、状态管
    环境准备nodev16.15.0npm8.5.5AntDesignofReact:https://ant.design/docs/react/introduce-cn一,创建项目npminitvite√Projectname:...vite-project-react√Selectaframework:»React√Selectavariant:»TypeScript然后使用vscode打开项目,由于......
  • 1521A - Nastia and Nearly Good Numbers
    A.NastiaandNearlyGoodNumbershttps://codeforces.com/problemset/problem/1521/A"""思路:1.就是普通的打印,NO的情况是只有b=1的时候才会出现,其他的都是YES,如果不想再继续分情况就把a*b放在中间做y,或者做x也可,避免(b-1)=1,最后要x+y=z"""forlinein[*open(0)......
  • [React Typescript] Strongly Typing Lazy Loaded Components with Generics
    Navigatingtothetypedefinitionfor lazy by CMD+click inlocalVSCode,orinthe DefinitelyTyped repo.Wecanseethefollowingdefinition:functionlazy<TextendsComponentType<any>>( factory:()=>Promise<{default:T}>):L......
  • CF1423K Lonely Numbers
    思路因为对于\(\gcd(a,b)\),\(\fraca{\gcd(a,b)}\),\(\fracb{\gcd(a,b)}\)中\(a\)和\(b\)是等价的,可以交换的。所以我们先令\(a>b\)。令\(\gcd(a,b)=d\),因为\(\fraca{\gcd(a,b)}\)有除法,所以我们应该想办法去除除法,就同乘以一个\(d\),即\(d^2\),\(a\),\(b\)三条边。......