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 ...
随机推荐
- CentOS 6.5 下安装 QT 4
1. 获取下载地址 从我到网盘下载: qt-creator-opensource-linux-x86_64-3.5.1.run qt-everywhere-opensource ...
- 洛谷:P3809 【模板】后缀排序(后缀数组模板)
P3809 [模板]后缀排序 题目链接:https://www.luogu.org/problemnew/show/P3809 题目背景 这是一道模板题. 题目描述 读入一个长度为 nn 的由大小写英 ...
- [python]字符串的ljust方法
ljust用法: string.ljust(number,'x') 格式化输出字符串,按照number数量调整字符串的总长度,ljust是左对齐,‘x’是填充字符,默认是空格 类似的还有rjust,c ...
- 题解 【luogu P1541 NOIp提高组2010 乌龟棋】
题目链接 题解 题意: 有一些格子,每个格子有一定分数. 给你四种卡片,每次可以使用卡片来前进1或2或3或4个格子并拾取格子上的分数 每张卡片有数量限制.求最大分数. 分析 设\(dp[i]\)为第前 ...
- HDU3308 线段树(区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Ant打jar包时,参数名被修改的问题
https://blog.csdn.net/landehuxi/article/details/42678117 使用Ant打jar包后,发现jar包中的方法名会在前面自动添加了“param”前缀,导 ...
- A Simple Math Problem(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 思路:矩阵快速幂模板题,不过因为刚刚入门矩阵快速幂,所以经常把数组f存反,导致本地错误一晚,差点 ...
- centos7 多版本python并存问题
新的阿里云服务器,本身装有python2.7,但是项目需要python3,于是只能再装一个python3.6 参考文章:https://www.cnblogs.com/johnny1024/p/844 ...
- Problems with Ribbon/Feign/Zuul retry
原文 https://github.com/spring-cloud/spring-cloud-netflix/issues/1577 I'm using Spring Cloud Camden SR ...
- HashMap 、LinkedHashMap、HashTable、TreeMap 和 Properties 的区别
HashMap 1.线程不安全: 2.允许null value 和 null key: 3.访问效率比较高: 4.Java1.2引进的Map接口的一个实现: 5.轻量级: 6.根据键的HashCode ...