The beautiful values of the palace(2019南京网络赛)
题目链接:https://nanti.jisuanke.com/t/41298
题意:给一个n * n的螺旋矩阵,n保证是奇数,取一些点使其、获得价值,价值为数位和,然后再给q次查询,求矩阵中的价值总和
题解:树状数组求解,将所有有价值的点和需要处理的有关于矩形的点都先记录下来,关于矩形价值总和的点,一个矩形有四个点。例如x1,y1,x2,y2的价值总和是Sx1,x1 - Sx1- 1,y2 - Sx2,y1 - 1 + Sx2,y2,所以可以有思路先将所有的点按照y的坐标值递增排序,之后就可以保证每次求x轴上的总和就是0,0 到 i,j的价值总和,这样就可以将y处理掉,之后保存答案后输出就好了
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<stack> #include<cstdlib> #include<queue> #include<set> #include<string.h> #include<vector> #include<deque> #include<map> using namespace std; #define INF 0x3f3f3f3f3f3f3f3f #define inf 0x3f3f3f3f #define eps 1e-4 #define bug printf("*********\n") #define debug(x) cout<<#x"=["<<x<<"]" <<endl; typedef long long LL; typedef long long ll; const int maxn = 1e6 + 5; const int mod = 998244353;struct node{int flag;LL x,y,id;LL val;friend bool operator < (node a,node b) {if(a.y == b.y) {if(a.x == b.x) return a.flag < b.flag;return a.x < b.x;}return a.y < b.y;} }p[maxn];LL re_val(LL x) {LL sum = 0;while(x > 0) {sum += x % 10;x /= 10;}return sum; } LL index(LL y,LL x,LL n) { //求的n * n的矩阵中(x,y)的值是多少LL mid = (n + 1) / 2;LL p = max(abs(x - mid), abs(y - mid));LL ans = n * n - (1 + p) * p * 4;LL sx = mid + p, sy = mid + p;if (x == sx && y == sy)return ans;else {if (y == sy || x == sx - 2 * p)return ans + abs(x - sx) + abs(y - sy);elsereturn ans + 8 * p - abs(x - sx) - abs(y - sy);} }LL c[maxn],ans[maxn]; void init() {memset(c,0,sizeof c);memset(ans,0,sizeof ans); } LL lowbit(LL x) {return x & -x; } LL sum(LL i) {LL res = 0;while(i) {res += c[i];i -= lowbit(i);}return res; } LL n;void add(LL i,LL t) {while(i <= maxn) {c[i] += t;i += lowbit(i);} } int main() {int t;scanf("%d",&t);while(t--) {init();LL m,q;scanf("%lld %lld %lld",&n,&m,&q);int cnt = 0;for(int i = 1;i <= m; i++) {LL x,y;scanf("%lld %lld",&x,&y);p[++cnt] = {0, x, y, -1, re_val(index(x,y,n))};}for(int i = 1; i <= q; i++) {LL x1,y1,x2,y2;scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);p[++cnt] = {1, x1 - 1, y1 - 1, i, 1};p[++cnt] = {1, x1 - 1, y2, i, -1};p[++cnt] = {1, x2, y1 - 1, i, -1};p[++cnt] = {1, x2, y2, i, 1};}sort(p + 1, p + 1 + cnt);for(int i = 1; i <= cnt; i++) {if(p[i].flag == 1) ans[p[i].id] += sum(p[i].x) * p[i].val;else add(p[i].x,p[i].val);}for(int i = 1; i <= q; i++)printf("%lld\n",ans[i]);} }
转载于:https://www.cnblogs.com/smallhester/p/11448469.html
The beautiful values of the palace(2019南京网络赛)相关推荐
- 【2019.09.01】2019南京网络赛
补题地址:https://www.jisuanke.com/contest/3004?view=challenges A: B: C: D: E: F:✅ G: H:✅ I: 转载于:https:// ...
- Holy Grail 2019南京网络赛
https://nanti.jisuanke.com/t/41305 给定一个有向无负环图,然后告诉你要依次加6条边,要保证每次加边后无负环,求依次加边时保证当前边最小. 由于题目保证有解,所以s-& ...
- 2019 南京 网络赛 B (二维偏序,树状数组离线)
题意: 给出一N*N的蛇形矩阵,具体位置元素值不给你,自己找规律,然后给你M个 有效位置,P次查询,每次查询一个子矩阵中有效元素的权值和,该权值和等于对于 每个有效元素,模10拆分后相加得到的和.(注 ...
- 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 ...
- 2018 ACM-ICPC南京网络赛 Magical Girl Haze(分层最短路)
2018 ACM-ICPC南京网络赛 Magical Girl Haze There are NN cities in the country, and MM directional roads fr ...
- 2019徐州网络赛G
2019徐州网络赛G 题意 给定s字符串,定义一个回文串的价值是这个回文串中不同字母的个数,求s中所有回文串的价值之和. 思路 马拉车加序列自动机. 代码 #include<bits/stdc+ ...
- ICPC 2019 徐州网络赛
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...
- 2019ACM南京网络赛 Holy Grail
ACM2019南京网络赛 Holy Grail SPFA 或 Bellman-Ford模板题(存在负权路径) Description Input Output 样例输入 样例输出 题目链接: http ...
- 2019 ICPC 南京网络赛 F Greedy Sequence
You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each i \in [1,n]i∈[1,n], c ...
最新文章
- 1476. Lunar Code
- 赢在中国(08-02-27)
- Android之四大组件(Service的开启与关闭)
- Windows下安装Objective-C开发环境
- 自定义控件-实现TextBox的禁止粘贴
- 磁盘阵列服务器Intel C610系列,超微6048R-E1CR36N 36盘位存储服务器 磁盘阵列
- mysql导数据出指定数量_mysql导出指定数据或部份数据的方法
- VMware虚拟机设置(vmtools分辨率)
- JavaScript 数组的知识点讲解
- 玩转windows内置linux子系统_1.安装
- dex文件解析(第三篇)
- 【最大流,最大匹配,最大独立集】2018.6.18 【2018提高组】模拟C组 T3 沙耶的玩偶
- 微信支付报错提示“商户号该产品权限未开通,请前往商户平台产品中心检查后重试...
- 数模【Mathematica(安装、入门方法、基本计算、基本图形、创建互动模型、利用数据、幻灯片演示、完整实例)】
- Mac上的QQ字体大小和颜色如何设置
- 【C#】消除锯齿 - 指定抗锯齿的呈现。
- 验证码之google的reCAPTCHA使用
- 阿里巴巴成立科技伦理治理委员会 推动技术治理、践行“好科技”
- 关于HIPO和IPO
- 论文翻译怎么在线操作,论文翻译的步骤