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. 非root用户安装centos的jdk

    1. 下载linux的jdk到自定义目录(以下简称安装目录),解压. 2. 在安装目录下新建文件局部环境变量文件:bash_profile 内容为:(注意修改JAVA_HOME目录) export J ...

  2. 【Java基础】常用类

    常用类 字符串相关的类 String类:代表字符串,使用一对 "" 引起来表示. public final class String implements java.io.Seri ...

  3. 【EXPDP/IMPDP】ORACLE数据泵导入导出案例(expdp & impdp)

    概要: 因项目需要,通常需要将生产库下的部分数据抽取并恢复到测试库上 本文主要介绍数据泵导入导出的几种情况以及错误处理 案例环境: rhel-server-6.5-x86_64 oracle 11.2 ...

  4. SDUST数据结构 - 19级期末考试

    判断题: 选择题: 函数题: 6-1 统计二叉树叶子结点个数: 题目: 裁判测试程序样例: #include <stdio.h> #include <stdlib.h> typ ...

  5. IE浏览器直接在页面中显示7z文件而不是下载问题解决

    IE浏览器中输入7z文件的完整下载URL后,不是保存文件,而是直接在页面中显示(当然是乱码) 这是因为浏览器对不同的资源文件处理的方式不同,例如图片文件,一般会直接打开,所以我们可以不用7z,使用zi ...

  6. 运行.bat执行sql文件 —— mysql

    参考地址:https://www.cnblogs.com/dingjiaoyang/p/9990188.html 运行test.bat 执行 test.sql文件 test.bat: @ECHO OF ...

  7. 浅谈JavaScript代码性能优化2

    一.减少判断层级 从下图代码中可以明显看出,同样的效果判断层级的减少可以优化性能 二.减少作用域链查找层级 简单解释下,下图中第一个运行foo函数,bar函数内打印name,bar作用域内没有name ...

  8. Python 身份证校验代码

    Python 身份证校验代码 居民身份证bai编号识别 1.身份证编码规则如下:根据[中华人民共和国国家标准GB11643-1999]中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本 ...

  9. 浅谈自动化构建之grunt

    自动化构建 开发行业的自动化构建 一句话把源代码转化为生产代码,作用是脱离运行环境兼容带来的问题开发阶段使用提高效率的语法,规范 和标准,构建转换那些不被支持的特性转化成能够执行的代码. 一.简单的自 ...

  10. 无法获取 vmci 驱动程序版本: 句柄无效。 驱动程序 vmci.sys 版本不正确。请尝试重新安装 VMware Workstation。 打开模块DevicePowerOn电源失败。

    1.别打开电源,然后到虚拟机安装文件夹内.2.找到你的虚拟机系统文件中后缀为vmx的文件,右击用记事本或者Notepad++打开.2.搜索找到vmci0.present='TRUE',字段,把true ...