Description

Mirko is a huge fan of chess and programming, but typical chess soon became boring for him, so he started having fun with rook pieces. He found a chessboard with N rows and N columns and placed K rooks on it. Mirko’s game is made of the following rules:

1. Each rook’s power is determined by an integer.

2. A rook sees all the fields that are in his row or column except its own field.

3. We say that a field is attacked if the binary XOR of all the powers of the rooks that see the field is greater than 0.

Notice that the field a rook is at can be attacked or not. Initially, Mirko placed the rooks in a certain layout on the board and will make P moves. After each move, determine how many fields are attacked. Every rook can be moved to any free field on the whole
board (not only across column and row).

Input

The first line of input contains integers N, K, P (1 ≤ N ≤ 1 000 000 000, 1 ≤ K ≤ 100 000, 1 ≤ P ≤ 100 000). Each of the following K lines contains three integers R, C, X (1 ≤ R, C ≤ N, 1 ≤ X ≤ 1 000 000 000) which denote that initially there is a rook of power
X on the field (R, C). Each of the following P lines contains four integers R1, C1, R2, C2 (1 ≤ R1, C1, R2, C2 ≤ N) which denote that the rook has moved from field (R1, C1) to field (R2, C2). It is guaranteed that there will not be two rooks on one field at
any point.

Output

The output must consist of P lines, the k th line containing the total number of attacked fields after k moves.

Sample Input

2 2 2

1 1 1

2 2 1

2 2 2 1

1 1 1 2

2 2 2

1 1 1

2 2 2

2 2 2 1

1 1 1 2

3 3 4

1 1 1

2 2 2

2 3 3

2 3 3 3

3 3 3 1

1 1 1 2

3 1 3 2

Sample Output

4

0

4

2

6

7

7

9

题意:有n*n的矩阵,放了k只乌鸦,每一只乌鸦能看到和它所在位置同一行的和同一列的格子,除了它自己站的位置,有p次操作,每次操作把一只乌鸦从原来站的位置放到另外一个位置,问每次操作后被看到的次数的异或和不为0的格子总数。

思路:用map记录第i行,第j列的异或值以及异或值为i的行,列的个数,然后每次移动一个子后,考虑失去这一格子对应的值value后对总的sum的影响,再考虑这一格子变成value^value后的值。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 600000
#define maxn 100050
ll sum;
int n;
map<int,int>rxor,cxor; //rxor[i]=j map里第i行的异或值
map<int,int>rcnt,ccnt; //rcnt[i]=j异或值为i的行的个数
map<pair<int,int> ,int>mp; void remove(int r,int c,int value)
{
int i,j;
sum-=n-ccnt[rxor[r] ];
sum-=n-rcnt[cxor[c] ];
if(rxor[r]!=cxor[c]){
sum++;
} rcnt[rxor[r] ]--;
rxor[r]^=value;
rcnt[rxor[r] ]++; ccnt[cxor[c] ]--;
cxor[c]^=value;
ccnt[cxor[c] ]++; sum+=n-ccnt[rxor[r] ];
sum+=n-rcnt[cxor[c] ];
if(rxor[r]!=cxor[c]){
sum--;
}
mp[make_pair(r,c) ]^=value;
}
int main()
{
int m,i,j,k,p;
int r1,r2,c1,c2,value;
while(scanf("%d%d%d",&n,&k,&p)!=EOF)
{
rcnt[0]=ccnt[0]=n;
for(i=1;i<=k;i++){
scanf("%d%d%d",&r1,&c1,&value);
remove(r1,c1,value);
}
for(i=1;i<=p;i++){
scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
value=mp[make_pair(r1,c1)];
remove(r1,c1,value);
remove(r2,c2,value);
printf("%lld\n",sum);
}
}
return 0;
}

