【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) B】Recursive Queries
2018-02-18 20:24
519 查看
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
写个记忆化搜索。
接近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) A】 Palindromic Supersequence
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) D. Tree(倍增)
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle
- 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) D】Tree
- D. Tree(ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- [Updating]ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- 【前缀和 && 思维转换】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)Molly's Chemicals
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 解题报告
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A. A Serial Killer(水题)
- 【解题报告】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 题解(A-E)
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) E. Team Work(dp)