题面以及思路: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. AI探索(一)基础知识储备

    AI的定义 凡是通过机器学习,实现机器替代人力的技术,就是AI.机器学习是什么呢?机器学习是由AI科学家研发的算法模型,通过数据灌输,学习数据中的规律并总结,即模型内自动生成能表达(输入.输出)数据之 ...

  2. 关于一家大型互联网公司的.NET面试

    上周去了一家大型的互联网公司去面试!四个面试官提的问题整理下!以后会注明答案! 1.关于垃圾回收的过程!GC的过程 其中包含:什么是根,Finalize与Dispose的区别,什么时候用到!IDisp ...

  3. LeetCode OJ:Count and Say(数数)

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  4. 服务器端使用DeferredResult异步推送技术

    注意1: org.springframework.web.context.request.async.DeferredResult; 是Spring4.0以后的版本才有的,注意Spring版本,然后添 ...

  5. db2生成连续日期

    //生成时间段内连续日期 select * from ( select date('2008-01-01') + (row_NUMBER() over () -1) days AS datennn f ...

  6. Thinkphp5.0 获取新增数据的ID

    // 方法1 insertGetId方法新增数据并返回主键值使用getLastInsID方法: Db::name('user')->insert($data); $userId = Db::na ...

  7. mapreduce-实现单表关联

    //map类 package hadoop3; import java.io.IOException; import org.apache.hadoop.io.LongWritable;import ...

  8. 学习动态性能表(9)--v$filestat

    学习动态性能表 第九篇--V$FILESTAT  2007.6.5 本视图记录各文件物理I/O信息.如果瓶颈与I/O相关,可用于分析发生的活动I/O事件.V$FILESTAT显示出数据库I/O的下列信 ...

  9. Word 2007 如何设置正文第一页----目录显示正文从第一页开始

    最近学校里开始要求写论文了,其中有个目录中的页码都不是从第一页开始的,毕竟前面还有封面.中英文摘要.目录等,所以正文内容就不是从第一页开始的了,但是很多的书上所有正文都是从第一页开始的,我的论文如何才 ...

  10. http协议及原理分析 1

    1:200与304的区别 浏览器第一次加载成功返回200状态,并会在浏览器的缓存中记录下 max-age 这个值.第二次发起服务器的访问时 会先看缓存中有没有要加载的资源 如果有 再去看有没有超出 m ...