题目链接: https://vjudge.net/problem/1377985/origin 题目大意就是要你把一个数字拆开,然后相乘. 要求得数要小于9,否则递归下去. 这里用到一个递归函数: int f(int x) { ) return x; ; while(x) { != ) ans *= x%; ; x /= ; } return f(ans); } 这个函数用来求得一个数字最终得到的那个k值是多少. 然后开一个二元数组记录一下,并且用到了前缀和,统计从1开始k值出现的次数:(打表)…
Description 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…
Codeforces 洛谷:咕咕咕 思路 设\(L_i,R_i\)为\(i\)左右第一个大于它的位置. 对于每一个询问\(l,r\),考虑区间每一个位置的贡献就是\(\min(r,R_i-1)-\max(l,L_i+1)+1\),加起来就是 \[ r-l+1+\sum_{i=l}^r \min(r,R_i-1)-\sum_{i=l}^r \max(l,L_i+1) \] 后面那两个东西显然可以差分后用线段树搞. 代码 #include<bits/stdc++.h> clock_t t=cloc…
B. Recursive Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output 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…
940C链接:http://codeforces.com/problemset/problem/940/C C. Phone Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output And where the are the phone numbers? You are given a string s consist…
[Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You should perform n queries. There are three different types of queries: 1 l r — Add all missing numbers from the interval [l, r] 2 l r — Remove all present…
--------------------------------------------------------------------- -- Inside Microsoft SQL Server 2008: T-SQL Querying (MSPress, 2009) -- Chapter 12 - Graphs, Trees, Hierarchies and Recursive Queries -- Copyright Itzik Ben-Gan, 2009 -- All Rights…
--------------------------------------------------------------------- -- Chapter 09 - Graphs, Trees, Hierarchies and Recursive Queries --图,树,层次结构,递归查询 --------------------------------------------------------------------- -----------------------------…
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\(\sum_{i=l}^r a_i(i-l+1)^k \mod 10^9+7\) \(n,m \leq 10^5,k \leq 5\) 分析 根据二项式定理 \[(i-l+1)^k=\sum_{j=0}^k (-1)^{k-j} C_{k}^j i^j(l-1)^{k-j}\] 那么 \(\begi…
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}-1)+f(m_{l,r}+1,r)&\textrm{if } l\le r\\ 0&\textrm{else}\\ \end{cases} \] 设 \(L_i=\max\{j\}(j<i,a_j>a_i)\),\(R_i=\min\{j\}(j>i,a_j>a_i…