题面以及思路: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. 论文笔记 — MatchNet: Unifying Feature and Metric Learning for Patch-Based Matching

    论文:https://github.com/ei1994/my_reference_library/tree/master/papers 本文的贡献点如下: 1. 提出了一个新的利用深度网络架构基于p ...

  2. android自定义日期组件之双DatePicker

    1.效果图(两个DatePicker放在一起,同时选择起始与结束时间): 2.实现 2.1布局文件: <?xml version="1.0" encoding="u ...

  3. 简单的shell语句

    1,重启tomcat 脚本: pid=`ps -ef|grep tomcat |grep -v grep |awk '{print $2}'` ##取tomcat的进程号,awk处理字符串 ,取一行的 ...

  4. LeetCode OJ:Kth Smallest Element in a BST(二叉树中第k个最小的元素)

    Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...

  5. 条款47:请使用traits class表示类型信息

    在stl的算法中,我们的希望往往是根据不同的迭代器类型进行不同的更有效率的操作: template<typename IterT, typename DistT> void advance ...

  6. Shell check IP

    #! /bin/bash checkip() {        if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3 ...

  7. python lambda 用途

    可以让一个带参数函数,传递并以无参调用 def test(a): print a a=test # #a() a=897987 fun=lambda : test(a) fun()

  8. Python 2.7_爬取CSDN单页面利用正则提取博客文章及url_20170114

    年前有点忙,没来的及更博,最近看爬虫正则的部分 巩固下 1.爬取的单页面:http://blog.csdn.net/column/details/why-bug.html 2.过程 解析url获得网站 ...

  9. TexStudio 非常好用的Latex软件

    先大概写一下,免得忘了,等有时间详细补充. 跨平台.免费. 语法高亮 方便的公式.符号选择界面 可以配置Latex,pdflatex,xelatex等默认编译命令 集成了pdf阅读器,可在阅读器中浏览 ...

  10. 10.Selenium+Python+任务计划程序实现定时发送邮件

    一.python具体代码实现 # coding=utf-8 import smtplib from email.mime.text import MIMEText from email.header ...