【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
写个记忆化搜索。
接近O(n)的复杂度吧
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int g[N+10];
int pre[N+10][20];
int f(int x){
int temp = 1;
while (x){
if (x%10!=0)
temp*=(x%10);
x/=10;
}
return temp;
}
int dfs(int x){
if (g[x]!=0) return g[x];
if (x<10){
return g[x] = x;
}else{
return g[x] = dfs(f(x));
}
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
for (int i = 1;i <= N;i++)
if (g[i]==0) dfs(i);
for (int i = 1;i <= N;i++){
for (int j = 1;j <= 9;j++)
pre[i][j] = pre[i-1][j];
if (g[i]<=9) pre[i][g[i]]++;
}
int q;
cin >> q;
while (q--){
int l,r,x;
cin >> l >> r >> x;
cout<<pre[r][x]-pre[l-1][x]<<endl;
}
return 0;
}
【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries的更多相关文章
- 【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 ...
- 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)
靠这把上了蓝 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabyte ...
- 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 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 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- hiho 1572 - set.upper_bound,排序树
链接 小Hi家的阳台上摆着一排N个空花盆,编号1~N.从第一天开始,小Hi每天会选择其中一个还空着花盆,栽种一株月季花,直到N个花盆都栽种满月季. 我们知道小Hi每天选择的花盆的编号依次是A1, A2 ...
- 路飞学城Python-Day16
- Spring 与CXF整合(spring3.2,cxf3.1.11)
1,jar包导入,从官网下载zip文件后里面会有很多jar包,哪些必须哪些不是必须,我能力有限,从其他人那参考了导入的一下jar包. 2.配置相关文件 web.xml中配置servlet <se ...
- springMVC 定时器配置
1.在springMVC中加入 xmlns:task="http://www.springframework.org/schema/task" http://www.springf ...
- k8s日志收集配置
容器日志样例 172.101.32.1 - - [03/Jun/2019:17:14:10 +0800] "POST /ajaxVideoQueues!queryAllUser.action ...
- 物理机安装CentOS7
最近捯饬到一台很老的机器,装Win7吧卡的不要不要的,思来想去的,搞个CentOS来玩玩,玩玩python的一些个人项目,一般装机啥的,都要做启动盘啥的,但是,这个都的话有很多网友已经分享了很多好的文 ...
- Mysql学习总结(21)——MySQL数据库常见面试题
1. 如何使用SELECT语句找到你正在运行的服务器的版本并打印出当前数据库的名称? 答:下面的语句的结果会显示服务器的版本和当前的数据库名称 mysql> SELECT VERSION(), ...
- 洛谷 P2744 [USACO5.3]量取牛奶Milk Measuring
P2744 [USACO5.3]量取牛奶Milk Measuring 题目描述 农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最 ...
- exadata(硬件更换文档部分)
Maintaining Flash Disks Replacing a Flash Disk Due to Flash Disk Failure Each Exadata Storage Server ...
- 移植u-boot-2014.4到S5PV210/TQ210(完整)
本文很多其它的是教会大家怎样学习 1.1 概述 1.2 u-boot配置过程分析 1.3 u-boot编译过程分析 1.4 SPL 1.5 加入自己的单板 1.6 移植u-bo ...