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),我就不知道了,但是要 ...
随机推荐
- nginx 重启报错
错误信息: nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or d ...
- lintcode 二叉树前序遍历
二叉树的前序遍历 给出一棵二叉树,返回其节点值的前序遍历. 您在真实的面试中是否遇到过这个题? Yes 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [1,2,3]. / ...
- 《Git学习指南》学习笔记(二)
第三章 提交究竟是什么 每次提交都会生成一个40位的散列值.只要知道散列值,我们就可以恢复到该次提交,这个操作也被称之为检出(checkout)操作. 访问权限与时间戳 Git会保存每个文件原有的访问 ...
- Java学习 · 初识 面向对象深入一
面向对象深入 1.面向对象三大特征 a) 继承 inheritance 子类可以从父类继承属性和方法 子类可以提供自己的属性方法 b) 封装 encapsulation 对外隐藏某些属性和方法 对外公 ...
- commons-lang源码解析之StringUtils
apache的commons工具包是平时使用最多的工具包之一,对其实现方式需要具体了解.commons-lang version 3.1 empty和blank的区别 StringUtils中判断St ...
- 技能get,React的优雅升级!
今日,我们不啖鸡汤,不饮鸡血 只有干货——关于React的优雅升级 双手奉上,来,干了! -2019年第4期- 夫 子 说 本次升级基础包情况:react 15.6 -> 16.6 升级流程: ...
- PAT-甲级解题目录
PAT甲级题目:点这里 pat解题列表 题号 标题 题目类型 10001 1001 A+B Format (20 分) 字符串处理 1003 1003 Emergency (25 分) 最短路径 ...
- nginx 应用篇
nginx 信号控制(commanLine) kill singel pid ps aux|grep nginx nginx 有两个进程,一个 master 一个worker 一个master管理一 ...
- BZOJ 4815 CQOI2017 小Q的表格 欧拉函数+分块
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4815 题意概述:要认真概述的话这个题就出来了... 分析: 首先分析题目,认真研究一下修 ...
- Alphabetic Removals(模拟水题)
You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...