2019icpc南京网络赛 A The beautiful values of the palace(离线+树状数组)
题意:
(假设所有的点对应的值已经求出)给你一个1e6*1e6的矩阵,有m<=1e5个点有值,其余都为0
q<=1e5个询问,求子矩阵的权值和
思路:
根据二维差分,对于询问左下角(x1,y1),右上角(x2,y2)
该询问答案为a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]
其中a为二维前缀和
那么我们把询问拆成四个前缀和,和m个点一起离线,树状数组更新答案即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); struct node{
ll lx;//U1 Q0
ll id,x,y,v;
node(){}
node(ll lx, ll id, ll x, ll y, ll v):lx(lx),id(id),x(x),y(y),v(v){
printf("**%lld %lld %lld %lld %lld\n",lx,id,x,y,v);
}
}Q[maxn];
bool cmp(node a, node b){
if(a.x==b.x&&a.y==b.y){
return a.lx>b.lx;
}
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
ll tree[maxn];
ll ans[maxn];
ll n, m, q;
void add(int x, ll c){for(int i=x;i<=n;i+=lowbit(i))tree[i]+=c;}
ll sum(int x){
ll ans = ;
for(int i = x; i; i-=lowbit(i))ans+=tree[i];
return ans;
}
int main() {
int t;
scanf("%d", &t);
while(t--){
scanf("%lld %lld %lld", &n, &m, &q);
int tot = ;
for(int i = ; i < maxn; i++){
tree[i]=ans[i]=;
}
for(int i = ; i <= m; i++){
ll x, y;
ll res;
scanf("%lld %lld", &x, &y);
x=x-n/-;y=y-n/-;
ll T = max(abs(x),abs(y));
if(x>=y)res=1ll*n*n-*T*T-*T-x-y;
else res=1ll*n*n-*T*T+*T+x+y;
ll c=;
while(res){c+=res%;res/=;}
Q[++tot]=node(,i,x+n/+,y+n/+,c);
}
for(int i = ; i <= q; i++){
ll x1,y1,x2,y2;
scanf("%lld %lld %lld %lld",&x1, &y1, &x2, &y2);
Q[++tot]=node(,i,x2,y2,);
Q[++tot]=node(,i,x1-,y1-,);
Q[++tot]=node(,i,x1-,y2,-);
Q[++tot]=node(,i,x2,y1-,-);
}
sort(Q+,Q++tot,cmp);
for(int i = ; i <= tot; i++){
if(Q[i].x<||Q[i].y<)continue;
if(Q[i].lx==)add(Q[i].y,Q[i].v);
else ans[Q[i].id]+=1ll*Q[i].v*sum(Q[i].y);
}
for(int i = ; i <= q; i++){
printf("%lld\n",ans[i]);
}
}
return ;
}
/*
22
3 4 4
1 1
2 2
3 3
2 3
1 1 1 1
2 2 3 2
1 1 2 2
1 1 2 3
*/
2019icpc南京网络赛 A The beautiful values of the palace(离线+树状数组)的更多相关文章
- 2019ICPC南京网络赛A The beautiful values of the palace
题意:蛇形填数超大版本,需要求出一些给定坐标的值的数位和,然后q次询问,一个矩形区域内值的和是多少 解题思路:二维偏序前缀和的经典题 二维偏序:求(x,y)左下角点的个数,思路是对x,y升序排序,用树 ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 A The beautiful values of the palace(树状数组+思维)
Here is a square matrix of n * nn∗n, each lattice has its value (nn must be odd), and the center val ...
- 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)
2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...
- 2019icpc南京网络赛_F_Greedy Sequence
题意 题意不明,队友告诉我对于每个\(i\),所在下标\(p[i]\),在\([p[i]-k,p[i]+k]\)中找到小于\(i\)的最大数\(x\),然后\(ans[i]=ans[x]+1\)即可. ...
- 2019ICPC南京网络赛B super_log——扩展欧拉定理
题目 设函数 $$log_a*(x) = \begin{cases}-1, & \text{ if } x < 1 \\ 1+log_a*(log_ax) & \text{ if ...
- 2019icpc南京网络赛
B. super_log(扩展欧拉函数) 题意:求aa...(b个a)模M的值. 思路:递归用欧拉函数求解,我们知道欧拉降幂公式: 如果讨论b和φ(p)的关系会很麻烦,网上证明了一种精妙的方法,只需重 ...
- 2019icpc南京网络赛 A 主席树
题意 给一个\(n\times n\)的螺旋矩阵,给出其中的\(m\)个点的值分别为各个点上数字的数位之和,给出\(q\)个询问,每次询问从\((x1,y1)\)到\((x2,y2)\)的子矩阵的和. ...
- 2019icpc南京网络赛 F 主席树
题意 给一个\(n\)的全排列数组\(a\),求一个递推数组每一项的值:\(ans[i]=ans[j]+1\),\(j\)为\(a[pos[i]-k]到a[pos[i]+k],(pos[i]为i在数组 ...
- 2019ICPC南京网络赛总结
这次是在学校打的,总体不算好,过两题校排200多..很惨. 开场一段时间没人过题,但是很多人交I, 我也就再看,看着看着发现不可做,这时候转F,花了半天读懂题意的时候想到主席树查找.但是主席树这种查找 ...
随机推荐
- 12款好用的Visual Studio插件,最后一款良心推荐
目录 01 CodeMaid 02 Markdown Editor 03 ReSharper 04 GitHub Extension for Visual Studio 05 ZenCoding 06 ...
- 基于GMC/umat的复合材料宏细观渐近损伤分析(一)
近期在开展基于GMC/umat的复合材料宏细观渐近损伤分析,一些技术细节分享如下: 1.理论基础 针对连续纤维增强复合材料,可以通过离散化获得如下的模型: (a)(b)(c) 图1 连续纤维增强复合材 ...
- cannot open git-upload-pack,cannot open git-receive-pack,Can't connect to any URI错误解决方法eclipse
cannot open git-upload-pack,cannot open git-receive-pack,Can't connect to any URI错误解决方法eclipse 解决ecl ...
- Http GetPost网络请求
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System ...
- 【Javascript函数】节流throttle和间隔控制dbounce
一.throttle 函数节流,指把很小时间内触发的N多事件,节流成1个事件. 我们这里说的throttle就是函数节流的意思.再说的通俗一点就是函数调用的频度控制器,是连续执行时间间隔控制.主要应用 ...
- webpack实践——DLLPlugin 和 DLLReferencePlugin的使用
DLLPlugin 和 DLLReferencePlugin的使用 DLLPlugin 和 DLLReferencePlugin 用某种方法实现了拆分 bundles,同时还大大提升了构建的速度. 1 ...
- ArcEngine语法笔记(VB)
1.获取图层字段 Dim pTable As ITable = pLayer Dim pField As IField pField = pTable.Fields.Field(i) Next 2. ...
- C#实现文件Move操作和文件的Copy操作
文件移动(Move)操作和文件的复制(Copy)是C#程式开发经常遇到的方法,根据传入的源文件地址和目标文件地址参数,实现对文件的操作.实现代码如下: Move操作代码: public static ...
- spring boot 集成apollo 快速指南
目前市面上流行的三大配置中心框架:Spring CLoud Config .Alibaba Nacos 以及携程apollo, 我们相应架构组号召,就使用Apollo吧. Work Flow 简单解释 ...
- Java入门 - 导读
原文地址:http://www.work100.net/training/java 更多教程:光束云 - 免费课程 Java入门 Java 是由 Sun Microsystems 公司于1995年5月 ...