【Codeforces 1114F】Please, another Queries on Array?
Codeforces 1114 F
题意:给你一个序列\(a_{1\dots n}\),以及\(q\)次查询,每次查询有两种格式:
- TOTIENT \(l\) \(r\):求出\(\phi(\Pi_{i=l}^ra_i)\)。
- MULTIPLY \(l\) \(r\) \(x\):将从\(l\)到\(r\)的所有数乘上\(x\leq 300\)。
处理每次查询。
思路:首先我们知道设\(x=\Pi_{i=1}^np_i^{e_i}\),则\(\phi(x)=x\Pi_{i=1}^n\frac{p_i-1}{p_i}\)。
所以就可以想到记录每一个数的质因子有哪些。
由于这个序列的每个数都很小(\(a_i\leq 300\)),所以在此范围内的质数也不多(\(62\)个),然后就可以用一个\(long\ long\)存下了。
然后考虑高效地处理区间乘。
可以用分块和线段树来解决。(我只写了分块)
将原序列分成几块,每一个块的大小是\(B\),然后对于每个块存储以下信息:
- 这个块所有数的积以及该乘积所含质因数
- 这个块对于所有数同时乘的数以及这个数所含质因数
- 这个块中每个数的值(这个只在边角的修改上要存)以及这个数所含质因数
每个操作的具体处理:
- 修改:首先要改区间两边未在整块内的边角的每个数的值和整块的积,然后再将中间块的整块的同时乘的数都改为需要更改的数。
- 查询:也是一样,现将区间两边的数乘上整块都要乘的数乘到答案里,再将中间块整块的乘积乘进答案。
然后就会发现如果要更改整块的积时需要求一个数的\(B\)次幂,那么就预处理一下即可。
然后具体的实现中还要注意一下一点点细节。
【Codeforces 1114F】Please, another Queries on Array?的更多相关文章
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Codeforces 710F】String Set Queries
Codeforces 710 F 思路:KMP学的还是不过关啊... 按照字符串的长度分类,如果长度大于\(\sqrt{n}\)的就扔到什么地方等待查询,否则就扔进trie里面. 对于查询,我们先在t ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 797E】Array Queries
[题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【30.93%】【codeforces 558E】A Simple Task
time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【codeforces 602D】Lipshitz Sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750E】New Year and Old Subsequence
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【13.91%】【codeforces 593D】Happy Tree Party
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- hexo博客更新主题后上传Git操作
克隆主题: git clone https://github.com/SuperKieran/TKL.git _config.yml文件中主题改为新增主题 # Extensions ## Plugin ...
- 递归函数获得n个不重复的随机数
// 递归函数获取不重复的随机数 var arr_end; // 用于保存最后得到的数组 function suiji(n) { var arr = [] // 产生n个随机数加入数组 for(var ...
- Python 解决Python安装包时提示Unable to find vcvarsall.bat的问题
解决Python安装包时提示Unable to find vcvarsall.bat的问题 by:授客 QQ:1033553122 问题 Python安装包时,提示Unable to find v ...
- Jni OnLoad()和OnUnload()
除了前面说的自定义JNI函数之外,JNI还提供了两个特殊函数,它们是JNI_OnLoad()和JNI_OnUnload(),分别在加载库和卸载库的时候调用. 1.JNI_OnLoad() Java调用 ...
- 《数据库系统概念》1-数据抽象、模型及SQL
DBMS(database-management system)包括数据库和用于存取数据的程序,DBMS的基本目标是为数据的存取提供方便.高效的方式,此外对大多数企业来说,数据是非常重要的,所以DB ...
- Flutter 布局(八)- Stack、IndexedStack、GridView详解
本文主要介绍Flutter布局中的Stack.IndexedStack.GridView控件,详细介绍了其布局行为以及使用场景,并对源码进行了分析. 1. Stack A widget that po ...
- IP负载均衡
推荐一篇关于LVS的好文: https://www.cnblogs.com/gaoxu387/p/7941381.html 一.原博主要内容: 1.概述 IP负载均衡:四层负载,是基于IP+端口的负载 ...
- inode 耗尽
背景: 之前为了提升大硬盘mkfs文件系统的速度,使用了大文件选项 mkfs.ext4 -T largefile /dev/xvde1 没有仔细算能存多少文件,结果今天发现磁盘没用完,但inode用完 ...
- 探索哪个进程使磁盘I/O升高
如果生产环境中磁盘使用率突然升高,却不知道因为哪个应用程序导致的,这个时候我们可以使用pidstat命令来查看,比如 Linux .el7.x86_64 (ip.ec2.internal) _x86_ ...
- Hadoop2.7.6_04_HDFS的Shell操作与常见问题
1. HDFS的shell操作 1.1. 支持的命令及参数 [yun@mini05 zhangliang]$ hadoop fs Usage: hadoop fs [generic options] ...