题意

\(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. css之display:inline-block

    display:inline-block: 作用:将对象呈现为inline对象,但是对象的内容作为block对象呈现.之后的内联对象会被排列在同一行内.比如我们可以给一个link(a元素)inline ...

  2. 在Activity之间传递参数(四)

    获取Activity的返回参数(在参数(三)User的例子的基础上实现): 1.activity_the_aty.xml文件:<EditText android:id="@+id/ed ...

  3. [Data Structure] Bit-map空间压缩和快速排序去重

    Bit-map是一种很巧妙的数据存储结构.所谓的Bit-map就是用一个bit位来标记某个元素对应的Value,而Key即是该元素.由于采用了Bit为单位来存储数据,可以大大节省存储空间.Bit-ma ...

  4. PHP读写大“二进制”文件,不必申请很大内存(fopen、fread、fwrite、fclose)

    <?php /** * 读写大二进制文件,不必申请很大内存 * 只有读取到内容才创建文件 * 保证目录可写 * * @param string $srcPath 源文件路径 * @param s ...

  5. winform窗体弹出时,光标默认显示在指定的输入框内

    private void Form1_Paint(object sender, PaintEventArgs e) { this.textBox1.SelectAll(); this.textBox1 ...

  6. js跨域问题

    跨域概念:只要协议.域名.端口有任何一个不同,都被当作是不同的域. 跨域的主要原因是由于安全限制(同源策略, 即JavaScript或Cookie只能访问同域下的内容). 常用的跨域解决方案: 1.J ...

  7. 分享一个简单易用的RPC开源项目—Tatala

    http://zijan.iteye.com/blog/2041894 这个项目最早(2008年)是用于一个网络游戏的Cache Server,以及一个电子商务的Web Session服务.后来不断增 ...

  8. 构建高可用ZooKeeper集群(转载)

    ZooKeeper 是 Apache 的一个顶级项目,为分布式应用提供高效.高可用的分布式协调服务,提供了诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知和分布式锁等分布式基础服务.由于 Zo ...

  9. java 深入技术四(Set)

    1)Set接口 set接口的父接口-Collection set接口的重要子类-HashSet set接口的重要子类 -TreeSet set 接口的特别子类-LinkedHashSet 2)Hash ...

  10. unlink和close关系

    今天看到nginx用文件锁实现互斥的实现方案时,发现,unlink文件后还可需用fd,很是纳闷!于是搜索到此文,并自测了下,涨姿势了~分享给大家~ 原理: 每一个文件,都可以通过一个struct st ...