HDU 1559 二维树状数组
来源:互联网 发布:win10 禁用windows 键 编辑:程序博客网 时间:2024/04/30 10:01
传送门:HDU 1559
模板题, 注意矩阵sum树状数组求和
AC code:
/*adrui's submission *Language : C++ *Result : Accepted *File Name: HDU 3333 *Favorite : Dragon Balls *love : yy *Standing in the Hall of Fame */#include<iostream>#include<cstring>#include<map>#include<algorithm>using namespace std;typedef long long LL;#define debug 0#define inf 0x3f3f3f3f#define M(a, b) memset(a, b, sizeof(a))#define lowbit(x) (x & (-x))const int maxn = 1000 + 5;int m, n, x, y;LL c[maxn][maxn];void add(int x, int y, LL v) { for (int i = x; i <= m; i += lowbit(i)) for (int j = y; j <= n; j += lowbit(j)) { c[i][j] += v; }}LL getSum(int x, int y) { LL res = 0; for (int i = x; i; i -= lowbit(i)) for (int j = y; j; j -= lowbit(j)) { res += c[i][j]; } return res;}int main() {#if debug freopen("in.txt", "r", stdin);#endif //debug cin.tie(0); cin.sync_with_stdio(false); int t; LL a; cin >> t; while (t--) { M(c, 0); cin >> m >> n >> x >> y; for (int i = 1; i <= m; ++i) for (int j = 1; j <= n; ++j) { cin >> a; add(i, j, a); } LL mx = -inf; for (int i = x; i <= m; ++i) for (int j = y; j <= n; ++j) { LL tmp = getSum(i, j) - getSum(i - x, j) - getSum(i, j - y) + getSum(i - x, j - y); mx = max(mx, tmp); } cout << mx << endl; } return 0;}
1 0
- HDU 1559 二维树状数组
- 二维树状数组 hdu 1892
- 【二维树状数组】HDU 1892
- HDU 1892 二维树状数组
- HDU 1892 二维树状数组
- HDU 2642 二维树状数组
- HDU 1892 (二维树状数组)
- HDU 1892 二维树状数组
- hdu 1892 二维树状数组
- hdu 2642 二维树状数组
- HDU 1892 二维树状数组
- hdu 1892 二维树状数组
- hdu 1892 树状数组,二维
- hdu 1890 二维树状数组
- HDU 2642 二维树状数组
- HDU 1892(树状数组二维)
- HDU 5517 二维树状数组
- HDU 5517 (二维树状数组)
- dubbo服务提供者的Maven构建流程
- 【java学习记录】8.输入三角形的三条边,计算三角形的周长
- 文章标题
- 测试使用word发布新浪博客
- 获得系统时间
- HDU 1559 二维树状数组
- Python __future__ 模块
- 最小二乘曲线拟合matlab实现
- ImageLoader的简易配置
- mt7620a上带机量的提高(三)
- strchr函数的用法
- 深入浅出JMS(二)--ActiveMQ简单介绍以及安装
- 09上机练习2
- 参照《第一行代码》开发CoolWeather (一)