zjnu1707 TOPOVI (map+模拟)的更多相关文章

  1. PAT 1002 A+B for Polynomials(map模拟)

    This time, you are supposed to find A+B where A and B are two polynomials(多项式). Input Each input fil ...

  2. UVa 1596 Bug Hunt (string::find && map && 模拟)

    题意 : 给出几组由数组定义与赋值构成的编程语句, 有可能有两种BUG, 第一种为数组下标越界, 第二种为使用尚未定义的数组元素, 叫你找出最早出现BUG的一行并输出, 每组以' . '号分隔, 当有 ...

  3. poj 3087 Shuffle'm Up ( map 模拟 )

    题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s ...

  4. CF981B Businessmen Problems map 模拟 二十二

    Businessmen Problems time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. 修改Map中确定key对应的value问题

    今天在码代码的时候出现一个没有预料的问题: 先看下面的代码: public static void main(String[] args) { String[] files=new String[]{ ...

  6. cache—主存—辅存三级调度模拟

    近日,在体系结构的课程中,老师留了一个上机作业,为cache—主存—辅存三级调度模拟,要求如下: 实现三级存储体系的模拟调度程序 描述:CPU在cache访问数据块,若命中给出对应的cache实地址, ...

  7. 模拟stringBeanFactory解析xml

    思路:根据源码分析,将配置Bean类信息存放到xml文件中,通过解析xml, 然后反射拿到对象 存放到集合中 这里选择hashmap(键放置类名,值放置对象)存放,使用时使用get方法通过键(类名)拿 ...

  8. STL复习之 map & vector --- disney HDU 2142

    题目链接: https://vjudge.net/problem/40913/origin 大致题意: 这是一道纯模拟题,不多说了. 思路: map模拟,vector辅助 其中用了map的函数: er ...

  9. 5-05. QQ帐户的申请与登陆(25)(map运用)(ZJU_PAT)

    题目链接:http://pat.zju.edu.cn/contests/ds/5-05 实现QQ新帐户申请和老帐户登陆的简化版功能. 最大挑战是:据说如今的QQ号码已经有10位数了. 输入格式说明: ...

随机推荐

  1. MalformedByteSequenceException: 1字节的 UTF-8 序列的字节 1 无效

    记住,每次修改了配置之后都 clean 一下,把 target 删除 第一种解决方案 去掉 pom.xml 中的 properties <properties> <maven.com ...

  2. 【Oracle】userenv()函数介绍分析

    说到这个userenv()使用起来还是很有用的 参数   功能 CLINET_INFO                                      返回最高可达64个字节存储的用户会话信 ...

  3. 【Oracle】创建用户配额总是不足的解决问题 quota

    在oracle中,正常创建的用户是没有配额限制的,也就是默认的是unlimited on tablespace的,但是在有些时候,没有设置相关的配额,用户总是会报错用户配额严重不足,查看表空间,也有很 ...

  4. LeetCode349. 两个数组的交集

    题目 给定两个数组,编写一个函数来计算它们的交集. 分析 数组元素值可以很大,所以不适合直接开数组进行哈希,这里要学习另一种哈希方式:集合 集合有三种,区别见下面代码随想录的Carl大佬的表格,总结的 ...

  5. LeetCode590. N叉树的后序遍历

    题目 1 class Solution { 2 public: 3 vector<int>ans; 4 vector<int> postorder(Node* root) { ...

  6. C#使用OracleParameter操作数据库

    public static int GetScalar(string sql,params OracleParameter [] OracleParms) { using (OracleConnect ...

  7. layui表格前端格式化时间戳字段

    layui.use(['util','table'], function(){   var table = layui.table;   var util = layui.util;   //... ...

  8. HTTPS请求HTTP接口被浏览器阻塞,python实现websocket客户端,websocket服务器,跨域问题,dwebsocket,https,拦截,服务端

    HTTPS请求HTTP接口被浏览器阻塞,python实现websocket客户端,websocket服务器,跨域问题,dwebsocket,https,拦截,服务端 发表时间:2020-03-05 1 ...

  9. python中json模块的使用

    Python自带json模块,它有loads.dumps.load和dump这4个功能,用于Json格式字符串和Python数据类型间进行转换. 一.json.loads() 把Json格式字符串解码 ...

  10. 笔记 | 吴恩达新书《Machine Learning Yearning》

    这本书共112页,内容不多,偏向于工程向,有很多不错的细节,在此记录一下. 0 书籍获取 关注微信公众号"机器学习炼丹术",回复[MLY]获取pdf 1 测试集与训练集的比例 2 ...