hdu 5032 Always Cook Mushroom 离线树状数组
来源:互联网 发布:单片机用什么编程 编辑:程序博客网 时间:2024/05/29 04:13
#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<cmath>#include<cassert>#include<cstring>#include<iomanip>using namespace std;#ifdef _WIN32#define i64 __int64#define out64 "%I64d\len"#define in64 "%I64d"#else#define i64 long long#define out64 "%lld\len"#define in64 "%lld"#endif/************ for topcoder by zz1215 *******************/#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)#define S64(a) scanf(in64,&a)#define SS(a) scanf("%d",&a)#define LL(a) ((a)<<1)#define RR(a) (((a)<<1)+1)#define pb push_back#define pf push_front#define X first#define Y second#define CL(Q) while(!Q.empty())Q.pop()#define MM(name,what) memset(name,what,sizeof(name))#define MC(a,b)memcpy(a,b,sizeof(b))#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)<(b)?(a):(b))#define read freopen("out.txt","r",stdin)#define write freopen("out2.txt","w",stdout)const int maxn = 100111;int A, B;int m;i64 ans[maxn];struct Node{int a, b;bool operator < (const Node & cmp) const{return b*cmp.a < a*cmp.b;}};struct Z{int a, b, x; int id;bool operator < (const Z & cmp) const{return b*cmp.a < a*cmp.b;}}zx;vector<Z>z;vector<Node>v;void init(){Node node;for (node.a = 1; node.a <=1000; node.a++){for (node.b = 1; node.b <= 1000; node.b++){v.push_back(node);}}sort(v.begin(), v.end());}i64 a[1111];int lowbit(int x){return x&(-x);}void add(int pos, int num, i64 ary[],int end){while (pos <= end){ary[pos] += num;pos += lowbit(pos);}}i64 sum(int x, i64 ary[]){i64 ans = 0;while (x){ans += ary[x];x -= lowbit(x);}return ans;}void start(){sort(z.begin(), z.end());for (int i = 0; i <= 1000; i++){a[i] = 0;}int pos = 0;for (int now = 0; now < z.size(); now++){for (; pos < v.size(); ){if (z[now].b* v[pos].a >= z[now].a * v[pos].b){add(v[pos].a, (v[pos].a + A)*(v[pos].b + B), a, 1000);pos++;}else{break;}}ans[z[now].id] = sum(z[now].x, a);}}int main(){init();int T;cin >> T;for (int tt = 1; tt <= T;tt++){cin >> A >> B;cin >> m;z.clear();for (int i = 1; i <= m; i++){//cin >> zx.a >> zx.b >> zx.x;SS(zx.a); SS(zx.b); SS(zx.x);zx.id = i;z.push_back(zx);}start();printf("Case #%d:\n",tt);for (int i = 1; i <= m; i++){printf("%I64d\n", ans[i]);}}return 0;}
0 0
- hdu 5032 Always Cook Mushroom 离线树状数组
- Hdu 5032 Always Cook Mushroom (树状数组)
- [HDU 5032 Always Cook Mushroom] 离线+极角排序+树状数组
- [hdu 5032]2014北京网络赛Always Cook Mushroom 离线线段树/树状数组
- [hdu 5032]2014北京网络赛Always Cook Mushroom 离线线段树/树状数组
- 【树状数组】 HDOJ 5032 Always Cook Mushroom
- HDU Always Cook Mushroom (极角排序+树状数组)
- HDU 5032 Always Cook Mushroom
- HDU 5032 Always Cook Mushroom(极角排序, 树状数组)
- HDU 5032 Always Cook Mushroom (极角排序 x 树状数组)
- HDU 5032 Always Cook Mushroom 极角排序 数状数组 姿势
- hdu5032 Always Cook Mushroom
- HDU 5032 Always Cook Mushroom (2014年北京赛区现场赛A题)
- hdu 4638 (树状数组+离线)
- hdu 4417 离线树状数组
- HDU 3333 树状数组离线
- HDU(3333)树状数组+离线
- HDU(3874)树状数组+离线
- 软工视频总结(二)
- 接口(听课笔记)
- Android适配方案小结(二)
- 关于面向对象中接口和抽象类的一个比喻
- 一个合格的程序员的编程方式
- hdu 5032 Always Cook Mushroom 离线树状数组
- [Android] 使用Include布局+Fragment滑动切换屏幕
- ESC32硬件---PCB小结(第一版)
- 1.1插入排序-简单(直接)插入排序
- base64加密算法的java实现
- 我的uboot之路(1)从spec开始
- 黑马程序员----C语言入门及终端指令
- 初识结构体与指针
- Android UI线程和子线程共享数据