南京网络赛自闭现场

https://nanti.jisuanke.com/t/41298

二维偏序经典题型

二维前缀和!!!

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%lld",&x);
int T;
#define P pair<int,int>
#define fi first
#define se second
#define maxn 1000000+10
int n,m,p;
int A[maxn];
int B[maxn];
int C[maxn];
int D[maxn];
int Ans[maxn];
map<int,int> mp;
struct Q{
int x,y,z,w;
}q[maxn];
P E[maxn];
int f(int x)
{
int ans=;
while(x)
{
ans+=(x%);
x/=;
}
return ans;
}
int cal(int x,int y)
{
int s=n*n;
int _t=(n+)/;
if(x==_t&&y==_t){
//return s;
return f(n*n);
}
int _a=max(abs(x-_t),abs(y-_t));///距中心点距离
int _x=(_a*+);
int sx=_t-_a;
int sy=_t-_a;
int ck=_a+_t-;///出口
// cout<<endl<<x<<" "<<y<<" "<<ck<<" ck "<<_a<<" "<<_t<<endl;
s-=(_x-)*(_x-);///减去内圈
if(y-_t==_a&&x<=ck) ///顶行
{
s-=(ck-x);
//cout<<endl<<"F"<<x<<' '<<y<<' '<<s<<' '<<f(s)<<endl; return f(s);
}
else
{
s-=(_x-);
//cout<<s<<" "<<_x<<" "<<y<<endl;
if(_t-x==_a)
{
s-=_x+sx-y-;
// cout<<s<<endl; return f(s);
}
else
{
s-=_x-; if(_t-y==_a)
{
s-=x-sx-;
return f(s);
}
else
{
s-=_x-;
if(x-_t==_a)
{ s-=y-sy-;
return f(s);
}
}
} } }
int V[maxn];
void add(int x,int val)
{
while(x<=maxn){
V[x]+=val;
x+=(x&-x);
}
}
int get(int x)
{
// if(x==0)return 0;
int ans=;
//ans+=V[0];
while(x){
ans+=V[x];
x-=(x&-x);
}
return ans;
}
bool cmp(int x,int y)
{
if(A[x]==A[y])return B[x]<B[y];
return A[x]<A[y];
}
void init()
{
for(int i=;i<maxn;i++){
Ans[i]=V[i]=;
mp.clear();
}
}
signed main()
{
sc(T); while(T--)
{
init();
sc(n);
sc(m);
sc(p);
int a,b,c,d;
for(int i=; i<=m; i++)
{
sc(A[i]);
sc(B[i]);
C[i]=i;
D[i]=cal(A[i],B[i]);
mp[D[i]]=;
}
sort(C+,C+m+,cmp);
int _k=;
for(int i=;i<p;i++){
sc(a);sc(b);sc(c);sc(d);
q[i].x=a;
q[i].y=b;
q[i].z=c;
q[i].w=d;
E[_k++]=P(a-,b-);
E[_k++]=P(a-,d);
E[_k++]=P(c,b-);
E[_k++]=P(c,d);
}
sort(E,E+_k);
int sz=unique(E,E+_k)-E;
int j=;
for(int i=;i<sz;){
//cout<<i<<sz<<'\n';
while(j<=m&&E[i].fi>=A[C[j]]){
add(B[C[j]],D[C[j]]);
j++;
}
Ans[i]=get(E[i].se);
// Ans1[i]=get(E[i].se-1);
i++;
} for(int i=;i<p;i++){
P x=P(q[i].x-,q[i].y-);
P y=P(q[i].z,q[i].w);
P w=P(q[i].x-,q[i].w);
P z=P(q[i].z,q[i].y-);
int an=Ans[lower_bound( E,E+sz,x)-E];
//cout<<x.fi<<' '<<an<<'\n';
an-=Ans[lower_bound( E,E+sz,w)-E];
an-=Ans[lower_bound( E,E+sz,z)-E];
cout<<Ans[lower_bound(E,E+sz,y)-E]+an<<'\n';
// cout<<Ans[lower_bound(E,E+sz,y)-E]<<'\n';
} }
}

最新文章

  1. spark伪分布式安装
  2. 2.b统计字符串长度
  3. SQL 函数
  4. Interpolated Strings
  5. 解决VS2012新建MVC4等项目时,收到加载程序集“NuGet.VisualStudio.Interop…”的错误
  6. 10分钟进阶Nuget
  7. 开源中国iOS客户端学习
  8. xtrabackup 开启压缩备份
  9. J2EE: JCA (Java Connector Architecture) [转]
  10. 安装VMware workstation遇到的两个问题:安装过程中的DLL问题和安装后打开需要的管理权限问题
  11. GAN模型生成手写字
  12. 高斯模糊的Java实现
  13. Python3 批量替换文本内容
  14. 队列 和 线程 之GCD dispatch
  15. Java编程的逻辑 (13) - 类
  16. 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)
  17. 在VS2015中用C++编写可被其它语言调用的动态库DLL
  18. Redis之Redis
  19. git用法小结(1)--建立远程仓库
  20. Python Numpy Array

热门文章

  1. 在子类中,若要调用父类中被覆盖的方法,可以使用super关键字
  2. 小记---------有关hadoop的HDFS命令行操作
  3. @OneToMany 一对多 通过表之间的链接
  4. str 小列题
  5. IE6兼容笔记
  6. atxserver2-rethinkdb的一些基础操作
  7. iOS蓝牙4.0开发
  8. Vmware 安装 ghost 版 win 7
  9. hostid - 显示当前主机的数字化标识
  10. python编码环境安装与基本语法