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

  

转载于:https://www.cnblogs.com/pkgunboat/p/10547905.html

HDU 4879 ZCC loves march (并查集,set,map)相关推荐

  1. hdu 4876 ZCC loves cards(暴力)

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

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

    HDU 4873 ZCC Loves Intersection 题目链接 题意:d维的.长度为n的块中,每次选d条平行于各条轴的线段,假设有两两相交则点数加1,问每次得到点数的期望是多少 思路:自己推 ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ZCC Loves Codefires Time Limit: 2000/1000 MS (Ja ...

  4. How Many Answers Are Wrong HDU - 3038(带权并查集经典题,满满的都是注释)

    How Many Answers Are Wrong HDU - 3038  点击打开链接 题意:现在有n个数(你并不知道这n个数是什么),m次查询,每次查询给出u,v,w.表示从第u个数到第v个数的 ...

  5. hdu 1232 畅通工程 最小生成树 并查集

    1232的连接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 #include <iostream>#include <cstdio& ...

  6. HDU 1213 How Many Tables 并查集 水~

    http://acm.hdu.edu.cn/showproblem.php?pid=1213 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶 ...

  7. hdu 3234 Exclusive-OR 题解(并查集,思维)

    该死的期末复习终于结束了... 暑假来了\color{#ff0000}{暑假来了}暑假来了!!! 所以我就珂以非常开心的写博客了. 原题链接: hdu 题意简述 多组数据.你有一个没有确定的数列.有一 ...

  8. HDU 1272 小希的迷宫 (并查集)

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  9. hdu 1811 Rank of Tetris (并查集+拓扑排序)

    Problem - 1811 感觉这题的并查集以及拓扑排序并不难,但是做题的时候必须理解到矛盾(CONFLICT)与不确定(UNCERTAIN)直接的优先关系. 做这题的时候,构图什么的很简单,就是没 ...

最新文章

  1. SQL 全角半角转换-(摘抄)
  2. 点击事件调用匿名函数如何传参_事件发布/订阅模式的简单实现
  3. Nginx的rewrite之if指令(一)
  4. Leet Code OJ 231. Power of Two [Difficulty: Easy]
  5. html5页面热力图几十万数据,基于百度地图的数据可视化,包括大量数据的标绘以及热力图的插入...
  6. c语言字符常量和字符串常量_C语言中的字符常量
  7. 安装 RabbitMQ
  8. android添加工程依赖工程,将项目依赖项添加到Android studio中的另一个项目
  9. 安装sphinx的心得和错误处理
  10. 行业领军的高压线性恒流驱动IC,真正长寿的半导体线性IC
  11. 【业务知识】金融、银行业务知识点(转载)
  12. 陈洁kiki宠粉节狂欢夜观看破千万!四年磨一剑将宠粉做到极致
  13. 解决宝塔面板开启HTTS后,Edge不能访问的问题
  14. java 不同包 调用_java中不同包之间的调用
  15. 联想台式计算机重装系统教程,联想台式机重装win7系统教程
  16. 微信公众平台群发消息里,为什么一天只能发一条
  17. Latex公式字母加粗
  18. 《C++ STL编程实战》读书笔记(四)
  19. PHP 亿级 pv 网站架构实战之性能压榨
  20. 君子剑,怎样炼成?——再再谈岳不群

热门文章

  1. C语言中如何求一天是星期几,计算任何一天是星期几的C语言源代码.
  2. android studio 加载ffmpeg.so,Android studio使用已经编译好的ffmpeg .so库
  3. linux win 时间不同步,[转]解决Win7和Linux Deepin双系统时间不同步的问题
  4. 数据结构讲义代码堆和栈、多线程、多进程、网络编程
  5. (2) 用java实现一个简易编译器1-词法解析入门
  6. mysql创建索引小案例
  7. python类和对象实例_python的类和实例化对象
  8. 数据结构(七)---循环队列的实现---java版
  9. Python科学计算:Pandas
  10. Kafka 副本OffsetOutOfRangeException