随笔分类 - 前缀和、差分
摘要:题目链接:https://ac.nowcoder.com/acm/problem/16722 差分模版 #include <bits/stdc++.h> using namespace std; #define ll long long ll sum[1000005]; ll a[1000005];
阅读全文
摘要:题目链接:https://www.luogu.com.cn/problem/P5638 前缀和模拟 #include<bits/stdc++.h> using namespace std; const int max_n=1e6+10; int n, k; long long a[max_n]; l
阅读全文
摘要:题目链接:https://www.luogu.com.cn/problem/P1387 二维前缀和模版题 #include<bits/stdc++.h> using namespace std; int n, m, a[105][105], s[105][105]; int ans; int mai
阅读全文
摘要:题目链接:https://www.luogu.com.cn/problem/P8649 方法一:模拟暴力(20分) #include<bits/stdc++.h> using namespace std; const int max_n=100010; int n, k, a[max_n]; lon
阅读全文
摘要:最大の和 #include<bits/stdc++.h> using namespace std; int n, k; int a[100010]; long long per_sum[100010], ans; int main() { cin>>n>>k; for(int i=1; i<=n;
阅读全文
摘要:[例题]一维前缀和 #include<bits/stdc++.h> using namespace std; int n, m; int a[100010]; long long per_sum[100010]; int l, r; int main() { cin>>n>>m; for(int i
阅读全文
摘要:U69096 前缀和的逆 #include<bits/stdc++.h> using namespace std; int n, a[10010]; int main() { cin>>n; for(int i=1; i<=n; i++)cin>>a[i]; for(int i=1; i<=n; i
阅读全文
摘要:题目链接 方法一:纯模拟50分 #include<bits/stdc++.h> using namespace std; int n, m; int a[100010]; int l, r; int ans; int main() { cin>>n; for(int i=1; i<=n; i++)c
阅读全文
摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1282 方法一:暴力(40分) 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n, a[105][105], ans=-(1<<30), s
阅读全文
摘要:题目链接https://www.luogu.com.cn/problem/P1083 一、5分题解: 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 cout<<0; 6 return 0; 7 } View C
阅读全文
摘要:题目链接https://www.luogu.com.cn/problem/P3406 【解题思路】前缀和、查分 对于其中一小段,我们要么全部买纸票,要么全部刷卡。 所以我们只需要统计每一小段经过的总次数。 如果你暴力模拟统计的话,估计会tle。 怎么快速知道每一段次数呢? 我们回忆一下“借教室”这道
阅读全文
摘要:题目链接https://www.luogu.com.cn/problem/P3397 题目数据很水,但是差分的模版题 方法一:模拟 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n, m; 4 int sx, sy, ex, ey; 5
阅读全文
摘要:【问题描述】 给出一个n*m的矩阵,多次询问子矩阵中数字之和。 【输入格式】 第一行包含三个正整数n, m, k(n, m<=5000, k<=10000),分别表示矩阵行数和列数以及询问次数。 接下来的n行,每行包含m个整数(整数不超过10000),描述该矩阵。 接下来的k行询问,数据描述子矩阵左
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1115 方法一:0分代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n, a[210000]; 4 int ans=-(1<<30); 5 int sum(
阅读全文
摘要:解决子数组问题 二维前缀和详解 前缀和、二维前缀和与差分的小总结 前缀和 和 差分模版 》》图示 二维前缀和练习
阅读全文