题意

\(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的更多相关文章

  1. 【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) ...

  2. 【BZOJ】3561: DZY Loves Math VI

    题意 求\(\sum_{i=1}^{n} \sum_{j=1}^{m} lcm(i, j)^{gcd(i, j)}\)(\(n, m<=500000\)) 分析 很显然要死推莫比乌斯 题解 设\ ...

  3. 【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 ...

  4. 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...

  5. 【dfs】bzoj3563 DZY Loves Chinese

    因为我们可以通过把某一行读到末尾来获取真正的K,所以把它和假K异或之后就是之前联通的次数(异或的逆运算为其本身).最后一次的暴力一下. #include<cstdio> #include& ...

  6. 【BZOJ】3052: [wc2013]糖果公园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3052 题意:n个带颜色的点(m种),q次询问,每次询问x到y的路径上sum{w[次数]*v[颜色]} ...

  7. 【BZOJ】3319: 黑白树

    http://www.lydsy.com/JudgeOnline/problem.php?id=3319 题意:给一棵n节点的树(n<=1e6),m个操作(m<=1e6),每次操作有两种: ...

  8. 【BZOJ】3319: 黑白树(并查集+特殊的技巧/-树链剖分+线段树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3319 以为是模板题就复习了下hld............................. 然后n ...

  9. 【BZOJ】1013: [JSOI2008]球形空间产生器sphere

    [BZOJ]1013: [JSOI2008]球形空间产生器sphere 题意:给n+1个n维的点的坐标,要你求出一个到这n+1个点距离相等的点的坐标: 思路:高斯消元即第i个点和第i+1个点处理出一个 ...

随机推荐

  1. 几款开源ESB总线的比较

    现有的开源ESB总线中,自从2003年第一个开源总线Mule出现后,现在已经是百花争鸣的景象了.现在我就对现有的各种开源ESB总线依据性能.可扩展性.资料文档完整程度以及整合难易程度等方面展开. CX ...

  2. Bash 什么时候会给 HOME 赋初始值

    今天无意发现下面这个表现: $  env -i bash -c cd bash: line 0: cd: HOME not set $ env -i bash -c 'echo $HOME' 这表明了 ...

  3. Flex Builder快捷键

    Flex几个最重要的快捷键 代码助手:Ctrl+Space(简体中文操作系统是Alt+/) 快速修正:Ctrl+1 单词补全:Alt+/ 打开外部Java文档:Shift+F2 显示搜索对话框:Ctr ...

  4. java中的wait(),notify(),notifyAll(),synchronized方法

    wait(),notify(),notifyAll()三个方法不是Thread的方法,而是Object的方法.意味着所有对象都有这三个方法,因为每个对象都有锁,所以自然也都有操作锁的方法了.这三个方法 ...

  5. make 和 makefile 的关系

    程序的 编译 和 链接 要先总结 make 和 makefile,就需要先了解下面这个过程: 预编译:也叫预处理,进行一些文本替换工作,比如将 #define 定义的内容,在代码中进行替换: 编译:将 ...

  6. MySQL Where 条件

    WHERE 条件 有时候操作数据库时,只操作一些有条件限制的数据,这时可以在SQL语句中添加WHERE子句来规定数据操作的条件. 语法: SELECT column,… FROM tb_name WH ...

  7. CPU思考

    线程高并发 会导致CPU load长,线程大运算量和大量线程 会导致CPU利用率高 因为CPU处理都是原子操作的,8核CPU在同一时刻最多也只能处理8个线程,但是因为处理的非常快,所以即使几万个简单线 ...

  8. exception catch doesn't work?? (python 3)

    exception catch doesn't work?? (python 3) except u.URLError, e: ^ SyntaxError: invalid syntax in Pyt ...

  9. [转载]Java数组扩容算法及Java对它的应用

    原文链接:http://www.cnblogs.com/gw811/archive/2012/10/07/2714252.html Java数组扩容的原理 1)Java数组对象的大小是固定不变的,数组 ...

  10. SQLite返回码

    SQLite返回码 返回码含义 宏 值 含义 SQLITE_OK 0 返回成功 SQLITE_ERROR 1 SQL错误或数据库不存在 SQLITE_INTERNAL 2 SQLite内部逻辑错误 S ...