两个二分 枚举位数

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll ten[];
ll check1(ll x) {
ll ans = ;
ll l, r;
for (ll i = ; i <= ; i++) {
l = ten[i], r = ten[i + ] - ;
if (r < x) {
ans += i * ( * x - l - r) * (r - l + ) / ;
} else {
ans += i * (x - l) * (x - l + ) / ;
break;
}
}
return ans;
}
ll check2(ll x) {
ll ans = ;
ll l, r;
for (ll i = ; i <= ; i++) {
l = ten[i], r = ten[i + ] - ;
if (r <= x) {
ans += i * (r - l + );
} else {
ans += i * (x - l + );
break;
}
}
return ans;
}
int main () {
ten[] = ;
for (int i = ; i <= ; i++) {
ten[i] = ten[i - ] * 10LL;
}
int Q;
scanf("%d", &Q);
while (Q--) {
ll n;
scanf("%lld", &n);
ll l = , r = 1e9, mid;
while (l < r - ) {
mid = (l + r) >> ;
if (check1(mid) < n) {
l = mid;
} else {
r = mid;
}
}
n -= check1(r - );
if (n == ) {
printf("%d\n", (r - ) % );
continue;
}
l = ;
r = 1e9;
while (l < r - ) {
mid = (l + r) >> ;
if (check2(mid) < n) {
l = mid;
} else {
r = mid;
}
}
n -= check2(r - );
int len = ;
ll xxx = r, xxxx = r;
while (xxx > ) {
xxx /= 10LL;
len++;
}
len -= n;
if (len < ) {
continue;
}
while (len--) {
xxxx /= ;
}
printf("%lld\n", xxxx % );
}
}

Codeforces 1216E2 枚举位数+二分的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. Codeforces 807C - Success Rate(二分枚举)

    题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...

  3. Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))

    题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...

  4. Codeforces 912 E.Prime Gift (折半枚举、二分)

    题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...

  5. Codeforces 912E Prime Gift ( 二分 && 折半枚举 && 双指针技巧)

    题意 : 给你 N ( 1 ≤ N ≤ 16 ) 个质数,然后问你由这些质数作为因子的数 ( 此数不超 10^18 ) & ( 不一定需要其因子包含所给的所有质数 ) 的第 k 个是什么 分析 ...

  6. Codeforces 888E:Maximum Subsequence(枚举,二分)

    You are given an array a consisting of n integers, and additionally an integer m. You have to choose ...

  7. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  8. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  9. Codeforces - 773A - Success Rate - 二分 - 简单数论

    https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...

随机推荐

  1. tensorflow搭建神经网络

    最简单的神经网络 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt date = np.linspa ...

  2. 最新 顺网科技java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.顺网科技得等10家互联网公司的校招Offer,因为某些自身原因最终选择了顺网科技.6.7月主要是做系统复习.项目复盘.Lee ...

  3. REST架构中的HTTP动词

    POST 增 DELETE 删 PUT 改 GET 查 GET(SELECT):从服务器取出资源(一项或多项). POST(CREATE):在服务器新建一个资源. PUT(UPDATE):在服务器更新 ...

  4. Pycharm 配置houdini

    一.houdini开发环境配置 1.添加Python可执行文件 2.设置代码自动补全 刚刚添加的Python.exe,右侧点击加号,依次添加以上长方形中的文件,路径会根据个人安装路径有所变化,后面的目 ...

  5. LocalDate与Date转化

    // 01. java.util.Date --> java.time.LocalDateTimepublic void UDateToLocalDateTime() { java.util.D ...

  6. 怎样获取所有style节点

    通过 document.styleSheets 获取所有的样式表节点. document.styleSheets instanceof StyleSheetList; // true 注意: 1. 返 ...

  7. Java生成随机数列表

    生成随机数列表 1.Java8以前 (1)Math.random private List<UserEntity> random1() { ArrayList<UserEntity& ...

  8. QQ浏览器、搜狗浏览器等兼容模式下,Asp.NetCore下,Cookie、Session失效问题

    原文:QQ浏览器.搜狗浏览器等兼容模式下,Asp.NetCore下,Cookie.Session失效问题 这些狗日的浏览器在兼容模式下,保存Cookie会失败,是因为SameSiteMode默认为La ...

  9. Core项目部署到IIS上delete、put谓词不支持

    解决方法:在web.config的system.webServer结点下添加如下代码 <modules runAllManagedModulesForAllRequests="true ...

  10. VBA学习资料分享-3

    VBA创建/发送OUTLOOK邮件时怎么加上默认签名呢?用过OUTLOOK写邮件的人都知道,如果你设置了默认签名,那么在创建空白邮件的时候就会自动加上你设置的签名.根据这一特性,我们可以在用VBA创建 ...