Codeforces Round #439 (Div. 2) E:The Untended Antiquity(Hash+二维树状数组)
来源:互联网 发布:网络电视看电视直播 编辑:程序博客网 时间:2024/06/06 07:30
传送门
题意:
给一个
题解:
首先矩形不相交可以知道两点如果不能互相到达一定是在不同的障碍里,考虑对每个障碍赋一个Hash值,用二维树状数组差分维护,查询直接查前缀和就好了。
#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned int uint;typedef pair<int,int> pii;struct IO{ streambuf *ib,*ob; inline void init(){ ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ib=cin.rdbuf();ob=cout.rdbuf(); } inline int read(){ static char ch;static int i,f; ch=ib->sbumpc();i=0,f=1; while(!isdigit(ch)){if(ch=='-')f=-1;ch=ib->sbumpc();} while(isdigit(ch)){i=(i<<1)+(i<<3)+ch-'0';ch=ib->sbumpc();} return i*f; } inline void W(string x){ int length=x.length(); for(int i=0;i<length;i++)ob->sputc(x[i]); ob->sputc('\n'); } inline uint unit(){ static uint state0=19491001; state0^=state0<<13; state0^=state0>>17; state0^=state0<<5; return state0; }}io;const int Maxn=2505;int n,m,q;ll bit[Maxn][Maxn];map<pii,ll>S;inline void insert(int x,int y,ll val){ for(int i=x;i<=n;i+=(i&(-i))) for(int j=y;j<=m;j+=(j&(-j))) bit[i][j]+=val;}inline ll query(int x,int y){ ll res=0; for(int i=x;i;i-=(i&(-i))) for(int j=y;j;j-=(j&(-j))) res+=bit[i][j]; return res;}int main(){ io.init(),n=io.read(),m=io.read(),q=io.read(); for(int i=1;i<=q;i++){ int op=io.read(),x1=io.read(),y1=io.read(),x2=io.read(),y2=io.read(); if(op==1){ ll val=io.unit();S[make_pair(x1*n+y1,x2*n+y2)]=val; insert(x1,y1,val);insert(x1,y2+1,-val);insert(x2+1,y1,-val);insert(x2+1,y2+1,val); }else if(op==2){ ll val=S[make_pair(x1*n+y1,x2*n+y2)]; insert(x1,y1,-val);insert(x1,y2+1,val);insert(x2+1,y1,val);insert(x2+1,y2+1,-val); }else{ if(query(x2,y2)==query(x1,y1))io.W("Yes"); else io.W("No"); } }}
阅读全文
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 二维线段树||二维树状数组
- 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(Hash)
- Codeforces Round #439 E. The Untended Antiquity (树状数组+随机化)
- 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(二维BIT)
- Codeforces 869 E. The Untended Antiquity 二维树状数组
- codeforces 869E The Untended Antiquity 二维BIT + hash
- codeforces869EThe Untended Antiquity(二维树状数组)
- CF869E The Untended Antiquity(二维数状数组+差分+hash)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- Codeforces Round #368 (Div. 2) E. Garlands(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- CF #439 E The Untended Antiquity
- bzoj2957楼房重建(线段树)
- 详解独角兽应该具备的6个特点,创业者必看
- POJ
- 设计模式系列之适配器模式
- hdu 2082 (dp)
- Codeforces Round #439 (Div. 2) E:The Untended Antiquity(Hash+二维树状数组)
- 微信公众号添加多客服微信号-微信公众号使用教程19
- NP(分块打表)
- Linux任务调度和进程管理
- javaEE概要
- 微信公众号添加客服素材-微信公众号使用教程20
- NP
- 排序算法-堆排序
- Java类初始化顺序