bzoj 2762: [JLOI2011]不等式组 树状数组
来源:互联网 发布:python查找txt内容 编辑:程序博客网 时间:2024/06/05 11:25
题意
旺汪与旺喵最近在做一些不等式的练习。这些不等式都是形如ax+b>c 的一元不等式。当然,解这些不等式对旺汪来说太简单了,所以旺喵想挑战旺汪。旺喵给出一组一元不等式,并给出一个数值 。旺汪需要回答的是x=k 时成立的不等式的数量。聪明的旺汪每次都很快就给出了答案。你的任务是快速的验证旺汪的答案是不是正确的。
N<=100000,a,b,c的范围为[-10^8,10^8],k的范围为[-10^6,10^6]。
分析
直接用树状数组维护即可。注意细节。
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int RANGE=1000005;int n,c[RANGE*2+1005],tot;pair<int,pair<int,int> > a[100005];bool vis[100005];void ins(int x,int y){ x+=RANGE+1;x=max(x,1);x=min(x,n); while (x<=n) c[x]+=y,x+=x&(-x);}int query(int x){ int ans=0;x+=RANGE+1;x=max(x,1);x=min(x,n); while (x) ans+=c[x],x-=x&(-x); return ans;}int main(){ n=RANGE*2+1000; int T; scanf("%d",&T); while (T--) { char ch[10]; scanf("%s",ch); if (ch[0]=='A') { int x,y,z; scanf("%d%d%d",&x,&y,&z); tot++;a[tot]=make_pair(x,make_pair(y,z)); if (x==0) { if (y>z) ins(-RANGE,1); continue; } if ((z-y)%x==0) if (x<0) ins(-RANGE,1),ins((z-y)/x,-1); else ins((z-y)/x+1,1); else if (x<0) ins(-RANGE,1),ins((int)floor((double)(z-y)/x)+1,-1); else ins((int)floor((double)(z-y)/x)+1,1); } else if (ch[0]=='D') { int w; scanf("%d",&w); if (vis[w]) continue; vis[w]=1; int x=a[w].first,y=a[w].second.first,z=a[w].second.second; if (x==0) { if (y>z) ins(-RANGE,-1); continue; } if ((z-y)%x==0) if (x<0) ins(-RANGE,-1),ins((z-y)/x,1); else ins((z-y)/x+1,-1); else if (x<0) ins(-RANGE,-1),ins((int)floor((double)(z-y)/x)+1,1); else ins((int)floor((double)(z-y)/x)+1,-1); } else { int w; scanf("%d",&w); printf("%d\n",query(w)); } } return 0;}
阅读全文
0 0
- BZOJ 2762 JLOI2011 不等式组 树状数组
- bzoj 2762: [JLOI2011]不等式组 树状数组
- BZOJ 2762 JLOI 2011 不等式组 树状数组
- bzoj2762 不等式组 树状数组
- bzoj 2762 树状数组
- bzoj 3155 树状数组
- bzoj 3594 树状数组
- bzoj[JLOI2011]飞行路线
- 【BZOJ】【JLOI2011】飞行路线
- 【树状数组】bzoj 1452 Count
- BZOJ 3289 莫队 树状数组
- bzoj 1878(离线+树状数组)
- bzoj 1818(树状数组)
- BZOJ 3236 莫队+树状数组
- bzoj 1452 二维树状数组
- bzoj 1878 树状数组+离线
- bzoj 3132 二维树状数组
- [bzoj 1452] Count (树状数组)
- 比特币老兵之续集
- 第五周项目3--括号的匹配
- 线段树的构造 II-LintCode
- 异常----自定义异常
- 开坑
- bzoj 2762: [JLOI2011]不等式组 树状数组
- Java开发中的23种设计模式详解(转)
- 鼠标事件被禁用了
- 第七周项目二
- 第八周项目一 顺序串算法库
- 设置小米5手机拒接中介骚扰标志的电话
- mybatis学习四之输入输出映射以及动态sql
- 178
- 【bzoj3036】绿豆蛙的归宿 期望dp