codeforces 914 D 线段树+数学】的更多相关文章

题意 给出一个长度为\(n\)的数列\(a\),两种询问,第一种给出三个数\(l,r,x\),区间\([l,r]\)的\(gcd\)值是否和\(x\)相似,若最多改变区间\([l,r]\)中的一个数使区间\([l,r]\)的\(gcd\)值等于\(x\),则相似,第二种给出两个数\(i,y\),将\(a[i]\)变为\(y\). 分析 建一个线段树维护区间\(gcd\),这个线段树非常好写,因为是单点修改,所以不需要tag数组和pushdown,查询的时候用一个变量\(cnt\),记录区间\([…
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个点,初始时候每个点权值都为0,m次修改,对v的叶子节点且距离小于d的都加上x 也就是v以下d层包括v自身都加上x 问最后每个点的权值 现在一想 用线段树来维护就是很自然的事了 但是要维护什么值呢 维护的就是某个深度上增加的值 先更新 后回溯取消更新 详见代码注释 #include <cstdio>…
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of nn opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expressio…
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in other words, a string s* of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is describe…
http://codeforces.com/problemset/problem/91/B B. Queue time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output There are n walruses standing in a queue in an airport. They are numbered startin…
Description 在一片美丽的大陆上有100000个国家,记为1到100000.这里经济发达,有数不尽的账房,并且每个国家有一个银行.某大公司的领袖在这100000个银行开户时都存了3大洋,他惜财如命,因此会不时地派小弟GFS清点一些银行的存款或者让GFS改变某个银行的存款.该村子在财产上的求和运算等同于我们的乘法运算,也就是说领袖开户时的存款总和为3100000.这里发行的软妹面额是最小的60个素数(p1=2,p2=3,…,p60=281),任何人的财产都只能由这60个基本面额表示,即设…
Description Translated by @Nishikino_Maki from Luogu 行吧是我翻的 Mad scientist Mike has constructed a rooted tree, which consists of n n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numb…
题意: 有n个点,q个询问, 每次询问有一种操作. 操作1:u→[l,r](即u到l,l+1,l+2,...,r距离均为w)的距离为w: 操作2:[l,r]→u的距离为w 操作3:u到v的距离为w 最终求起点到其他点的最短距离,到达不了输出-1 题解 线段树优化建图+最短路... 不知道这种东西,百度了一下,好像最早的是POI2015的PUS,然后2017/2018的oi也都出过, 还是要见识一下的... 顺便记录一下,封装好的djisktra和graph 代码如下: #include <bit…
题目描述 给你一个长度为\(n\)的数列,第\(i\)个数为\(a_i\).每个数的质因子都只有前\(60\)个质数.有\(q\)个询问,每次给你\(l,r\),求\(\varphi(\prod_{i=l}^ra_i)\) 模数为\(19961993\),是个质数 \(n=100000,q\leq 100000\) 题解 水题 \[ \phi(x)=x\prod_{p_i|x}(1-\frac1{p_i}) \] 用线段树维护区间乘积和这个区间的乘积的质因子(每个质数有没有出现) 然后乱搞 时间…