题解 u
- 这里AC解法因为手残
tag2[min(r+l, n+1)][min(c+l+1, n+1)]+=s;写成tag2[min(r+l, n+1)][c+l+1]+=s;惨遭RE,以后注意查边界,还有数组能开下的话尽量开两倍 - 跑对拍一定要跑几组极限数据,看看会不会RE什么的
发现q比较大,单次操作最慢也得是\(O(log^2n)\)的
都是区间加减,拆成n列直接差分的话单次操作是\(O(n)\)的,有点悬
注意到这里是等腰直角三角形,标记可以斜着传
那就在左上顶点打一个加法标记,左下顶点打一个减法标记
加法标记向正下和右下传,减法标记向右边传
然后标记直接互相抵消还有不少细节
Code:
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 1010
#define ll long long
#define ld long double
#define usd unsigned
#define ull unsigned long long
//#define int long long
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1<<21, stdin)), p1==p2?EOF:*p1++)
char buf[1<<21], *p1=buf, *p2=buf;
inline int read() {
int ans=0, f=1; char c=getchar();
while (!isdigit(c)) {if (c=='-') f=-f; c=getchar();}
while (isdigit(c)) {ans=(ans<<3)+(ans<<1)+(c^48); c=getchar();}
return ans*f;
}
int n, q;
namespace force{
ll mat[N][N];
void solve() {
int r, c, l, s;
for (int i=1; i<=q; ++i) {
r=read(); c=read(); l=read(); s=read();
for (int x=r; x<r+l&&x<=n; ++x)
for (int y=c; y<=x-r+c&&y<=n; ++y)
mat[x][y]+=s;
}
ll ans=0;
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) ans^=mat[i][j];
//for (int i=1; i<=n; ++i) {for (int j=1; j<=n; ++j) cout<<mat[i][j]<<' '; cout<<endl;}
printf("%lld\n", ans);
}
}
namespace task2{
ll mat[N][N], tag1[N][N], tag2[N][N];
void solve() {
int r, c, l, s;
for (int i=1; i<=q; ++i) {
r=read(); c=read(); l=read(); s=read();
tag1[r][c]+=s; tag1[min(r+l+1, n+1)][min(c+l+1, n+1)]-=s;
tag2[min(r+l, n+1)][c]-=s; tag2[min(r+l, n+1)][min(c+l+1, n+1)]+=s;
}
for (int j=1; j<=n; ++j) {
ll now=0;
for (int i=1; i<=n; ++i) {
now+=tag1[i][j]+tag2[i][j];// now+=tag2[i][j];
mat[i][j]=now;
//tag1[i][j]+=tag2[i][j];
//assert(tag1[i][j]==now);
tag1[i+1][j+1]+=tag1[i][j];
tag2[i][j+1]+=tag2[i][j];
//tag2[i][j+1]+=tag2[i][j];
}
}
ll ans=0;
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) ans^=mat[i][j];
//for (int i=1; i<=n; ++i) {for (int j=1; j<=n; ++j) cout<<mat[i][j]<<' '; cout<<endl;}
printf("%lld\n", ans);
}
}
signed main()
{
#ifdef DEBUG
freopen("1.in", "r", stdin);
#endif
n=read(); q=read();
if (!q) {puts("0"); return 0;}
//force::solve();
task2::solve();
return 0;
}
题解 u的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
- JSOI2016R3 瞎BB题解
题意请看absi大爷的blog http://absi2011.is-programmer.com/posts/200920.html http://absi2011.is-programmer.co ...
随机推荐
- 使用xcodeproj 动态插入第三方代码
# 为什么这么做? 现在有这么一个使用场景,基线能生成项目A,项目B,项目C...如果只有项目A中使用SDK_A,其他项目都不使用,这时候就需要对基线进行差分,只有当我切换到项目A时,才插入SDK_A ...
- 从零学习SpringSecurity
一.简介 SpringSecurity是一个功能强大且高度可定制的身份验证和访问控制框架,和spring项目整合更加方便. 二.核心功能 认证(Authentication):指的是验证某个用户能否访 ...
- python05篇 json和函数
一.json json就是一个字符串,只不过是所有语言能解析这个字符串.1.1 把python的数据类型转为json import json d = {'name': 'xiaohei', 'cars ...
- 以太网MAC地址组成与交换机基本知识
以太网MAC地址 MAC地址由48位二进制组成,通常分为六段,用十六进制表示,工作在数据链路层. 数据链路层功能: 链路的建立,维护与拆除 帧包装,帧传输,帧同步 帧的差错恢复 简单的流量控制 第八位 ...
- 1.在配置XML文件时出现reference file contains errors (http://www.springframework.org/schema/beans/...解决方案
解决方案: 第一步:将 Preferences > XML > XML Files > Validation中"Honour all XML schema location ...
- LeetCode 780. Reaching Points
题目链接:https://leetcode.com/problems/reaching-points/ 题意:给定操作可以使点(x,y)变为点(x+y,y)或者点(x,x+y).现已知初始点(sx,s ...
- ORB随便记一记
论文摘取 (这部分看的是泡泡机器人的翻译) 基于特征点.单目.完全自动初始化,基于PTAM框架. 相关工作 A.位置识别(大概是用于回环检测) bags of words FAB-map DBOW2 ...
- linux相关的常用站点
1 http://cdimage.ubuntu.com/ ubuntu各个发行版的总集服务器 2 http://www.rpmfind.net/ 各种RPM包
- 使用vue-preview报错Cannot read property 'open' of undefined
最近在做一个vue项目中时,需要使用vue-preview插件制作缩略图,首先在终端使用npm i vue-preview -S指令安装了vue-preview插件,然后在main.js中,导入并引用 ...
- Python 创建一个Django项目
1 环境搭建及创建 1) 安装Django 方法一:pip install django 方法二:Pycharm File--settings--Project--Python Interpreter ...