题面以及思路: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);
}
}
} }

  

HDU 4879 ZCC loves march (并查集,set,map)的更多相关文章

  1. HDU 4876 ZCC loves cards(暴力剪枝)

    HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...

  2. hdu 4873 ZCC Loves Intersection(大数+概率)

    pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...

  3. hdu 4876 ZCC loves cards(暴力)

    题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...

  4. HDU 4873 ZCC Loves Intersection(可能性)

    HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...

  5. UOJ_14_【UER #1】DZY Loves Graph_并查集

    UOJ_14_[UER #1]DZY Loves Graph_并查集 题面:http://uoj.ac/problem/14 考虑只有前两个操作怎么做. 每次删除一定是从后往前删,并且被删的边如果不是 ...

  6. hdu 4882 ZCC Loves Codefires(数学题+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...

  7. HDU HDU1558 Segment set(并查集+判断线段相交)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1558 解题报告:首先如果两条线段有交点的话,这两条线段在一个集合内,如果a跟b在一个集合内,b跟c在一 ...

  8. hdu 1257 小希的迷宫 并查集

    小希的迷宫 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 D ...

  9. hdu 3635 Dragon Balls(并查集应用)

    Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...

随机推荐

  1. nginx基本参数详解

    运行用户 user nobody; 启动进程,通常设置成和cpu的数量相等 worker_processes 1; 全局错误日志及PID文件 error_log logs/error.log; err ...

  2. Django-03

    知识预览 分页器(paginator) COOKIE 与 SESSION Django的用户认证 FORM 回到顶部 分页器(paginator) 分页器的使用 1 2 3 4 5 6 7 8 9 1 ...

  3. python--pycharm汉化

    一.准备工具 1.pycharm软件 2.汉化包 二.解压汉化包 三.将resources_cn.jar复制到pycharm文件中lib目录下 四.重新打开pycharm

  4. Linux_总结_01_VMware14虚拟机下安装CentOS7.x

    一.前言 本文是采用最小安装方式 二.下载 1.官网 https://www.centos.org/download/ 在此页面下,选择 Minimal ISO 进行下载. 三.VMWare中新建虚拟 ...

  5. react-webpack(一)

    要让webpack知道这就是我们的index.html入口文件,并且我们不需要手动引入打包后的js文件,需要安装html-webpack-plugin npm install html-webpack ...

  6. 源码编译安装mysql5.6

    1.download the source package and unzip to the destination dir http://mirror.switch.ch/mirror/mysql/ ...

  7. Busybox shell脚本修改密码

    /****************************************************************************** * Busybox shell脚本修改密 ...

  8. HDU - 5412 CRB and Queries (整体二分)

    题目链接 动态区间第k小,但是这道题的话用主席树+树状数组套线段树的空间复杂度是O(nlog2n)会爆掉. 另一种替代的方法是用树状数组套平衡树,空间复杂度降到了O(nlogn),但我感觉平衡树是个挺 ...

  9. CodeForces - 13D :Triangles(向量法:问多少个蓝点三角形内部无红点)

    Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three ...

  10. Kerberos的hive链接问题

    javax.security.auth.login.LoginException: Checksum failed 之前碰到过类似的问题,都是因为服务器端的keytab问题:多半是因为重新生成了key ...