题意:

(假设所有的点对应的值已经求出)给你一个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(离线+树状数组)的更多相关文章

  1. 2019ICPC南京网络赛A The beautiful values of the palace

    题意:蛇形填数超大版本,需要求出一些给定坐标的值的数位和,然后q次询问,一个矩形区域内值的和是多少 解题思路:二维偏序前缀和的经典题 二维偏序:求(x,y)左下角点的个数,思路是对x,y升序排序,用树 ...

  2. 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 ...

  3. 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 ...

  4. 2019icpc南京网络赛_F_Greedy Sequence

    题意 题意不明,队友告诉我对于每个\(i\),所在下标\(p[i]\),在\([p[i]-k,p[i]+k]\)中找到小于\(i\)的最大数\(x\),然后\(ans[i]=ans[x]+1\)即可. ...

  5. 2019ICPC南京网络赛B super_log——扩展欧拉定理

    题目 设函数 $$log_a*(x) = \begin{cases}-1, & \text{ if } x < 1 \\ 1+log_a*(log_ax) & \text{ if ...

  6. 2019icpc南京网络赛

    B. super_log(扩展欧拉函数) 题意:求aa...(b个a)模M的值. 思路:递归用欧拉函数求解,我们知道欧拉降幂公式: 如果讨论b和φ(p)的关系会很麻烦,网上证明了一种精妙的方法,只需重 ...

  7. 2019icpc南京网络赛 A 主席树

    题意 给一个\(n\times n\)的螺旋矩阵,给出其中的\(m\)个点的值分别为各个点上数字的数位之和,给出\(q\)个询问,每次询问从\((x1,y1)\)到\((x2,y2)\)的子矩阵的和. ...

  8. 2019icpc南京网络赛 F 主席树

    题意 给一个\(n\)的全排列数组\(a\),求一个递推数组每一项的值:\(ans[i]=ans[j]+1\),\(j\)为\(a[pos[i]-k]到a[pos[i]+k],(pos[i]为i在数组 ...

  9. 2019ICPC南京网络赛总结

    这次是在学校打的,总体不算好,过两题校排200多..很惨. 开场一段时间没人过题,但是很多人交I, 我也就再看,看着看着发现不可做,这时候转F,花了半天读懂题意的时候想到主席树查找.但是主席树这种查找 ...

随机推荐

  1. ASCII、UNICODE、UTF

    在计算机中,一个字节对应8位,每位可以用0或1表示,因此一个字节可以表示256种情况. ascii 美国人用了一个字节中的后7位来表达他们常用的字符,最高位一直是0,这便是ascii码. 因此asci ...

  2. 二次排序LincodeNo.846

    846.Multi-keyword Sort 题目要求在已经排序好的序列上进行二次排序 那么改变一下比较方法即可 bool cmp(vector<int> a,vector<int& ...

  3. codevs 3981 动态最大子段和(线段树)

    题目传送门:codevs 3981 动态最大子段和 题目描述 Description 题目还是简单一点好... 有n个数,a[1]到a[n]. 接下来q次查询,每次动态指定两个数l,r,求a[l]到a ...

  4. php改变时间的方法

    1. strtotime date("Y-m-d",strtotime('+1day')) 2. mktime date("Y-m-d",mktime(0,0, ...

  5. Scala实践12

    1.内部类和抽象类型成员作为对象成员 内部类 在Scala中,可以让类将其他类作为成员.这些内部类是封闭类的成员.在Scala中,这样的内部类绑定到外部对象.假设希望编译器在编译时阻止我们混合哪些节点 ...

  6. Java List集合的介绍与常用方法

    List接口的介绍 List接口简介: java.util.List接口继承自Collection接口,是单列集合的一个重要分支,习惯性地会将实现了List接口的对象称为List集合. 在List集合 ...

  7. 如何应用threejs实现立方体每个面用图片替换

    var geometry = new THREE.BoxGeometry(200, 200, 200);var materialsbg = []; for (var i = 0; i < geo ...

  8. Quartz定时任务整理

    一. 介绍 Quartz是一个开源的定时任务调度框架,这里就不详细介绍了,我们直入主题Quartz主要由三部分组成 任务:JobDetail 触发器:Trigger,(分两类:SimpleTrigge ...

  9. css 脱离文档流

    一.float <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&quo ...

  10. Frameworks.Entity.Core 7

    1描述:实体基类,与业务和架构无关名称:EntityBase属性:public abstract 2描述:/ MongoDB的一些扩展方法名称:MongoExtensions修饰: public st ...