4822: [Cqoi2017]老C的任务
来源:互联网 发布:linux 安全扫描工具 编辑:程序博客网 时间:2024/05/22 01:53
每次统计一个矩形内的点权和
拆成四个小矩形作差分
扫描线+树状数组即可
#include<iostream>#include<cstdio>#include<vector>#include<algorithm>#include<cstring>using namespace std; const int maxn = 1E5 + 10;const int Max = ~0U>>1;const int Min = -(1LL << 31LL);typedef long long LL; struct Query{ int y,Num,typ; Query(){} Query(int y,int Num,int typ): y(y),Num(Num),typ(typ){}}; int n,m,cx,cy,tx,ty,ax[maxn],ay[maxn],px[maxn],py[maxn],p[maxn];LL Ans[maxn],sum[maxn]; vector <Query> Q[maxn];vector <pair<int,int> > P[maxn]; inline int getint(){ char ch = getchar(); int ret = 0,a = 1; while (ch < '0' || '9' < ch) { if (ch == '-') a = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') ret = ret * 10 + ch - '0',ch = getchar(); return ret * a;} inline void Add(int x,int y,int Num,int typ){ int nx = lower_bound(ax + 1,ax + cx + 1,x) - ax; int ny = lower_bound(ay + 1,ay + cy + 1,y) - ay; if (ax[nx] > x) --nx; if (ay[ny] > y) --ny; Q[nx].push_back(Query(ny,Num,typ));} void Pre_Work(){ for (int i = 1; i <= n; i++) { ax[i] = px[i] = getint(); ay[i] = py[i] = getint(); p[i] = getint(); } cx = 1; ax[++tx] = Min; ax[++tx] = Max; cy = 1; ay[++ty] = Min; ay[++ty] = Max; sort(ax + 1,ax + tx + 1); for (int i = 2; i <= tx; i++) if (ax[i] != ax[i - 1]) ax[++cx] = ax[i]; sort(ay + 1,ay + ty + 1); for (int i = 2; i <= ty; i++) if (ay[i] != ay[i - 1]) ay[++cy] = ay[i]; for (int i = 1; i <= n; i++) { px[i] = lower_bound(ax + 1,ax + cx + 1,px[i]) - ax; py[i] = lower_bound(ay + 1,ay + cy + 1,py[i]) - ay; P[px[i]].push_back(make_pair(py[i],p[i])); } for (int i = 1; i <= m; i++) { int xa,ya,xb,yb; xa = getint(); ya = getint(); xb = getint(); yb = getint(); Add(xb,yb,i,1); if (xa > Min) Add(xa - 1,yb,i,-1); if (ya > Min) Add(xb,ya - 1,i,-1); if (xa > Min && ya > Min) Add(xa - 1,ya - 1,i,1); }} int main(){ #ifdef DMC freopen("DMC.txt","r",stdin); #endif tx = ty = n = getint(); m = getint(); Pre_Work(); for (int i = 1; i <= cx; i++) { for (int j = 0; j < P[i].size(); j++) for (int k = P[i][j].first; k <= cy; k += k&-k) sum[k] += 1LL * P[i][j].second; for (int j = 0; j < Q[i].size(); j++) { Query now = Q[i][j]; LL tot = 0; for (int k = now.y; k > 0; k -= k&-k) tot += sum[k]; Ans[now.Num] += 1LL * now.typ * tot; } } for (int i = 1; i <= m; i++) printf("%lld\n",Ans[i]); return 0;}
0 0
- 4822: [Cqoi2017]老C的任务
- 【CQOI2017】bzoj4822 老C的任务
- 【BZOJ4822】 [Cqoi2017]老C的任务
- bzoj4822 cqoi2017 老C的任务【树状数组+扫描】
- 4822: [Cqoi2017]老C的任务&&1935: [Shoi2007]Tree 园丁的烦恼
- 4822: [Cqoi2017]老C的任务&&bzoj 1935: [Shoi2007]Tree 园丁的烦恼
- 【CQOI2017】老C的方块
- 【CQOI2017】bzoj4823 老C的方块
- Bzoj 4824: [Cqoi2017]老C的键盘
- 4824: [Cqoi2017]老C的键盘
- 4823: [Cqoi2017]老C的方块
- 【BZOJ4824】 [Cqoi2017]老C的键盘
- 【BZOJ4823】 [Cqoi2017]老C的方块
- bzoj4822[CQOI2017]:老C的任务(树状数组/k-dtree)
- [最小割] BZOJ 4823 [Cqoi2017]老C的方块
- [树形DP] BZOJ 4824 [Cqoi2017]老C的键盘
- bzoj4823 cqoi2017 老C的方块【最大流】
- BZOJ 4823: [Cqoi2017]老C的方块(最小割)
- js 遍历数组
- 啥是Document类型
- Hexo博客主题应用
- linux sed 替换 与 grep查找
- eureka入门
- 4822: [Cqoi2017]老C的任务
- Android launcher3 循环桌面
- linux命令之awk
- winhex 手工恢复佳能70D视频过程
- 走进数据结构之排序(三)---冒泡排序
- Ubuntu下添加开机启动项的2种方法
- 第一次机房收费系统 “登录”
- Jenkins---安装及配置/jenkins环境搭建
- LDA的算法小结,希望能够帮助到其他人