Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
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
这道题就是直接暴力应该会超时,用前缀和处理一下就可以了(吐槽,一开始都没看懂题,本咸鱼就没读懂过带公式的题(╥╯^╰╥))
代码:
//B. Recursive Queries-前缀和
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stdlib.h>
using namespace std;
const int maxn=1e6+10;
int a[10][maxn];
int fun(int x){
if(x<10)return x;
int sum=1;
while(x){
sum*=x%10>0?x%10:1;
x/=10;
}
return fun(sum);
}
void qianzhuihe(){
for(int i=1;i<=1000000;i++)
a[fun(i)][i]++;
for(int i=1;i<10;i++){
for(int j=1;j<=1000000;j++)
a[i][j]+=a[i][j-1];
}
}
int main(){
qianzhuihe();
int t;
scanf("%d",&t);
while(t--){
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
printf("%d\n",a[k][r]-a[k][l-1]);
}
return 0;
}
Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))的更多相关文章
- Codeforces 932.B Recursive Queries
B. Recursive Queries time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)
靠这把上了蓝 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabyte ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个记忆化搜索. 接近O(n)的复杂度吧 [代码] #include <bits/stdc++.h> using nam ...
- Codeforces 932 C.Permutation Cycle-数学 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 932 A.Palindromic Supersequence (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分 ...
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A
2018-02-19 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 mega ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) D】Tree
[链接] 我是链接,点我呀:) [题意] 让你在树上找一个序列. 这个序列中a[1]=R 然后a[2],a[3]..a[d]它们满足a[2]是a[1]的祖先,a[3]是a[2]的祖先... 且w[a[ ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大 ...
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A】 Palindromic Supersequence
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 字符串倒着加到原串右边就好 [代码] #include <bits/stdc++.h> using namespace ...
随机推荐
- Vue木桶布局插件
公司最近在重构,使用的是Vue框架.涉及到一个品牌的布局,因为品牌的字符长度不一致,所以导致每一个的品牌标签长短不一.多行布局下就会导致每行的品牌布局参差不齐,严重影响美观.于是就有了本篇的木 ...
- 【mysql】[Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation ‘=
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
- CSS清除浮动8大方法
CSS清除浮动是每一位web前端工程师都要掌握的技术,也是让每一位刚入门的前端工程师感到头疼的问题, 下面就来讲一下CSS清除浮动的原理和各种解决方法,大家可以根据实际情况选择最佳的解决方案. 在用D ...
- day14-推导式和生成器表达式
1.推导式规则 [每一个元素或者是和元素相关的操作 for 元素 in 可迭代数据类型] ----------遍历之后挨个处理[满足条件的元素相关的操作 for 元素 in 可迭代数据类型 if 元素 ...
- 一键生成属于自己的QQ历史报告,看看你对自己的QQ了解程度有多深?
目录 一键生成属于自己的QQ历史报告,看看你对自己的QQ了解程度有多深? 简介 功能截图 如何运行 编写思路 main.py模块 qq_bot模块 tkinter_gui模块 static_data模 ...
- LeetCode(123) Best Time to Buy and Sell Stock III
题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an ...
- k短路模板
https://acm.taifua.com/archives/jsk31445.html 链接: https://nanti.jisuanke.com/t/31445 #include <io ...
- 菜单及CMenu类的使用
CMenu类的主要成员函数 BOOL LoadMenu(UINT nIDResource); 加载菜单资源,并将其附加到CMenu对象上.参数nIDResource指定了要加载的菜单资源的ID.如果菜 ...
- <原创> 通过PEB获得进程路径 (附完整工程)
完整工程:http://files.cnblogs.com/files/Gotogoo/%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86%E5%99%A8%28x86%26%2 ...
- 在从1到n的正数中1出现的次数 【微软面试100题 第三十题】
题目要求: 给定 一个十进制正整数N,写下从1开始,到N的所有整数,然后数一下其中出现的所有“1”的个数. 例如:N = 2,写下1,2.这样只出现了1个“1”. N = 12 ...