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),我就不知道了,但是要 ...
随机推荐
- 制作一个App的完整流程是哪些
APP开发流程其实并不复杂,但是对于客户来说,.一般移动APP开发都离不开UI设计师.前端开发.后端开发.测试专员.产品经理等,由于他们的工作性质都不一样,我们且先把APP软件开发项目分为三个阶段: ...
- 深入理解java虚拟机学习笔记(一)
第二章 Java内存区域与内存溢出异常 运行时数据区域 程序计数器(Program Counter Register) 程序计数器:当前线程所执行的字节码行号指示器.各条线程之间计数器互不影响,独立存 ...
- Apache POI:Excel读写库
1)Apache POI 简介 Apache POI是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写 ...
- python图片大小处理;
循环一个目录将下面的所有png或者jpg文件全部缩小一定比例: from PIL import Image import os,re work_dir = 'C:\\Users\\Admini ...
- 【shell 练习1】编写Shell条件句练习
实例一.比较两个整数大小 #!/bin/bash while true do read -p "Please input two int nums:" a b >/dev/& ...
- 剑指offer-整数中1出现的次数27
题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...
- spring boot 下使用@ConponentScan注解遇到的问题
问题描述 如果你心急看结果,请直接到本文末尾 今天使用了注解操作spring boot,一开始程序无法启动,提示无法找到一个注解注入的类,查询网上,有人说使用@ConponetScan注解,可以指定需 ...
- HADOOP docker(四):安装hive
1.hive简介2.安装hive2.1 环境准备2.1.1 下载安装包2.1.2 设置hive用户的环境变量2.1.3 hive服务端配置文件2.1.4 hive客户端配置文件2.1.4 分发hive ...
- centos环境配置(nginx,node.js,mysql)
1.安装 Install GCC and Development Tools on a CentOS yum group install "Development Tools" n ...
- 浮点数(floating-point number)二进制存储格式
定义 浮点数就是小数点位置不固定的数,也就是说与定点数不一样,浮点数的小数点后的小数位数可以是任意的,根据IEEE754-1985(也叫IEEE Standard for Binary Floatin ...