题意:

给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少。

思路:

以后记住:二维前缀和sort+树状数组就行了!!!。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; ll c[N],ans[N];
void Init(int n)
{
for(int i=;i<=n;++i)
c[i]=ans[i]=;
}
void add(int i,ll t)
{
while(i<=N)
{
c[i]+=t;
i+=lowbit(i);
}
}
ll sum(int i)
{
ll sum=;
while(i)
{
sum+=c[i];
i-=lowbit(i);
}
return sum;
}
//-----------------------------------树状数组;
struct node
{
int f;
int x,y,ans_id;
ll val;
friend bool operator<(node a,node b)
{
if(a.y==b.y)
{
if(a.x==b.x)
return a.f<b.f;
return a.x<b.x;
}
return a.y<b.y;
}
}p[N];
ll re_val(ll x)
{
ll sum=;
while(x>)
{
sum+=x%;
x/=;
}
return sum;
}
long long index(long long y,long long x,long long n)
{
long long mid=(n+)/;
long long p=max(abs(x-mid),abs(y-mid));
long long ans=n*n-(+p)*p*;
long long sx=mid+p,sy=mid+p;
if(x==sx&&y==sy)
return ans;
else
{
if(y==sy||x==sx-*p)
return ans+abs(x-sx)+abs(y-sy);
else
return ans+*p-abs(x-sx)-abs(y-sy);
}
}
void solve(int n)
{
for(int i=;i<=n;++i)
{
if(p[i].f) ans[p[i].ans_id]+=sum(p[i].x)*p[i].val;
else add(p[i].x,p[i].val);
}
} int main()
{
int T;
sc("%d",&T);
while(T--)
{
int n,m,ask;
sc("%d%d%d",&n,&m,&ask);
Init(N-);
int cnt=;
for(int i=;i<=m;++i)
{
int x,y;
sc("%d%d",&x,&y);
p[++cnt]={,x,y,-,re_val(index(x,y,n))};
}
for(int i=;i<=ask;++i)
{
int xl,yl,xr,yr;
sc("%d%d%d%d",&xl,&yl,&xr,&yr);
p[++cnt]={,xl-,yl-,i,};
p[++cnt]={,xl-,yr,i,-};
p[++cnt]={,xr,yl-,i,-};
p[++cnt]={,xr,yr,i,};
}
sort(p+,p++cnt);
solve(cnt);
for(int i=;i<=ask;++i)
pr("%lld\n",ans[i]);
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019的更多相关文章

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

  2. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  3. F. Greedy Sequence(主席树区间k的后继)(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 查找区间k的后继. 思路: 直接主席树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio&g ...

  4. bzoj4785:[ZJOI2017]树状数组:二维线段树

    分析: "如果你对树状数组比较熟悉,不难发现可怜求的是后缀和" 设数列为\(A\),那么可怜求的就是\(A_{l-1}\)到\(A_{r-1}\)的和(即\(l-1\)的后缀减\( ...

  5. 树状数组 二维偏序【洛谷P3431】 [POI2005]AUT-The Bus

    P3431 [POI2005]AUT-The Bus Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 ...

  6. BZOJ4822[Cqoi2017]老C的任务——树状数组(二维数点)

    题目描述 老 C 是个程序员.     最近老 C 从老板那里接到了一个任务——给城市中的手机基站写个管理系统.作为经验丰富的程序员,老 C 轻松 地完成了系统的大部分功能,并把其中一个功能交给你来实 ...

  7. BZOJ1935: [Shoi2007]Tree 园丁的烦恼(树状数组 二维数点)

    题意 题目链接 Sol 二维数点板子题 首先把询问拆成四个矩形 然后离散化+树状数组统计就可以了 // luogu-judger-enable-o2 #include<bits/stdc++.h ...

  8. bzoj 4822: [Cqoi2017]老C的任务【扫描线+树状数组+二维差分】

    一个树状数组能解决的问题分要用树套树--还写错了我别是个傻子吧? 这种题还是挺多的,大概就是把每个矩形询问差分拆成四个点前缀和相加的形式(x1-1,y1-1,1)(x2.y2,1)(x1-1,y2,- ...

  9. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

随机推荐

  1. jQuery动画之自定义动画

    语法 $(selector).animate({params}, speed, callback); 参数: params: 必选,要执行动画的CSS属性. speed: 可选,执行动画时长. cal ...

  2. IDEA:Process finished with exit code -1073741819 (0xC0000005)

    出门左转:https://www.cnblogs.com/virgosnail/p/10335224.html

  3. TCP窗口扩大选项Window Scale

    窗口扩大选项使TCP的窗口定义从16bit增加到32bit.这并不是通过修改TCP首部来实现的,TCP首部仍然使用16bit,而是通过定义一个选项实现对16bit的扩大操作来完成的.于是TCP在内部将 ...

  4. 基本CSS布局二

    基本CSS布局二------基本页面布局二 /*主面板样式*/ #container { width:100%; margin:0px auto;/*主面板DIV居中*/ } /*顶部面板样式*/ # ...

  5. Web存储机制—sessionStorage,localStorage使用方法

    Web存储机制,在这里主要聊有关于Web Storage API提供的存储机制,通过该机制,浏览器可以安全地存储键值对,比使用cookie更加直观.接下来简单的了解如何使用这方面的技术. 基本概念 W ...

  6. drawable SVG 使用

    Android会使用一些规则来去帮我们匹配最适合的图片.什么叫最适合的图片?比如我的手机屏幕密度是xxhdpi,那么drawable-xxhdpi文件夹下的图片就是最适合的图片.因此,当我引用andr ...

  7. 如何查看MySQL connection id连接id

    每个MySQL连接,都有一个连接ID,可以通过 connection_id()查看. 连接id也可以通过以下方式查看: show processlist中id列 information_schema. ...

  8. Vue-1:鄙人是如何开始学习的

    说实话,Vue这个东西早想学习她了.为啥呢?不是因为有多火热多好用多水嫩...而是每次面试都会问我,你会不会Vue...接下来就是突然安静的空气,,,真TM气人.所以鄙人在经历诸事之后决心一定要搞一下 ...

  9. Hadoop : MapReduce中的Shuffle和Sort分析

    地址 MapReduce 是现今一个非常流行的分布式计算框架,它被设计用于并行计算海量数据.第一个提出该技术框架的是Google 公司,而Google 的灵感则来自于函数式编程语言,如LISP,Sch ...

  10. WPF Slider Tickbar 中显示数值

    class CustomTickBar : TickBar { protected override void OnRender(System.Windows.Media.DrawingContext ...