题目链接:https://nanti.jisuanke.com/t/41298

扫描线的简单题,题目难在找宫殿的价值(°ー°〃),比赛时将近100多行代码找价值,纯模拟,看到题解哭了。

存下每个宫殿的横坐标、价值,存下每个矩形平行于y轴的两条边,左边的那个边要特殊处理,就是横坐标减一。线段树维护y坐标区间和。坐标离散化处理,按x遍历线段,先线段树更新点在y坐标上的值,再处理边,如果线段是矩形终止的边,答案即为更新完点之后查询线段树[y1,y2]上的区间和再减去起始边时查询线段树[y1,y2]上的区间和。

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define maxn 2000005
ll n,m,p,sum[maxn<<],lazy[maxn<<],ans[maxn];
int ly[maxn];
struct node{
int x,y,val;
bool operator <(const node &w)const{
return x<w.x;
}
}a[maxn];
struct seg{
int x,l,r,s,id;
seg(){}
seg(int x,int l,int r,int s,int id):x(x),l(l),r(r),s(s),id(id){};
bool operator <(const seg &w)const{
if(x==w.x)return s<w.s;
return x<w.x;
}
}se[maxn<<];
int getval(int x,int y)
{
ll num,t;
x=x-n/-;y=y-n/-;
t=max(abs(x),abs(y));
if(x>=y)num=1ll*n*n-*t*t-*t-x-y;
else num=1ll*n*n-*t*t+*t+x+y;
int ret=;
while(num)
{
ret+=num%;
num/=;
}
return ret;
}
void build(int l,int r,int rt)
{
sum[rt]=lazy[rt]=;
if(l==r)return ;
int mid=l+r>>;
build(ls);build(rs);
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void update(int p,int val,int l,int r,int rt)
{
if(l==r)
{
sum[rt]+=val;return ;
}
int mid=l+r>>;
if(p<=mid)update(p,val,ls);
else update(p,val,rs);
sum[rt]=sum[rt<<]+sum[rt<<|];
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)return sum[rt];
int mid=l+r>>;
ll ret=;
if(L<=mid)ret+=query(L,R,ls);
if(R>mid)ret+=query(L,R,rs);
return ret;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld",&n,&m,&p);
int x,y,x1,y1,val,tot=,cnt=;
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
val=getval(x,y);
a[++tot].x=x;a[tot].y=y;a[tot].val=val;
ly[tot]=y;
}
for(int i=;i<=p;i++)
{
scanf("%d%d%d%d",&x,&y,&x1,&y1);
se[++cnt]=seg(x-,y,y1,,i);ly[++tot]=y;
se[++cnt]=seg(x1,y,y1,-,i);ly[++tot]=y1;
}
sort(a+,a++m);
sort(ly+,ly++tot);
sort(se+,se++cnt);
int ny=unique(ly+,ly++tot)-ly-,pos=;
build(,ny,);
for(int i=;i<=cnt;i++)
{
se[i].l=lower_bound(ly+,ly++ny,se[i].l)-ly;
se[i].r=lower_bound(ly+,ly++ny,se[i].r)-ly;
}
for(int i=;i<=m;i++)
a[i].y=lower_bound(ly+,ly++ny,a[i].y)-ly;
int j=,num=se[].x;
for(int i=;i<=cnt;i++)
{
while(a[pos].x<=se[i].x&&pos<=m)pos++;
for(;j<pos;j++)update(a[j].y,a[j].val,,ny,);
j=pos;
if(se[i].s==)ans[se[i].id]=query(se[i].l,se[i].r,,ny,);
else ans[se[i].id]=query(se[i].l,se[i].r,,ny,)-ans[se[i].id];
}
for(int i=;i<=p;i++)
printf("%lld\n",ans[i]);
}
return ;
}

19南京网络赛A 扫描线的更多相关文章

  1. 19南京网络赛B 欧拉降幂

    题目链接 给a,b,p.有b个a的幂 #include <iostream> using namespace std; typedef long long LL; const LL N = ...

  2. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)

    Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  4. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  5. 2018ICPC南京网络赛

    2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...

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

  7. 2019 南京网络赛A

    南京网络赛自闭现场 https://nanti.jisuanke.com/t/41298 二维偏序经典题型 二维前缀和!!! #include<bits/stdc++.h> using n ...

  8. 计蒜客 2018南京网络赛 I Skr ( 回文树 )

    题目链接 题意 : 给出一个由数字组成的字符串.然后要你找出其所有本质不同的回文子串.然后将这些回文子串转化为整数后相加.问你最后的结果是多少.答案模 1e9+7 分析 : 应该可以算是回文树挺裸的题 ...

  9. 分治维护dp——19南昌网络赛C/cf750E

    南昌网络赛,是cf的原题 第一次做到这种题,所以认真想了下,每次给一个询问[L,R],要求出这个区间里有2017子序列,但是不能有2016子序列需要删掉的最少元素个数 首先如果我们之询问一小段区间[L ...

随机推荐

  1. H3C OSPF协议分区域管理

  2. js 操作字符串方法记录

    var str="helloworld"; 这三个方法如果只传一个参数默认截取到最后..将截取的字符返回,对原字符串没有任何改变 slice(star,end)//从索引star开 ...

  3. 2018-9-2-WPF-开发自动删除软件

    title author date CreateTime categories WPF 开发自动删除软件 lindexi 2018-09-02 14:51:48 +0800 2018-08-09 09 ...

  4. vue-learning:12-vue获取模板内容的方式

    vue获取模板内容的方式 目录 outerHTML获取内容 template属性获取内容 ES6的字符串模板 <template>标签 <srcipt type="text ...

  5. TOJ5705动态序列操作(STL or treap)

    传送门:动态序列操作 在一个动态变化的序列中,完成以下基本操作: (1)插入一个整数 (2)删除一个整数 (3)查找序列中最大的数 (4)查找序列中最小的数 (5)求x的前驱(前驱定义为不大于x的序列 ...

  6. 深度解读 - Windows 7核心图形架构细致分析(来自微软)

    编辑:马志文 时间: 2009-12-29 如现在大家所想的那样, Windows7 其实是 Windows Vista 的改进版. Windows 7 在 Windows Vista 的基础上进行了 ...

  7. SPA+.NET Core3.1 GitHub第三方授权登录 使用AspNet.Security.OAuth.GitHub

    GitHub第三方授权登录 使用SPA+.NET Core3.1实现 GitHub第三方授权登录 类似使用AspNet.Security.OAuth.GitHub,前端使用如下:VUE+Vue-Rou ...

  8. Java中的Redis 哨兵高可用性

    让我们探索Redis Sentinel,看看如何在Java上运行它,一起来看看,最近get了很多新知识,分享给大家参考学习.需要详细的java架构思维导图路线也可以评论获取! 什么是Redis哨兵? ...

  9. DOCKER学习_008:Docker容器的运行最佳实践

    一 容器分类 容器按用途大致可分为两类: 服务类容器,如 web server. database等 工具类容器,如cur容器, Iredis-cli容器 通常而言,服务类容器需要长期运行,所以使用 ...

  10. 跌宕起伏的java帝国史,剖析谷歌甲骨文长达8年的版权战争

    这篇博文是我在B站上发的一个科普java的视频文案整理,本来发过一次了,但是有几种不严谨的地方只能删掉重新发了一下,内容如标题,感兴趣的码农朋友可以观看视频的版本,欢迎提提意见啥的,感谢~https: ...