题意:

(假设所有的点对应的值已经求出)给你一个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-6;
const int mod = 1e9+7;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
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 = 0;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 = 0;for(int i = 0; i < maxn; i++){tree[i]=ans[i]=0;}for(int i = 1; i <= m; i++){ll x, y;ll res;scanf("%lld %lld", &x, &y);x=x-n/2-1;y=y-n/2-1;ll T = max(abs(x),abs(y));if(x>=y)res=1ll*n*n-4*T*T-2*T-x-y;else    res=1ll*n*n-4*T*T+2*T+x+y;ll c=0;while(res){c+=res%10;res/=10;}Q[++tot]=node(1,i,x+n/2+1,y+n/2+1,c);}for(int i = 1; i <= q; i++){ll x1,y1,x2,y2;scanf("%lld %lld %lld %lld",&x1, &y1, &x2, &y2);Q[++tot]=node(0,i,x2,y2,1);Q[++tot]=node(0,i,x1-1,y1-1,1);Q[++tot]=node(0,i,x1-1,y2,-1);Q[++tot]=node(0,i,x2,y1-1,-1);}sort(Q+1,Q+1+tot,cmp);for(int i = 1; i <= tot; i++){if(Q[i].x<1||Q[i].y<1)continue;if(Q[i].lx==1)add(Q[i].y,Q[i].v);else ans[Q[i].id]+=1ll*Q[i].v*sum(Q[i].y);}for(int i = 1; i <= q; i++){printf("%lld\n",ans[i]);}}return 0;
}
/*
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*/

转载于:https://www.cnblogs.com/wrjlinkkkkkk/p/11465632.html

2019icpc南京网络赛 A The beautiful values of the palace(离线+树状数组)相关推荐

  1. ICPC2017网络赛(南宁)子序列最大权值(树状数组+dp)

    https://nanti.jisuanke.com/t/17319 Let SS be a sequence of integers s_{1}s ​1 ​​ , s_{2}s ​2 ​​ , .. ...

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

  3. The Preliminary Contest for ICPC Asia Nanjing 2019ICPC南京网络赛

    B.super_log (欧拉降幂) •题意 定一个一个运算log*,迭代表达式为 给定一个a,b计算直到迭代结果>=b时,最小的x,输出对m取余后的值 •思路 $log*_{a}(a^{a}) ...

  4. 2019icpc南京网络赛 Holy Grail(SPFA)

    题目链接---- 我至今还对题意有点模棱两可,不过也大致是知道了... 大致是一开始给你一个有向图,然后让你给你六个顶点,添六条边,但是添边是有限制的.每次添边的权值要最小,还有个条件就是不能构成ne ...

  5. 2019ICPC南京网络赛E题 K Sum

    题意: 数学题见链接 数据范围: n=1e9,k=101e5 链接: https://nanti.jisuanke.com/t/41304 题解: 涉及积性函数.莫比乌斯反演.杜教筛(狄利克雷卷积). ...

  6. 吉首大学2019年程序设计竞赛(重现赛)B——干物妹小埋(树状数组+二分)

    链接:https://ac.nowcoder.com/acm/contest/992/B 来源:牛客网 题目描述 在之前很火的一个动漫<干物妹小埋>中,大家对小埋打游戏喝可乐的印象十分的深 ...

  7. 2019hdu暑假多校训练赛第九场1002 Rikka with Cake hdu6681(树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6681 题意:给定一个n*m的蛋糕,再给出K个操作,每次都是从蛋糕的中间向四个方向中的一个切过去,问最后 ...

  8. 2018 ACM-ICPC南京网络赛 Magical Girl Haze(分层最短路)

    2018 ACM-ICPC南京网络赛 Magical Girl Haze There are NN cities in the country, and MM directional roads fr ...

  9. 2019ACM南京网络赛 Holy Grail

    ACM2019南京网络赛 Holy Grail SPFA 或 Bellman-Ford模板题(存在负权路径) Description Input Output 样例输入 样例输出 题目链接: http ...

  10. The beautiful values of the palace(2019南京网络赛)

    题目链接:https://nanti.jisuanke.com/t/41298 题意:给一个n * n的螺旋矩阵,n保证是奇数,取一些点使其.获得价值,价值为数位和,然后再给q次查询,求矩阵中的价值总 ...

最新文章

  1. 出门问问李志飞:小米让别人无路可走,我也要让它走起来没有那么方便
  2. kafka topic制定规则
  3. Java8排序–性能陷阱
  4. Java虚拟机(十二)——StringTable
  5. 加载PageOffice控件失败。 当前浏览器是42版本以上的谷歌浏览器,建议采用POBrowser技术打开PageOffice即可。
  6. 编写可靠shell脚本的八个建议
  7. 【语音处理】基于matlab语音去噪频谱分析【含Matlab源码 1019期】
  8. 熔断机制什么意思_什么是“熔断机制”,为什么交易所需要它?看完你就明白了!...
  9. oracle12c 数据库驱动,常用数据库的驱动程序_Oracle 12c_Oracle 数据库_Oracle 视频_课课家...
  10. php中文手册 最新评论整合,ThinkPHP整合百度Ueditor
  11. 使用GitHub搭建个人博客
  12. MP3音频解码详细过程(二)
  13. 【企业微信】自建应用可信域名验证
  14. Ashen的成长,从CSDN博客开始!
  15. 年会活动必备微信墙3D签到配置教程
  16. docker portainer agent 安装
  17. html字体怎么变大,网页字体怎么变大(html怎么改字体类型)
  18. Java 实现视频弹幕功能
  19. python 接收MQTT间隔一段时间停止问题
  20. plc远程服务器,PLC远程控制

热门文章

  1. Linux下打包qt程序,可以发布到一台纯净的linux发行版系统上
  2. C语言_函数指针高级用法
  3. 大数据时代的回收生意经(淼一专访)
  4. 删除链表中重复的节点
  5. java 面试,java 后端面试,数据库方面对初级和高级程序员的要求
  6. php中使用fsockopen实现异步请求
  7. Redis Nosql数据库
  8. Android Screen Orientation
  9. Process Explorer
  10. 如何在横竖屏切换时Activity内容不变