如果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…
A. In Search of an Easy Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as poss…
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就没啥难度了... #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #defin…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离恰好是 m 的有几个. $$n,m\leq 10^6$$ 题解 首先显然 a 和 b 的具体值是没用的. 于是我们就可以直接计数: 枚举树链 ab 上除了 a 和 b 有几个节点,假设是 i 个节点,那么这种情况下的方案总数是多少? 首先,ab 路径上 i+1 条 [1,m] 的边的和是 m ,共有…
思路及博客:https://www.cnblogs.com/uid001/p/10507346.html 代码: #include <bits/stdc++.h> #define LL long long #define ls(x) (x << 1) #define rs(x) ((x << 1) | 1) using namespace std; const int maxn = 100010; int m; int p[20], b[maxn], tot, re[1…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举最大值和最小值在什么地方. 显然,只要包含最小值的区间,都让他减少. 因为就算那个区间包含最大值,也无所谓,因为不会让答案变小. 但是那些不包含最大值的区间却能让差值变大. 所以没有问题. [代码] #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 300; int n,m; int a[N+10],segl[N+10],…
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有多少个长度为偶数的连续区间,使得其前一半的异或和等于后一半的异或和. 题解 显然就是求长度为偶数且异或和为\(0\)的区间个数 求异或和为\(0\)的区间个数很简单,对于整个区间求异或前缀和看看有多少个相等就好了. 求长度为偶数的也很简单,把每个位置的异或前缀和按照位置的奇偶性分开求个数每次计算一下…
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l,r]\)满足\([l,mid]\)的异或和等于\([mid+1,r]\)的异或和. solution 等价于询问有多少长度为偶数的区间异或和为\(0\). 只需要两个位置的异或前缀和与下标奇偶性相同即可组成一个合法区间. #include<cstdio> #include<algorith…
[CF734F]Anton and School(构造) 题面 Codeforces 洛谷 题解 算是一道\(easy\)? 发现\((a\&b)+(a|b)=a+b\). 那么根据给定条件我们就能确定唯一的\(a\)数列,最后再带回去\(check\)一下就做完了??? #include<iostream> #include<cstdio> using namespace std; #define ll long long #define MAX 200200 inlin…
一般搜索 注意:一般定义成void Books Exchange (easy version) CodeForces - 1249B2 The only difference between easy and hard versions is constraints. There are nn kids, each of them is reading a unique book. At the end of any day, the ii-th kid will give his book…
Problem Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem Description Input The first line contains one string s (1≤|s|≤5000) — the initial name, which consists only of lowercase Latin letters. It is guarante…
Problem Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem Description Input The first line contains one integer n (2≤n≤3⋅10^5) — the size of the array. The second line contains n integers a1,a2,…,an (0≤ai<2^…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…