BZOJ3542 DZY Loves March 【map + 线段树】
题目链接
题解
线段树裸题,,对每一行每一列开线段树
由于坐标很大,用\(map\)维护根下标
化一下式子,只用维护区间和,区间平方和,区间存在的个数
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b,c) (node){a,b,c}
#define cls(s) memset(s,0,sizeof(s))
#define cp node
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 8000005,INF = 1000000000,P = 1000000007;
inline LL read(){
LL out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct node{LL a,b,c;};
map<LL,int> rt1,rt2;
LL x[maxn],y[maxn],m;
LL sum[maxm],sum2[maxm],num[maxm],cnt;
int ls[maxm],rs[maxm],n;
void upd(int u){
sum[u] = (sum[ls[u]] + sum[rs[u]]) % P;
sum2[u] = (sum2[ls[u]] + sum2[rs[u]]) % P;
num[u] = num[ls[u]] + num[rs[u]];
}
void modify(int& u,int l,int r,int pos,LL v,LL vv){
if (!u) u = ++cnt;
if (l == r){v %= P; sum[u] = v; sum2[u] = v * v % P; num[u] = vv; return;}
int mid = l + r >> 1;
if (mid >= pos) modify(ls[u],l,mid,pos,v,vv);
else modify(rs[u],mid + 1,r,pos,v,vv);
upd(u);
}
cp query(int u,int l,int r,int L,int R){
if (!u) return mp(0,0,0);
if (l >= L && r <= R) return mp(sum[u],sum2[u],num[u]);
int mid = l + r >> 1;
if (mid >= R) return query(ls[u],l,mid,L,R);
if (mid < L) return query(rs[u],mid + 1,r,L,R);
cp t1 = query(ls[u],l,mid,L,R),t2 = query(rs[u],mid + 1,r,L,R);
return mp((t1.a + t2.a) % P,(t1.b + t2.b) % P,t1.c + t2.c);
}
LL lans,t,l,r,d,X,Y;
int main(){
n = read(); m = read();
REP(i,n){
x[i] = read(); y[i] = read();
modify(rt1[x[i]],1,n,i,y[i] % P,1);
modify(rt2[y[i]],1,n,i,x[i] % P,1);
}
int T = read(); char opt; cp u;
while (T--){
opt = getchar(); while (!isalpha(opt)) opt = getchar();
if (opt == 'Q'){
t = read() ^ lans; l = read(); r = read();
u = query(rt1[x[t]],1,n,l,r);
X = x[t] % P; Y = y[t] % P;
lans = ((Y * Y % P * u.c % P - 2ll * Y % P * u.a % P) % P + u.b)% P;
u = query(rt2[y[t]],1,n,l,r);
lans = (lans + (X * X % P * u.c % P - 2ll * X % P * u.a % P) % P + u.b) % P;
lans = (lans % P + P) % P;
printf("%lld\n",lans);
}
else {
t = read() ^ lans; d = read();
modify(rt1[x[t]],1,n,t,0,0);
modify(rt2[y[t]],1,n,t,0,0);
switch(opt){
case 'U':y[t] += d;break;
case 'D':y[t] -= d;break;
case 'L':x[t] -= d;break;
case 'R':x[t] += d;break;
default:break;
}
modify(rt1[x[t]],1,n,t,y[t] % P,1);
modify(rt2[y[t]],1,n,t,x[t] % P,1);
}
}
return 0;
}
BZOJ3542 DZY Loves March 【map + 线段树】的更多相关文章
- hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序
DZY Loves Topological Sorting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...
- ACM学习历程—Codeforces 446C DZY Loves Fibonacci Numbers(线段树 && 数论)
Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence ...
- hdu 5649 DZY Loves Sorting 二分+线段树
题目链接 给一个序列, 两种操作, 一种是将[l, r]里所有数升序排列, 一种是降序排列. 所有操作完了之后, 问你a[k]等于多少. 真心是涨见识了这题..好厉害. 因为最后只询问一个位置, 所以 ...
- Codeforces444C DZY Loves Colors(线段树)
题目 Source http://codeforces.com/problemset/problem/444/C Description DZY loves colors, and he enjoys ...
- codeforces 446C DZY Loves Fibonacci Numbers 线段树
假如F[1] = a, F[2] = B, F[n] = F[n - 1] + F[n - 2]. 写成矩阵表示形式可以很快发现F[n] = f[n - 1] * b + f[n - 2] * a. ...
- [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】
题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...
- Codeforces 446C DZY Loves Fibonacci Numbers [线段树,数论]
洛谷 Codeforces 思路 这题知道结论就是水题,不知道就是神仙题-- 斐波那契数有这样一个性质:\(f_{n+m}=f_{n+1}f_m+f_{n}f_{m-1}\). 至于怎么证明嘛-- 即 ...
- CF446C DZY Loves Fibonacci Numbers 线段树 + 数学
有两个性质需要知道: $1.$ 对于任意的 $f[i]=f[i-1]+f[i-2]$ 的数列,都有 $f[i]=fib[i-2]\times f[1]+fib[i-1]\times f[2]$ 其中 ...
- Codeforces446C DZY Loves Fibonacci Numbers(线段树 or 分块?)
第一次看到段更斐波那契数列的,整个人都不会好了.事后看了题解才明白了一些. 首先利用二次剩余的知识,以及一些数列递推式子有下面的 至于怎么解出x^2==5(mod 10^9+9),我就不知道了,但是要 ...
随机推荐
- pg mysql 比较
PostgreSQL 与 MySQL比较: 一.pg优势: MySQL 不支持 OVER 子句, 而 Pg 支持 它可以存储 array 和 json, 可以在 array 和 json 上建索引, ...
- hdu1171Big Event in HDU(01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 逆波兰表达式[栈 C 语言 实现]
逆波兰表达式 逆波兰表达式又叫做后缀表达式.在通常的表达式中,二元运算符总是置于与之相关的两个运算对象之间,这种表示法也称为中缀表示.波兰逻辑学家J.Lukasiewicz于1929年提出了另一种表示 ...
- Oracle启动与关闭数据库实例
Oracle数据库启动实例分为3个步骤: 启动实例 加载数据库 打开数据库 通用模式: STARTUP [ nomount | mount | open | force ] [resetrict] ...
- Spring Cloud(十一):服务网关 Zuul(过滤器)【Finchley 版】
Spring Cloud(十一):服务网关 Zuul(过滤器)[Finchley 版] 发表于 2018-04-23 | 更新于 2018-05-07 | 在上篇文章中我们了解了 Spring ...
- 孤荷凌寒自学python第七十八天开始写Python的第一个爬虫8
孤荷凌寒自学python第七十八天开始写Python的第一个爬虫8 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 到今天止基本完成了对docx模块针 ...
- 关于Python3中函数:
# 关于Python3中函数: - 定义 定义函数使用关键字def,后接函数名和放在圆括号()中的可选参数列表,函数内容以冒号起始并且缩进.一般格式如下:``` def 函数名(参数列表): &quo ...
- BFC与合并 浅析
BFC BFC 全称 Block Formatting Context.每个渲染区域用formatting context表示,它决定了其子元素将如何定位,以及和其他元素的关系和相互作用在正常流中的盒 ...
- EF中如何为表添加新的字段和映射
首先先了解一下ef生成的模型edmx的代码,传送门:http://www.cnblogs.com/yushengbo/p/4807715.html 一.添加新的字段 例子就用我现在项目的这个吧,首先在 ...
- 使用深度学习来破解 captcha 验证码(转)
使用深度学习来破解 captcha 验证码 本项目会通过 Keras 搭建一个深度卷积神经网络来识别 captcha 验证码,建议使用显卡来运行该项目. 下面的可视化代码都是在 jupyter not ...