【BZOJ】3542: DZY Loves March
题意
\(m * m\)的网格,有\(n\)个点。\(t\)个询问:操作一:第\(x\)个点向四个方向移动了\(d\)个单位。操作二:询问同行同列其他点到这个点的曼哈顿距离和。强制在线。(\(n \le 10^5,m \le 10^{18}\))
分析
没啥好分析的,就是推一下能推出每行每列的一个式子来,然后套两个区间维护的结构就行了。
题解
set + 线段树
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mo=1e9+7, N=100005;
int n;
ll x[N], y[N];
template<class T>
inline void fix(T &x) {
if(x>=mo || x<=-mo) x%=mo;
if(x<0) x+=mo;
}
struct dat {
int s, sum1, sum2;
void init() {
s=sum1=sum2=0;
}
void add(int _s, int go) {
s+=_s;
sum1+=(ll)go*go%mo*_s; fix(sum1);
sum2+=go*_s; fix(sum2);
}
};
dat operator + (const dat &a, const dat &b) {
static dat x;
x.s=a.s+b.s;
x.sum1=a.sum1+b.sum1; fix(x.sum1);
x.sum2=a.sum2+b.sum2; fix(x.sum2);
return x;
}
struct node *null;
struct node {
node *c[2];
dat d;
void up() {
d=c[0]->d+c[1]->d;
}
void init() {
d.init();
c[0]=c[1]=null;
}
}Po[5000005], *iT=Po, *bin[5000005], **iTbin=bin;
node *newnode() {
node *x;
if(iTbin!=bin) x=*(--iTbin);
else {
if(iT==Po+5000000) x=new node;
else x=iT++;
}
x->init();
return x;
}
void delnode(node *&x) {
*iTbin=x;
iTbin++;
x=null;
}
void seginit() {
null=newnode();
null->init();
}
void update(int p, int s, int go, int l, int r, node *&x) {
if(x==null) {
x=newnode();
}
if(l==r) {
x->d.add(s, go);
if(x->d.s==0) {
delnode(x);
}
return;
}
int mid=(l+r)>>1;
if(p<=mid) {
update(p, s, go, l, mid, x->c[0]);
}
else {
update(p, s, go, mid+1, r, x->c[1]);
}
x->up();
if(x->d.s==0) {
delnode(x);
}
}
dat ask(int L, int R, int l, int r, node *x) {
static dat nul={0, 0, 0};
if(x==null) {
return nul;
}
if(L<=l && r<=R) {
return x->d;
}
int mid=(l+r)>>1;
dat ret;
ret.init();
if(L<=mid) {
ret=ask(L, R, l, mid, x->c[0]);
}
if(mid<R) {
ret=ret+ask(L, R, mid+1, r, x->c[1]);
}
return ret;
}
map<ll, node *> X, Y;
void add(ll x, int s, int go, int id, map<ll, node *> &a) {
if(a.find(x)==a.end()) {
a[x]=null;
}
node *&it=a[x];
update(id, s, go, 1, n, it);
if(it==null) a.erase(a.find(x));
}
dat ask(ll x, int L, int R, map<ll, node *> &a) {
return ask(L, R, 1, n, a[x]);
}
int main() {
seginit();
int m;
scanf("%d%d", &n, &m);
for(int i=1; i<=n; ++i) {
ll _x, _y;
scanf("%lld%lld", &_x, &_y);
x[i]=_x;
y[i]=_y;
fix(_x);
fix(_y);
add(x[i], 1, _y, i, X);
add(y[i], 1, _x, i, Y);
}
int T, ans=0;
scanf("%d", &T);
while(T--) {
char s[5];
int pos;
scanf("%s%d", s, &pos);
pos^=ans;
if(s[0]=='Q') {
int L, R;
scanf("%d%d", &L, &R);
dat d1, d2;
d2=ask(x[pos], L, R, X);
d1=ask(y[pos], L, R, Y);
ans=0;
ll ans1=0, ans2=0, tx=x[pos], ty=y[pos];
fix(tx);
fix(ty);
ans1=-((tx*d1.sum2%mo)<<1)+tx*tx%mo*d1.s+d1.sum1;
ans2=-((ty*d2.sum2%mo)<<1)+ty*ty%mo*d2.s+d2.sum1;
fix(ans1);
fix(ans2);
ans=ans1+ans2;
fix(ans);
printf("%d\n", ans);
}
else {
ll d;
scanf("%lld", &d);
ll _x=x[pos], _y=y[pos];
if(s[0]=='U') y[pos]+=d;
if(s[0]=='D') y[pos]-=d;
if(s[0]=='R') x[pos]+=d;
if(s[0]=='L') x[pos]-=d;
add(_x, -1, _y%mo, pos, X);
add(_y, -1, _x%mo, pos, Y);
add(x[pos], 1, y[pos]%mo, pos, X);
add(y[pos], 1, x[pos]%mo, pos, Y);
}
}
return 0;
}
【BZOJ】3542: DZY Loves March的更多相关文章
- 【BZOJ】3309: DZY Loves Math 莫比乌斯反演优化
3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...
- 【BZOJ】3561: DZY Loves Math VI
题意 求\(\sum_{i=1}^{n} \sum_{j=1}^{m} lcm(i, j)^{gcd(i, j)}\)(\(n, m<=500000\)) 分析 很显然要死推莫比乌斯 题解 设\ ...
- 【BZOJ】3309: DZY Loves Math
题意 \(T(T \le 10000)\)次询问,每次给出\(a, b(1 \le a, b \le 10^7)\),求 \[\sum_{i=1}^{a} \sum_{j=1}^{b} f((i, j ...
- 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)
http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...
- 【dfs】bzoj3563 DZY Loves Chinese
因为我们可以通过把某一行读到末尾来获取真正的K,所以把它和假K异或之后就是之前联通的次数(异或的逆运算为其本身).最后一次的暴力一下. #include<cstdio> #include& ...
- 【BZOJ】3052: [wc2013]糖果公园
http://www.lydsy.com/JudgeOnline/problem.php?id=3052 题意:n个带颜色的点(m种),q次询问,每次询问x到y的路径上sum{w[次数]*v[颜色]} ...
- 【BZOJ】3319: 黑白树
http://www.lydsy.com/JudgeOnline/problem.php?id=3319 题意:给一棵n节点的树(n<=1e6),m个操作(m<=1e6),每次操作有两种: ...
- 【BZOJ】3319: 黑白树(并查集+特殊的技巧/-树链剖分+线段树)
http://www.lydsy.com/JudgeOnline/problem.php?id=3319 以为是模板题就复习了下hld............................. 然后n ...
- 【BZOJ】1013: [JSOI2008]球形空间产生器sphere
[BZOJ]1013: [JSOI2008]球形空间产生器sphere 题意:给n+1个n维的点的坐标,要你求出一个到这n+1个点距离相等的点的坐标: 思路:高斯消元即第i个点和第i+1个点处理出一个 ...
随机推荐
- 产经新闻:公交WiFi这次能扛多久
来源:16WiFi.流量咪 http://www.16wifi.com/18820/mtbd/html/1096904.html 不靠谱也许是成长的烦恼,也可能是本性使然.公交WiFi就给人一种不靠 ...
- JAVA起名规范
1:包名 package com.cenzhongman.模块名.组件 必须全部小写,作为java文件第一行代码 2:类名 名词,表示一类实物,如:人类 首字母大写 3.接口名 形容词/副词,表示一种 ...
- 浅谈Android中拍照、从相册选择图片并截图相关知识点
前言 我们在Android开发中经常会需要使用相机或者从相册中选取图片的情况,今天就把这里面相关的知识点总结下,方便以后开发的时候使用. 1.相机拍照并可自定义截图功能 我们先来看如何使用Intent ...
- Swift 3.0 【Swift 3.0 相较于 Swift 2.2 的变化】
一.编译器和语法变化 函数或方法参数 调用函数或方法时从第一个参数开始就必须指定参数名 在Swift的历史版本中出现过在调用函数时不需要指定任何函数参数(或者从第二个参数开始指定参数名),在调用方法时 ...
- [Data Structure] 数据结构中各种树
数据结构中有很多树的结构,其中包括二叉树.二叉搜索树.2-3树.红黑树等等.本文中对数据结构中常见的几种树的概念和用途进行了汇总,不求严格精准,但求简单易懂. 1. 二叉树 二叉树是数据结构中一种重要 ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- Spring各jar包的作用
spring.jar是包含有完整发布的单个jar 包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下才会用到 spring-m ...
- Alpha版本十天冲刺——Day 10
站立式会议 最后一天,很高兴我们做出了跟预期差不多的版本,实现了基本功能,虽然还有一些bug,但是下一阶段我们会继续加油! 会议总结 队员 今天完成 遇到的问题 感想 鲍亮 功能细节更改 我的手机运行 ...
- 分享一个Visual Studio的背景插件,让堆码更富情趣
忘记一件重要的事情,我使用的是VS 2012版,其他更高版本应该是可以找到的,以下版本就不清楚了.有可能找不到,见谅,也不是我开发的,只是偶尔碰到,拿出来让大家知道. 上周某日,新生命群里面还是一如既 ...
- TraceView进行性能分析
一.TraceView概述 TraceView 是 Android 平台配备一个很好的性能分析的工具.它可以通过图形化的方式让我们了解我们要跟踪的程序的性能,并且能具体到 method. 详细内容参考 ...