Codeforces 932.B Recursive Queries
2 seconds
256 megabytes
standard input
standard output
Let us define two functions f and g on positive integer numbers.
You need to process Q queries. In each query, you will be given three integers l, r and k. You need to print the number of integers xbetween l and r inclusive, such that g(x) = k.
The first line of the input contains an integer Q (1 ≤ Q ≤ 2 × 105) representing the number of queries.
Q lines follow, each of which contains 3 integers l, r and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).
For each query, print a single line containing the answer for that query.
4
22 73 9
45 64 6
47 55 7
2 62 4
1
4
0
8
4
82 94 6
56 67 4
28 59 9
39 74 4
3
1
1
5
In the first example:
- g(33) = 9 as g(33) = g(3 × 3) = g(9) = 9
- g(47) = g(48) = g(60) = g(61) = 6
- There are no such integers between 47 and 55.
- g(4) = g(14) = g(22) = g(27) = g(39) = g(40) = g(41) = g(58) = 4
题目大意:f(x)的值是x非零数位的乘积.q组询问,每次问[l,r]之间的x,有多少g(x) = k;
分析:多组询问想到预处理,每次问个数想到前缀和,那么预处理一个前缀和就好了.
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; int q,a[],sum[][]; int solve(int x)
{
if (x < )
return x;
if (a[x])
return a[x];
int res = ;
while (x)
{
int temp = x % ;
if (temp != )
res *= temp;
x /= ;
}
return a[x] = solve(res);
} int main()
{
scanf("%d",&q);
for (int i = ; i <= ; i++)
{
if (i < )
a[i] = i;
else
a[i] = solve(i);
}
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
sum[i][j] += sum[i - ][j];
sum[i][a[i]]++;
}
while (q--)
{
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
printf("%d\n",sum[r][k] - sum[l - ][k]);
} return ;
}
Codeforces 932.B Recursive Queries的更多相关文章
- Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
B. Recursive Queries time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- sql server: Graphs, Trees, Hierarchies and Recursive Queries
--------------------------------------------------------------------- -- Chapter 09 - Graphs, Trees, ...
- sql script: Graphs, Trees, Hierarchies and Recursive Queries
--------------------------------------------------------------------- -- Inside Microsoft SQL Server ...
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- CodeForces - 369E Valera and Queries(树状数组)
CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...
- codeforces 1217E E. Sum Queries? (线段树
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...
- 笔记-Recursive Queries
Recursive Queries \[m_{l,r}=\textrm{id}(\max_{i=l}^r a_i)\\ f(l,r)= \begin{cases} (r-l+1)+f(l,m_{l,r ...
- Codeforces 1117G Recursive Queries [线段树]
Codeforces 洛谷:咕咕咕 思路 设\(L_i,R_i\)为\(i\)左右第一个大于它的位置. 对于每一个询问\(l,r\),考虑区间每一个位置的贡献就是\(\min(r,R_i-1)-\ma ...
- 前缀和:CodeForces 932B Recursive Queries
Description Let us define two functions f and g on positive integer numbers. You need to process Q q ...
随机推荐
- 用python画小猪佩奇(非原创)
略作改动: # coding:utf-8 import turtle as t t.screensize(400, 300, "blue") t.pensize(4) # 设置画笔 ...
- MySQL数据库 : 查询语句,连接查询及外键约束
查询指定字段 select 字段1,字段2 from 表名; 消除重复行(重复指的是结果集中的所有完全重复行) select distinct 字段1,字段2.. ...
- Laravel操作上传文件的方法
1.获取上传的文件 $file=$request->file('file');2.获取上传文件的文件名(带后缀,如abc.png) $filename=$file->getClientOr ...
- 【word】html转doc的小研究
html转doc,页眉页脚丢失 html 转 doc,是全屏铺满(缩放级别很高)
- rpm、yum命令
一.rpm命令 挂载光盘文件到/media目录: 进去/media目录下的Packages目录: 查看系统已安装的所有rpm包: 查看系统是否安装dhcp软件包: 安装dhcp软件包: 查看dhcp软 ...
- wordCount的执行流程
我们对于wordCount的这个流程,在清晰不过了,不过我们在使用spark以及hadoop本身的mapReduce的时候,我们是否理解其中的原理呢,今天我们就来介绍一下wordCount的执行原理, ...
- Python 探测图片文件类型
Table of Contents 1. 探测图片类型 1.1. python magic 1.2. imghdr 1.3. PIL.Image 探测图片类型 今天遇到一个小问题,如何探测图片的文件类 ...
- TouTiao开源项目 分析笔记18 视频详情页面
1.效果预览 1.1.需要做到的真实效果 1.2.触发的点击事件 在MediaArticleVideoViewBinder的每一个item点击事件中: VideoContentActivity.lau ...
- 1- js vue.js
1 js 2 Vue.js
- tools.jar seem to ....
android stadio 运行不起来,可以在java_home原来的路径下加一个\, 然后就可以运行起来了.