zjnu1707 TOPOVI (map+模拟)
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+模拟)的更多相关文章
- 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 ...
- UVa 1596 Bug Hunt (string::find && map && 模拟)
题意 : 给出几组由数组定义与赋值构成的编程语句, 有可能有两种BUG, 第一种为数组下标越界, 第二种为使用尚未定义的数组元素, 叫你找出最早出现BUG的一行并输出, 每组以' . '号分隔, 当有 ...
- poj 3087 Shuffle'm Up ( map 模拟 )
题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s ...
- CF981B Businessmen Problems map 模拟 二十二
Businessmen Problems time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 修改Map中确定key对应的value问题
今天在码代码的时候出现一个没有预料的问题: 先看下面的代码: public static void main(String[] args) { String[] files=new String[]{ ...
- cache—主存—辅存三级调度模拟
近日,在体系结构的课程中,老师留了一个上机作业,为cache—主存—辅存三级调度模拟,要求如下: 实现三级存储体系的模拟调度程序 描述:CPU在cache访问数据块,若命中给出对应的cache实地址, ...
- 模拟stringBeanFactory解析xml
思路:根据源码分析,将配置Bean类信息存放到xml文件中,通过解析xml, 然后反射拿到对象 存放到集合中 这里选择hashmap(键放置类名,值放置对象)存放,使用时使用get方法通过键(类名)拿 ...
- STL复习之 map & vector --- disney HDU 2142
题目链接: https://vjudge.net/problem/40913/origin 大致题意: 这是一道纯模拟题,不多说了. 思路: map模拟,vector辅助 其中用了map的函数: er ...
- 5-05. QQ帐户的申请与登陆(25)(map运用)(ZJU_PAT)
题目链接:http://pat.zju.edu.cn/contests/ds/5-05 实现QQ新帐户申请和老帐户登陆的简化版功能. 最大挑战是:据说如今的QQ号码已经有10位数了. 输入格式说明: ...
随机推荐
- mysql中的kill
show processlist;查看id, 然后 kill id ; 就行了.
- qmake奇淫技巧之字符串宏定义
阅读本文大概需要3.3分钟 我们平时在软件开发过程中需要定义一些宏,以便在代码中调用,这样每次不需要修改代码,只需要修改外部编译命令就可以得到想要的参数,非常方便 比如我们想在软件介绍中显示软件版本, ...
- ctfhub技能树—文件上传—00截断
什么是00截断 相关教程:http://www.admintony.com/%E5%85%B3%E4%BA%8E%E4%B8%8A%E4%BC%A0%E4%B8%AD%E7%9A%8400%E6%88 ...
- 分布式系统:xxl-job改造spring-cloud
目录 改造原因 主要改造思路 调度中心 调度中心 执行器侧 总结 修改后的源码仓库地址:GitHub. : 改造原因 原有的xxl-job使用自己实现的http协议进行注册以及调度等,与目前框架中本身 ...
- ORA-00054: 資源正被使用中, 請設定 NOWAIT 來取得它, 否則逾時到期
1.查看被使用资源的OBJECT_ID SELECT *FROM DBA_OBJECTS WHERE OBJECT_NAME='OBJECT_NAME' 2.查看资源被谁占用SELECT * FROM ...
- JVM 判断对象已死,实践验证GC回收
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 提升自身价值有多重要? 经过了风风雨雨,看过了男男女女.时间经过的岁月就没有永恒不变 ...
- Kubernetes 升级过程记录:从 1.17.0 升级至最新版 1.20.2
本文记录的是将 kubernetes 集群从 1.17.0 升级至最新版 1.20.2 的实际操作步骤,由于 1.17.0 无法直接升级到 1.20.2,需要进行2次过滤升级,1.17.0 -> ...
- mybatis中传集合时 报异常 invalid comparison: java.util.Arrays$ArrayList and java.lang.String
犯了一个低级的错误,在传集合类型的参数时,把他当成字符串处理了,导致报类型转换的错误 把 and nsrsbh!=' ' 删掉就行了
- vue中computed/method/watch的区别
摘要:本文通过官方文档结合源码来分析computed/method/watch的区别. Tips:本文分析的源码版本是v2.6.11,文章中牵涉到vue响应式系统原理部分,如果不是很了解,建议先阅读上 ...
- 使用fdopen对python进程产生的文件进行权限最小化配置
需求背景 用python进行文件的创建和读写操作时,我们很少关注所创建的文件的权限配置.对于一些安全性较高的系统,如果我们创建的文件权限其他用户或者同一用户组里的其他用户有可读权限的话,有可能导致不必 ...