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),我就不知道了,但是要 ...
随机推荐
- Ubuntu Server 下将HTML页面转换为PNG图片
零.前言 最近做一个网站,需要将网页转换为图片.由于服务器是Ubuntu Server,没有图形界面,所以实现的过程中遇到了很多问题.记录下来备用. 一.安装CutyCapt CutyCapt是一个可 ...
- 获取附加在方法上的Attribute
如下: class Program { static void Main(string[] args) { var methodInfo = typeof(Program).GetMethod(&qu ...
- Win10系统XWware虚拟机安装Linux系统(Ubuntu)最新版教程
XWware虚拟机安装Linux系统(Ubuntu)教程 一.下载并安装VMware虚拟机 借助VMware Workstation Pro, 我们可以在同一台Windows或Linux PC上同时运 ...
- 饥饿的小易(枚举+广度优先遍历(BFS))
题目描述 小易总是感觉饥饿,所以作为章鱼的小易经常出去寻找贝壳吃.最开始小易在一个初始位置x_0.对于小易所处的当前位置x,他只能通过神秘的力量移动到 4 * x + 3或者8 * x + 7.因为使 ...
- C++ 学习笔记之——STL 库 vector
vector 是一种顺序容器,可以看作是可以改变大小的数组. 就像数组一样,vector 占用连续的内存地址来存储元素,因此可以像数组一样用偏移量来随机访问,但是它的大小可以动态改变,容器会自动处理内 ...
- php面试的那些“黑话”
以下是一些常见的面试暗语,求职者一定要弄清楚其中蕴含的深意,不然可能“躺着也中枪”,最后只能铩羽而归. (1)请把简历先放在这,有消息我们会通知你的 面试官说出这句话,则表明他对你已经“兴趣不大”,为 ...
- 官方文档 恢复备份指南三 Recovery Manager Architecture
本节讨论以下问题: About the RMAN Environment 关于RMAN环境 RMAN Command-Line Client ...
- ZOJ 3686 A Simple Tree Problem(线段树)
Description Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the ...
- 声明变量&定义变量
从编译原理上来说,声明是仅仅告诉编译器,有个某类型的变量会被使用,但是编译器并不会为它分配任何内存.而定义就是分配了内存.这对于以关键字extern进行声明是一定成立的,而对声明格式“ ...
- Alpha发布——Thunder团队
视频展示 视频链接: 爱奇艺: http://www.iqiyi.com/w_19ruzwru25.html (画质清晰,但可能需多次刷新或重新打开页面,此问题因电脑型号和网络而异) 优酷: ...