题目链接

BZOJ3542

题解

线段树裸题,,对每一行每一列开线段树

由于坐标很大,用\(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 + 线段树】的更多相关文章

  1. hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

    DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  2. ACM学习历程—Codeforces 446C DZY Loves Fibonacci Numbers(线段树 && 数论)

    Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence ...

  3. hdu 5649 DZY Loves Sorting 二分+线段树

    题目链接 给一个序列, 两种操作, 一种是将[l, r]里所有数升序排列, 一种是降序排列. 所有操作完了之后, 问你a[k]等于多少. 真心是涨见识了这题..好厉害. 因为最后只询问一个位置, 所以 ...

  4. Codeforces444C DZY Loves Colors(线段树)

    题目 Source http://codeforces.com/problemset/problem/444/C Description DZY loves colors, and he enjoys ...

  5. 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. ...

  6. [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】

    题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...

  7. Codeforces 446C DZY Loves Fibonacci Numbers [线段树,数论]

    洛谷 Codeforces 思路 这题知道结论就是水题,不知道就是神仙题-- 斐波那契数有这样一个性质:\(f_{n+m}=f_{n+1}f_m+f_{n}f_{m-1}\). 至于怎么证明嘛-- 即 ...

  8. 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]$ 其中 ...

  9. Codeforces446C DZY Loves Fibonacci Numbers(线段树 or 分块?)

    第一次看到段更斐波那契数列的,整个人都不会好了.事后看了题解才明白了一些. 首先利用二次剩余的知识,以及一些数列递推式子有下面的 至于怎么解出x^2==5(mod 10^9+9),我就不知道了,但是要 ...

随机推荐

  1. django1.11+xadmin的搭建

    1.git clone https://github.com/sshwsfc/xadmin.git或者直接下载zip包 2..在项目根目录下建一个extra_apps的包,将xadmin源码包存放在里 ...

  2. 180620-mysql之数据库导入导出

    文章链接:https://liuyueyi.github.io/hexblog/2018/06/20/180620-mysql之数据库导入导出/ mysql之数据库导入导出 实际工作中,需要做一下数据 ...

  3. Siki_Unity_3-13_编程内功修炼-算法

    Unity 3-13 编程内功修炼 -- 算法 任务1&2:课程介绍 主要算法: 分治法 堆排序 二叉树 动态规划 贪心算法 图 任务3:分治算法 -- Divide and Conquer ...

  4. MarkDown编辑器使用

    有几款好用的MarkDown编辑器,参考: https://blog.csdn.net/bat67/article/details/72804251 我就下载的是 MarkDown 2来使用. 现用现 ...

  5. Python基础简介

    一.目前各种语言的应用:java, 可以把特别小的项目做大,并且开源库比较多,C: 用在最底层,例如编写操作系统,运行速率快,开发效率低,C++:常坐游戏引擎Python:AI(人工智能) 简单.明确 ...

  6. 安装sqoop 1.99.4

    参考http://sqoop.apache.org/docs/1.99.4/Installation.html 1.简介 sqoop2分为server和client两部分.server作为maprde ...

  7. JS中Document节点总结

    document对象是documentHTML的一个实例,也是window对象的一个属性,因此可以将document对象作为一个全局对象来访问. Document节点的子节点可以是DocumentTy ...

  8. Beta版本软件使用说明

    北京航空航天大学计算机学院 远航1617 小组 产品版本: Beta版本 产品名称:Crawling   is going on 文档作者:杨帆 文档日期:2013/12/24 1.   引言 1.1 ...

  9. c#积累之测试

    初来上班,免不了看别人代码.快速搞懂别人代码是我现在受到的一大挑战.寻摸着规律,发现一边进行调试,一边进行行行注释的逻辑判断不失为一种妙招. c#调试用的是vs2012.f11键和f10和f5键的应用 ...

  10. 软工实践Alpha冲刺(2/10)

    队名:我头发呢队 组长博客 作业博客 杰(组长) 过去两天完成了哪些任务 查看了讯飞开放平台的sdk 查阅了Google Material Design 2的官方文档 接下来的计划 继续打磨UI界面: ...