原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109E.html 题意 给定一个长度为 n 的数列 a,以及一个模数 M(不一定是质数). 要求支持 q 次以下操作: 区间乘 单点除(保证能够整除) 区间求和,最终结果对 M 取模输出. $$n,q\leq 10^5$$ 题解 这里我们设 $f(x)$ 表示 $\frac x {\gcd(x,M)}$ . 令 $c(x,i)$ 表示 x 最多能够整除 M 的第 $i$ 个质因子的 $c(x,i)$ 次…
题目简述:给定$m \leq 10^9+9$,维护以下操作 1. "1 l r x":将序列$a[l], a[l+1], \dots, a[r]$都乘上$x$. 2. "2 p x":将$a[p]$除以$x$,保证可整除. 3. "3 l r":求$(a[l]+a[l+1]+\dots+a[r]) \bmod m$. 解:code 除了操作2以外,都显然可以用线段树维护. 主要遇到的问题是$m$不一定是质数,不妨设$m = p_1^{m_1} p…
如果mod是质数就好做了,但是做除法的时候对于合数mod可能没有逆元.所以就只有存一下mod的每个质因数(最多9个)的幂,和剩下一坨与mod互质的一部分.然后就能做了.有点恶心. CODE #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 100005; const int MAXP = 9; int n, q, a[MAXN], p[MAXP], cnt, mod, phi…
[Codeforces 464E] The Classic Problem(可持久化线段树) 题面 给出一个带权无向图,每条边的边权是\(2^{x_i}(x_i<10^5)\),求s到t的最短路\(\mathrm{mod} \ 10^9+7\)的值 分析 显然边权存不下,由于取模会影响大小关系,不能直接取模然后跑dijkstra 考虑用可持久化线段树维护每个点到起点的距离(二进制表示),即维护一个01序列,[1,n]从低位到高位存储. 修改的时候我们要把第i位+1,如果第i位是0,直接取反就可以…
E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r…
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The New Year holidays are over, but Resha doesn't want to throw away the N…
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c…
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Description One day, a useless calculator was being built by Kuros. Let's assume that number X is showed on the screen of calculator. At first,…
https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的一个 查询强制在线 题解: 显然,暴力就是,对于每次搜索深搜距离x小于$k$的所有点搜索 那么我们考虑优化 首先,查询对$x$距离小于$k$的所有点,等价于在整颗树上,查询$\forall dep(x)≤dep(i)≤dep(x)+k$中,在$x$子树中的点的最小值 那么,一个大胆的想法就是,对于每…
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干需要花费bi时间,有两个玩家,玩家一可以移动到当前点的子节点也可以申请游戏结束返回根节点并吃沿途的饼干,玩家二可以删除当前点到儿子节点的一条边,走路和吃饼干都消耗时间,会给出一个总时间,在总时间内尽可能的多吃饼干,问最多能吃多少个? 思路: 由于是玩家一先手,那么最开始的最大边则不会被删除,但之后路…