. 样例输入复制 4 4 样例输出复制 14 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD=1e9+7,inv2=500000004,inv6=166666668; ll n,m; const int maxn=100000; ll A(ll x) { x %= MOD; return ((x * x) + x) % MOD; } ll mul(ll a, ll b) { a %=…
https://nanti.jisuanke.com/t/31448 题意 已知a序列,给你一个n和m求小于n与m互质的数作为a序列的下标的和 分析 打表发现ai=i*(i+1). 易得前n项和为 Sn=n*(n+1)(2*n+1)/6+n*(n+1)/2;我们直接求与m互质的数较难,所以我们可以换个思路,求与 m不互质的数,那么与m不互质的数,是取m的素因子的乘积(因为根据唯一分解定理,任意个数都可看作的素数积),那么我们将m分解质因数,通过容斥定理,就可以得道与m不互质的数,总和sum减去这…
这题很好啊,好在我没做出来...大概分析了一下,题目大概意思就是求 问所有满足1<=i<=n且i与m互素的ai之和 最开始我们队的做法是类似线性筛的方法去筛所有数,把数筛出来后剩下数即可,但是这样的是时间复杂度十分大,我们需要遍历每个质因 的倍数,这样最坏的复杂度是很大的1e8,因为我们需要把i的倍数筛到1e8,这样肯定不行,那么想想其他办法 我们想到了容斥-----(赛后想到的) 我们可以推处一个公式ai=i*i+i; 那么ai的前n项和Tn=n*(n+1)*(2*n+1)/6+n*(n+1…
可推出$a_n = n^2+n, $ 设\(S_n = \sum_{i=1}^{n} a_i\) 则 \(S_n = \frac{n(n+1)(2n+1)}{6} + \frac{n(n+1)}{2}\) 需要求出\([1,N]\)中与\(M\)互质的下标的和 可以容斥计算答案,\(O(1)\)时间算出\(S_n\),需要减去与\(M\)非互质的下标\(a_i\) 对于\(M\)的每一种质因数的组合\(k\),可以求出\(b_kn = (kn)^2+kn\),则也可以\(O(1)\)得到在\(b…
https://nanti.jisuanke.com/t/31448 解析 易得an=n*n+n O(1)得到前n项和  再删除与m不互素的数  我们用欧拉函数求出m的质因数  枚举其集合的子集 进行容斥 n*n+n+2n*2n+2n+3n*3n+3n=(1+4+9)*n*n+(1+2+3)*n 所以也可以O(1)得到. AC代码 #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi firs…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让你求出1..n中和m互质的位置i. 让你输出∑ai 这个ai可以oeis一波. 发现是ai = i(i+1) 1..n中和m互质的数字的个数之前有做过一题. 然后发现是逆着做的. 删掉不互质的.剩下的就是互质的了. 是用容斥原理搞的. 其中有ans+=n/temp和ass-=n/temp 表示的是加上temp,2temp,3temp...ttemp这些数字 以及减去temp,2temp,3temp...t*temp这些数字 放…
J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, you need to handle QQ operations. There're two types: 1\ L\ X1 L X: Increase points by XX of all nodes whose depth equals LL ( the depth o…
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy ) means the wave is a rectangle whose vertexes are ( 00 , 00 ), ( xx ,…
https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集组成的数字是个素数或1. 分析 打表发现满足要求的数字很少.实际上因为一个数不能出现两次,而偶数不能存在.这样最后只有20个数符合要求. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ; ] = {,,,…
Supreme Number A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number N as the supreme number if and only if each number made up of an non-empty subse…
Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are N spots in the jail and MM roads connecting some of the spots. JOJO finds…
131072K   One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are NN spots in the jail and MM roads connecting some of the spots. JOJO finds tha…
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all…
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up sev…
G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secre…
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N), and each time a child is invited, Miss Li…
There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N), and each time a child is invited,…
A. Gudako and Ritsuka 链接 by Yuki & Asm.Def 期望难度:Hard- 考虑从后往前进行博弈动态规划,在这一过程中维护所有的先手必胜区间.区间不妨采用左开右闭,方便转移. 考虑一次转移,如果当前Servant的后一个位置属于对手,则当前Servant的必胜区间可以通过将后一个Servant的每个必败区间的左端点+1.右端点+x得到:如果后一个位置属于自己,则可以通过将后一个Servant的必胜区间做同样的操作得到.不妨分别对必胜区间左右端点维护一个偏移量,需要…
A. Gudako and Ritsuka 留坑. B. Call of Accepted 题意:定义了一种新的运算符$x d y$ 然后给出中缀表达式,求值 思路:先中缀转后缀,然后考虑如何最大如何最小,按题意模拟即可 #include <bits/stdc++.h> using namespace std; #define ll long long ]; ll suffix[]; ]; unordered_map <char, int> mp; inline void Init…
学长写的 F. Fantastic Graph "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundar…
题目链接: https://nanti.jisuanke.com/t/31452 AC代码(看到不好推的定理就先打表!!!!): #include<bits/stdc++.h> using namespace std; # define maxn 40000+100 int a[maxn]; int b[maxn]; int ans=0; char s[1000]; int c[maxn]; int ti=0; void f() { memset(c,0,sizeof(c)); memset(…
Ka Chang 思路: dfs序+树状数组+分块 先dfs处理好每个节点的时间戳 对于每一层,如果这一层的节点数小于sqrt(n),那么直接按照时间戳在树状数组上更新 如果这一层节点个数大于sqrt(n),那么直接存一下这一层每个节点的大小(都是一样的),这样的层数不会超过sqrt(n)层 然后查询的时候先在树状数组查询答案,然后再遍历第二种层数,加到答案中 复杂度:n*sqrt(n)*log(n) 代码: #pragma GCC optimize(2) #pragma GCC optimiz…
Given a rooted tree ( the root is node 1 ) of N nodes. Initially, each node has zero point. Then, you need to handle Q operations. There're two types: 1 L X: Increase points by X of all nodes whose depth equals L ( the depth of the root is zero ). (x…
题意: 二分图 有k条边,我们去选择其中的几条 每选中一条那么此条边的u 和 v的度数就+1,最后使得所有点的度数都在[l, r]这个区间内 , 这就相当于 边流入1,流出1,最后使流量平衡 解析: 这是一个无源汇有上下界可行流 先添加源点和汇点 超级源超级汇  跑遍dinic板子 就好了...看了一发蔡队的代码,学到了好多新知识(逃)... #include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a)) #define r…
求第k短路 模板题 套模板即可 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <queue> using namespace std; ; ; struct State{ int f; // f=g+dis dis表示当前点到终点的最短路径,即之前的预处理 int g; //g表示到当前点的路径长度 int u; bool op…
思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> #include<stack> #include<string> #include<cmath> #include<vector> #include<cstdio> #include<iostream> #include<algori…
G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N) and each time a child is inv…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 点可以重复走的k短路. [代码] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define all(x) x.begin(),x.end() #define pb push_bac…
原题链接:https://nanti.jisuanke.com/t/31450 附上队友代码:(感谢队友带飞) #include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define DOR(i,a,b) for(int i=(a);i>=(b);--i) const int maxN=2e5+5,inf=0x3f3…
https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. 贪心做法: 考虑两个集合A和B,A为L<=d[i]<=R,B为d[i]>R 枚举每个边 1.如果u和v都在B集合,直接删掉2.如果u和v都在A集合,无所谓3.如果u在B,v在A,并且v可删边即d[v]>L4.如果u在A,v在B,并且u可删边即d[u]>L 最后枚举N+M个点判断是…