HDU 4879 ZCC loves march (并查集,set,map)
题面以及思路: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)的更多相关文章
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...
- hdu 4873 ZCC Loves Intersection(大数+概率)
pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...
- hdu 4876 ZCC loves cards(暴力)
题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...
- HDU 4873 ZCC Loves Intersection(可能性)
HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...
- UOJ_14_【UER #1】DZY Loves Graph_并查集
UOJ_14_[UER #1]DZY Loves Graph_并查集 题面:http://uoj.ac/problem/14 考虑只有前两个操作怎么做. 每次删除一定是从后往前删,并且被删的边如果不是 ...
- hdu 4882 ZCC Loves Codefires(数学题+贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...
- HDU HDU1558 Segment set(并查集+判断线段相交)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1558 解题报告:首先如果两条线段有交点的话,这两条线段在一个集合内,如果a跟b在一个集合内,b跟c在一 ...
- hdu 1257 小希的迷宫 并查集
小希的迷宫 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 D ...
- hdu 3635 Dragon Balls(并查集应用)
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...
随机推荐
- c、rust、golang、swift性能比较
mac 计算速度视觉判断是(由好到差):c > rust > swift > golang 内存开销在mac上是(由好到差):c > rust > golang > ...
- Linux下安装scrapy包出错
pip install -i https://pypi.douban.com/simple/ scrapy 出现错误: error: command 将依赖包装全. sudo apt-get inst ...
- LeetCode OJ:Subsets(子集)
Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...
- MySQL 添加、查看字段注释
语法: 创建表时的COMMENT内容,要查看这些内容,使用命令: show full fields from '表名称'; 查看tb_usr表字段注释: 创建新表的脚本中, 可在字段定义脚本中添加co ...
- c++ 修改stl set中的元素
set的迭代器it有const修饰符,那么对它元素的修改就必然不能成功了.但是有时候遇到要修改stl set元素的问题,这个问题一般的解决方法是先erase这个元素,然后再insert,这样效率很低, ...
- 【java规则引擎】简单规则的rete网络示意图
一个Fact通过Session添加到规则网络中,如何进行规则匹配的大致过程如下 (1)通过根结点对象从EntryPointNode的Map集合中找到相应的EntryPointNode对象 (2)Ent ...
- 基于JQ的多选/全选/反选及获取选中的值
<!-- author:青芒 --> <!DOCTYPE html> <html lang="en"> <head> <met ...
- JvisualVm添加远程监控
一.Weblogic远程监控 1.首先需要在远程的weblogic的域下面,找到/bin/ setDomainEnv.sh ,需要在此文件下加入如下内容: -Dcom.sun.management.j ...
- 在ThinkPHP的common.php文件里添加公共函数的注意事项
注意事项: 1.函数不要加public访问控制权限,因为默认就是public的. 2.当你写好了一个新函数后在本地运行发现没有问题,但是在生产环境运行会报错:找不到这个函数,解决方法是删除runtim ...
- 蓝桥杯 基础练习 BASIC-24 龟兔赛跑预测
基础练习 龟兔赛跑预测 时间限制:1.0s 内存限制:512.0MB 问题描述 话说这个世界上有各种各样的兔子和乌龟,但是研究发现,所有的兔子和乌龟都有一个共同的特点——喜欢赛跑.于是世界上各 ...