AC日记——红色的幻想乡 洛谷 P3801
思路:
线段树+容斥原理;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
#define maxm maxn<<2
#define ll long long
class TreeType {
private:
int L[maxm],R[maxm],mid[maxm],dis[maxm];
public:
void build(int now,int l,int r)
{
L[now]=l,R[now]=r,dis[now]=;
if(l==r) return;mid[now]=l+r>>;
build(now<<,l,mid[now]),build(now<<|,mid[now]+,r);
}
void updata(int now,int to)
{
if(L[now]==R[now])
{
dis[now]^=;
return;
}
if(to<=mid[now]) updata(now<<,to);
else updata(now<<|,to);
dis[now]=dis[now<<]+dis[now<<|];
}
int query(int now,int l,int r)
{
if(L[now]>=l&&R[now]<=r) return dis[now];
int res=;
if(l<=mid[now]) res+=query(now<<,l,r);
if(r>mid[now]) res+=query(now<<|,l,r);
return res;
}
};
struct TreeType tree1,tree2;
int n,m,q;
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
int main()
{
in(n),in(m),in(q);
tree1.build(,,n);
tree2.build(,,m);
int op,x1,y1,x2,y2;
while(q--)
{
in(op),in(x1),in(y1);
if(op==) tree1.updata(,x1),tree2.updata(,y1);
else
{
in(x2),in(y2);
ll ans1=tree1.query(,x1,x2),ans2=tree2.query(,y1,y2);
printf("%lld\n",ans1*(y2-y1+)+ans2*(x2-x1+)-ans1*ans2*);
}
}
return ;
}
AC日记——红色的幻想乡 洛谷 P3801的更多相关文章
- AC日记——校门外的树 洛谷 P1047
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...
- AC日记——无线网络发射器选址 洛谷 P2038
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...
- AC日记——小A的糖果 洛谷七月月赛
小A的糖果 思路: for循环贪心: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defi ...
- AC日记——矩阵取数游戏 洛谷 P1005
矩阵取数游戏 思路: dp+高精: 代码: #include <bits/stdc++.h> using namespace std; #define ll long long struc ...
- AC日记——妖梦拼木棒 洛谷 P3799
妖梦拼木棒 思路: 神特么题: 代码: #include <bits/stdc++.h> using namespace std; #define mod 1000000007LL int ...
- AC日记——妖梦斩木棒 洛谷 P3797
妖梦斩木棒 思路: 略坑爹: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define m ...
- AC日记——[SDOI2009]HH去散步 洛谷 P2151
[SDOI2009]HH去散步 思路: 矩阵快速幂递推(类似弗洛伊德): 给大佬跪烂-- 代码: #include <bits/stdc++.h> using namespace std; ...
- AC日记——聪明的质监员 洛谷 P1314
聪明的质监员 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define l ...
- AC日记——大爷的字符串题 洛谷 P3709
大爷的字符串题 思路: 莫队,需开O2,不开50: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 20000 ...
随机推荐
- Codeforces Round #343 (Div. 2) A
A. Far Relative’s Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...
- 解决iText2.0.8+freemark导出pdf不支持base64的解决办法
转换工具类 public class B64ImgReplacedElementFactory implements ReplacedElementFactory { /** * 实现createRe ...
- ListBox, ListView, GridView
ListView是ListBox的派生类,而GridView是ViewBase的派生类 ListView的View属性是ViewBase,所以GridView可以作为ListView的属性 如 < ...
- 正确理解WPF中的TemplatedParent
(注:Logical Tree中文称为逻辑树,Visual Tree中文称为可视化树或者视觉树,由于名称不是很统一,文中统一用英文名称代表两个概念,况且VisualTreeHelper和Logical ...
- git设置免密码登录
设置用户名和邮箱 git config --global user.name "<username>" git config --global user.email & ...
- Bzoj3481 DZY Loves Math III
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 310 Solved: 65 Description Input Output Sample Input ...
- bzoj 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列——map+hash+转换
Description N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色, 每头牛有多种特色,用二进制01表示它的特色ID.比如特色ID为13(1101), ...
- PHP 练习1:新闻发布
1.新闻发布主页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- Quick-Cocos2dx-Community_3.6.3_Release 编译时libtiff.lib 无法解析
Quick-Cocos2dx-Community_3.6.3_Release 使用VS2012编译,报错: libtiff.lib lnk2001 无法解析的外部符号 ltod3 类似于上面这种,刚才 ...
- HDU 1203 I NEED A OFFER! (dp)
题目链接 Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定 ...