题面以及思路:https://blog.csdn.net/glqac/article/details/38402101

代码:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL mod = 1000000007;
const int maxn = 2000010;
struct node {
LL x, y;
int cnt;
node(){}
node(LL x, LL y, int cnt) {
this -> x = x;
this -> y = y;
this -> cnt = cnt;
}
};
node pos[maxn];
map<LL, set<int> > row, col;
set<int> :: iterator it;
int f[maxn];
int get(int x) {
if(x == f[x]) return x;
return f[x] = get(f[x]);
}
int tot;
int main() {
int n, m, T, p;
LL x, y, ans, d;
char s[10];
while(~scanf("%d%d", &n, &m)) {
row.clear();
col.clear();
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &x, &y);
pos[i] = node(x, y, 1);
f[i] = i;
row[x].insert(i);
col[y].insert(i);
}
f[n + 1] = n + 1;
tot = n + 1;
scanf("%d", &T);
ans = 0;
while(T--) {
scanf("%s",s + 1);
if(s[1] == 'Q') {
scanf("%d", &p);
p = p ^ ans;
p = get(p);
node tmp = pos[p];
int num = 0;
ans = 0;
LL xx = pos[p].x, yy = pos[p].y;
for (it = row[xx].begin(); it != row[xx].end(); it++) {
node& tmp = pos[*it];
f[*it] = tot;
col[yy].erase(*it);
num += tmp.cnt;
LL tmp1 = (abs(yy - tmp.y)) % mod;
ans = (ans + (tmp1 * tmp1) % mod * tmp.cnt % mod) % mod;
tmp.y = yy;
}
for (it = col[yy].begin(); it != col[yy].end(); it++) {
node& tmp = pos[*it];
f[*it] = tot;
num += tmp.cnt;
row[xx].erase(*it);
LL tmp1 = (abs(xx - tmp.x)) % mod;
ans = (ans + (tmp1 * tmp1) % mod) % mod;
tmp.y = yy;
}
col[yy].clear();
row[xx].clear();
pos[tot] = node(xx, yy, num);
col[yy].insert(tot);
row[xx].insert(tot);
tot++;
f[tot] = tot;
printf("%lld\n", ans);
} else {
scanf("%d%lld", &p, &d);
p = p ^ ans;
int p1 = p;
p = get(p);
node& tmp = pos[p];
LL xx = tmp.x, yy = tmp.y;
tmp.cnt--;
if(tmp.cnt == 0) {
row[xx].erase(p);
col[yy].erase(p);
}
if(s[1] == 'L') {
yy -= d;
} else if(s[1] == 'U') {
xx -= d;
} else if(s[1] == 'D') {
xx += d;
} else {
yy += d;
}
f[p1] = p1;
pos[p1] = node(xx, yy, 1);
row[xx].insert(p1);
col[yy].insert(p1);
}
}
} }

  

最新文章

  1. QuickSort 快速排序 基于伪代码实现
  2. asp.net 与数据库操作
  3. c#上iOS apns p12文件制作记录 iOS推送证书制件
  4. Linux基础※※※※如何使用Git in Linux(一)
  5. [SQL]patindex的用法
  6. 菜鸟-手把手教你把Acegi应用到实际项目中(3)
  7. C++:静态成员
  8. HDOJ1175连连看 DFS
  9. android抓包工具
  10. linux串口驱动分析——发送数据
  11. PHP学习笔记三十八【下载】
  12. la 3942 Rember_前缀树
  13. [原]iOS中 Web 页面与 Native Code 的一种通信方式
  14. win10 + ubuntu 16.04 双系统安装
  15. MySQL重复数据处理
  16. Swift基础
  17. 利用Python爬取豆瓣电影
  18. ASP.NET MVC:模块化/插件式文章汇总
  19. 通过html导出PDF如何分页
  20. webgote的例子 数据库与sql注入的相关联系(1)

热门文章

  1. python之单元测试框架—unittest
  2. 不一样的控制面板 GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
  3. 33 python 并发编程之IO模型
  4. winform常用方法
  5. memcache应对缓存失效问题
  6. HDU2065&quot;红色病毒&quot;问题【指数型母函数】
  7. kong插件官方文档翻译
  8. docker 镜像自动升级脚本
  9. C++空类大小
  10. Poj 2421 Constructing Roads(Prim 最小生成树)