给定一个长度为N的数列A,以及M条指令,每条指令可能是以下两种之一:
1、“C l r d”,表示把 A[l],A[l+1],…,A[r] 都加上 d。
2、“Q l r”,表示询问 数列中第 l~r 个数的和。
...
给定长度为N的数列A,然后输入M行操作指令。
第一类指令形如“C l r d”,表示把数列中第l~r个数都加d。
第二类指令形如“Q X”,表示询问数列中第x个数的值。
对于每个询问,输出一个整数表示答案。
#incl...
树状数组用于动态维护数组(矩阵)的前缀和,异或和,最大值,最小值。
(1)利用树状数组求逆序对O(nlogn)
楼兰图腾:y1~yn是1~n的一个全排列:
#include<iostream>
#include<cstring>
using n...
向量:
#include<iostream>
using namespace std;
const int N = 50010;
int d[N], father[N];
int n, k;
int find(int x){
if (x == father[...
银河英雄传说:
#include<iostream>
#include<cmath>
using namespace std;
int n;
const int N = 31010;
int father[N], d[N], size[N];
in...
程序自动分析:
(1)并查集(路径压缩)+离散化(数据过大):
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const in...
①先筛选出1~N的每个质数p
②N!中质因子p的个数为:
floor(N/p)+floor(N/p2)+floor(N/p3)+…+floor(N/pfloor(logpN))=Σ(pk≤N)floor(N/pk)
时间复杂度:O(NlogN)
...
SG函数的模板:
//f[N]:可改变当前状态的方式,N为方式的种类,f[N]要在getSG之前先预处理
//SG[]:0~n的SG函数值
//S[]:为x后继状态的集合
int f[N],SG[MAXN],S[MAXN];
void getSG(int n){
...
B城:
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e6 + 200;
long long h[...
time = 1; dfn[N] = { 0 }, low[N] = { 0 };
void dfs(int x){
stack.push(x);
dfn[x] = low[x] = time++;
for (int y = 0; y < n; ...
将行作为一个集合,将列作为另一个集合,进行二分图匹配,匹配数即匹配的边作为車的位置。
#include<iostream>
using namespace std;
const int N = 210;
int g[N][N], match[N], n, m, t;...
二分图的最大匹配:匈牙利算法
int n1, n2;
int h[N], next_pos[N], e[N], idx;
int match[N];
bool st[N];
bool find(int x){
for (int i = h[x]; i; i = next_...
#include<iostream>
#include<cstring>
using namespace std;
const int N = 20010;
const int M = 200010;
int h[N], e[M], next_pos[M]...
#include<iostream>
#include <string>
using namespace std;
class Base
{
public:
string content;
Base(string c)
{ conten...
二分图等价定义:不含奇数条边的环。
染色法:
(1)dfs,链式前向星
#include<iostream>
using namespace std;
const int N = 1010;
int h[N], e[N], next_pos[N], n,...
Description:一棵树,添加k条边使得遍历所有的点的总代价最小,其中1<=k<=2;
不建道路,路线总长度2*(n-1);
当k等于1,此时的最优解无疑是将边加到直径两端;那么答案就是2*(n-1)-d+1;其实考虑k=2时,对于一棵树,我们加边会形成一个环,加...
#include<iostream>
using namespace std;
int days[] = {0, 30, 31, 30, 31, 31, 30, 31, 30, 31};//4月之后每月的天数,第一个元素为0便于计数
string week[] =...
树的直径:树中所有最短路径的最大值。(1)树状dp(得到直径值);(2)若无负权边,2次DFS(BFS)得到直径值和最长链)
(1)在一个连通无向无环图中,以任意结点出发所能到达的最远结点,一定是该图直径的端点之一。
(2)树的直径,等于以树直径上任意一点为根的有根树,其左子树的高...
(1)最短路径树和最小生成树的区别:
最短路径树:源点到其它所有节点的最短路径构成的树。实际上是一个(DAG)
最小生成树:网络中任意两个顶点可达,且边集总长度最小,不能保证源点到其它点距离最小。
(2)求最短路径树的数量:乘法原理(记录每个节点的父节点可取数cnt[i]表示...
度受限的最小生成树:
给定一张N个点,M个边的无向图,求出无向图的一颗最小生成树,但是我们要求一号节点的入度不可以超过给定的整数S
也就是一个最小生成树,要求它的一号节点,最多只能和S个节点相连.
————&mdas...
dfs
应用:求最小生成树某一结点到其它各节点的路径上的最大边
#include<iostream>
using namespace std;
const int N = 100;
int n, m;
bool vis[N][N]; int g[N][N];...
并查集
将边升序排列,两个连通图之间增加(p*q-1)条边,最小增加的权值为(w+1)。
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 6010;...
https://blog.csdn.net/sugarbliss/article/details/86551050
拼尽全力,青春无悔!
在路上就是最好的状态,加油,结果不负有心人!
整除#include<bits/stdc++.h>
using namespace std;
int main(){
int count=0;
for(int i=100;i<=1000;i+...
#include <bits/stdc++.h>
C++语言中反转字符串的函数strrev(), reverse()
1:
char s[]="hello";
strrev(s);
puts(s);
return 0;
2:
...
#include <bits/stdc++.h>
using namespace std;
int main(){
int a[11];
int t;
 ...
这是行内嵌入公式$\surd, \sqrt{2}, \sqrt[n]{}, \sqrt[3]{\frac{x^3+y^3}{2}}$ ,文字和公式在同一行。
使用 $$1+1=2$$ 渲染时公式另起一行。
不换行两边用单个$包围,将latex公式放在中间
换行...
#include
#include
int a[101]={0};
int main()
{
int i,c,b;
scanf("%d",&b);
for(int i=0;i0){
printf("...
1.题目中12的阶乘非零数位为6,应该是5才对吧
2.麻烦大佬帮我看一看我的代码哪里错了,输入12是5,但输入10000000为0????
#include <iostream>
using namespace std;
int main()
{
&...