luogu P1549 棋盘问题(2) 题解 题目描述 在\(N * N\)的棋盘上\((1≤N≤10)\),填入\(1,2,-,N^2\)共\(N^2\)个数,使得任意两个相邻的数之和为素数. 例如:当\(N=2\)时,有: 其相邻数的和为素数的有: \(1+2,1+4,4+3,2+3\) 当\(N=4\)时,一种可以填写的方案如下: 在这里我们约定:左上角的格子里必须填数字\(1\). 输入输出格式 输入格式: 一个数\(N\) 输出格式: 如有多种解,则输出第一行.第一列之和为最小的排列方…
题目链接:https://www.luogu.org/problemnew/show/P2762 算是拍照那个题的加强下. 输入真的很毒瘤.(都这么说但好像我的过了?) #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; con…
题目链接:https://www.luogu.org/problemnew/show/P2146 变量名真毒瘤 我真的再也不把l,left,r,right弄反了 反向思维更好做一些 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long #define lson left, mid, rt<<1 #defi…
题目链接:https://www.luogu.org/problemnew/show/P1314 二分答案 但是计算区间贡献的时候 直接暴力会挂 前缀和加速 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; const int maxn = 2000000 + 10; l…
题目链接:https://www.luogu.org/problemnew/show/P2590 我想学树剖QAQ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 31000; int fa[maxn], dep[maxn], size[maxn], son[maxn], to…
题目链接:https://www.luogu.org/problemnew/show/P3709 离散化+区间众数..? #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn = 500000+10; inline int read() { int k=0; char c; c=getcha…
题目链接:https://www.luogu.org/problemnew/show/P4113 为什么要卡莫队!为什么加强的这么毒瘤! 莫队可以拿100分剩下三个点没治了 // luogu-judger-enable-o2 #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ri regist…
题目链接:https://www.luogu.org/problemnew/show/P1972 真是不懂为什么要卡莫队! #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 2000100; int a[maxn], n, m, an…
题目链接:https://www.luogu.org/problemnew/show/P4462 ax+ax-1+...+ay = cntx+cnty 这样把一段序列变成两段相加跑莫队. #include <cstdio> #include <algorithm> #include <iostream> #include <cmath> using namespace std; ; , curL = , answer,a[maxn], ans[maxn],…
题目链接:https://www.luogu.org/problemnew/show/P1903 裸的...带修莫队... 比较麻烦吧(对我来说是的) 两个变量分开记录查询和修改操作. #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #define ri register using namespace std; ; , qnum = , unum = ,…