Codeforces Round #439 (Div. 2) E. The Untended Antiquity (hash+数状数组)
来源:互联网 发布:linux telnet 退出 编辑:程序博客网 时间:2024/05/30 04:16
这个题,做出来的人很多,我感觉是数据不够强,我看了很多人的代码直接暴力也能过了,直接暴力如果数据够强的话肯定是时间超限,边缘数据不够强。如果和上次一样估计很多人的E会GG。我看到一位OIdalao的代码,认为这个是正确的解法,对每一道围墙进行hash处理,然后用二维的树状数组来解决这个问题。感觉博主已经写得简单易懂了。长了姿势
#include <bits/stdc++.h>using namespace std;map<pair<pair<int, int>, pair<int, int> >, int>g;int n, m, q;long long c[2520][2520];void R(int x, int y, long long z) {for (int i = x; i <= n; i += i & -i) {for (int j = y; j <= m; j += j & -j) {c[i][j] += z;}}}long long G(int x, int y) {long long re = 0;for (int i = x; i > 0; i -= i & -i) {for (int j = y; j > 0; j -= j & -j) {re += c[i][j];}}return re;}int rd() {return rand() << 15 | rand();}int main() {scanf("%d%d%d", &n, &m, &q);srand(time(0));for (int i = 0; i < 011; i++) {srand(rd());}for (int i = 0; i < q; i++) {int o, xa, xb, ya, yb;scanf("%d%d%d%d%d", &o, &xa, &ya, &xb, &yb);if (o == 1) {int u = rd();g[make_pair(make_pair(xa, ya), make_pair(xb, yb))] = u;R(xa, ya, u);R(xa, yb + 1, -u);R(xb + 1, ya, -u);R(xb + 1, yb + 1, u);} else if (o == 2) {int u = g[make_pair(make_pair(xa, ya), make_pair(xb, yb))];R(xa, ya, -u);R(xa, yb + 1, u);R(xb + 1, ya, u);R(xb + 1, yb + 1, -u);} else {long long va = G(xa, ya);long long vb = G(xb, yb);if (va == vb) {printf("Yes\n");} else {printf("No\n");}}}return 0;}
阅读全文
0 0
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity (hash+数状数组)
- Codeforces Round #439 (Div. 2) E:The Untended Antiquity(Hash+二维树状数组)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity(Hash)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity hash+二维树状数组或二维线段树
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维树状数组 随机化
- Codeforces Round #439 E. The Untended Antiquity (树状数组+随机化)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity(二维BIT)
- CF869E The Untended Antiquity(二维数状数组+差分+hash)
- codeforces 869E The Untended Antiquity 二维BIT + hash
- Codeforces 869 E. The Untended Antiquity 二维树状数组
- CF #439 E The Untended Antiquity
- CF 869E(The Untended Antiquity-Hash值维护连通性)
- CF869 E. The Untended Antiquity
- CF869 E. The Untended Antiquity
- [哈希+差分] Codeforces 869E. The Untended Antiquity
- tensorflow入门栗子:mnist的AlexNet实现
- android性能优化-评论列表
- Mariadb通过yum安装
- Codeforces Round #439 B
- LDA 主题模型
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity (hash+数状数组)
- JAVA课堂练习
- FTPrep, 108 Convert Sorted Array to Binary Search Tree
- EU5-12:Talking about the future technology
- 学习JavaScript数据结构与算法(四)——链表
- Codeforces Round #439 (Div. 2)-The Intriguing Obsession(DP)
- JAVA提高篇(18)--BufferedReader、BufferedWriter
- FTPrep, 109 Convert Sorted List to Binary Search Tree
- Ubuntu16.04 安装百度云bcloud