hdu5372 离散化+树状数组
来源:互联网 发布:网络间接市场调研方法 编辑:程序博客网 时间:2024/05/20 01:11
这个题离散化有点蛋疼。。。
代码:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<string>#include<iomanip>#pragma comment(linker, "/STACK:1024000000,1024000000")#include<vector>#include<set>#include<map>#include<queue>#include<list>using namespace std;typedef long long LL;typedef unsigned long long ULL;#define rep(i,k,n) for(int i=(k);i<=(n);i++)#define red(i,k,n) for(int i=(k);i>=(n);i--)#define sqr(x) ((x)*(x))#define clr(x,y) memset((x),(y),sizeof(x))#define mod 1000000007#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)>(b)?(b):(a))const int maxn = 400010;struct opp{ bool type; int de;} op[200010];int a[maxn],n,N,acnt;int r[maxn];bool cmp(int x,int y){ return a[x]<a[y];}void dis(){ rep(i,1,acnt)r[i]=i; sort(r+1,r+1+acnt,cmp); int pre=a[r[1]]; N=a[r[1]]=1; rep(i,2,acnt) { if(a[r[i]]==pre)a[r[i]]=a[r[i-1]]; else { pre=a[r[i]]; N=a[r[i]]=a[r[i-1]]+1; } }}struct Bit{ int bit[maxn]; void cl() { clr(bit,0); } void add(int k,int v) { for(int i=k; i<=N; i+=i&-i)bit[i]+=v; } int sum(int k) { int ret=0; for(int i=k; i>0; i-=i&-i)ret+=bit[i]; return ret; }} BL,BR;int main(){//#define LOCAL#ifdef LOCAL freopen("e:\\read.txt","r",stdin); //freopen("e:\\write.txt","w",stdout);#endif int ii=0; while(~scanf("%d",&n)) { acnt=0; rep(i,1,n) { int t; scanf("%d",&t); op[i].type=t; if(t) { scanf("%d",&op[i].de); } else { acnt+=2; scanf("%d",&t); a[acnt-1]=t; a[acnt]=t+acnt/2; } } dis(); BL.cl(); BR.cl(); int s=1; printf("Case #%d:\n",++ii); rep(i,1,n) { if(op[i].type) { int k=op[i].de; BL.add(a[k*2-1],-1); BR.add(a[k*2],-1); } else { printf("%d\n",BR.sum(a[2*s])-BL.sum(a[2*s-1]-1)); BL.add(a[2*s-1],1); BR.add(a[2*s],1); s++; } } } return 0;}
0 0
- hdu5372 离散化+树状数组
- hdu5372(树状数组)
- hdu5372 Segment Game 树状数组
- hdu5372 Segment Game (树状数组)
- 树状数组--离散化
- Flowers&&树状数组+离散化
- hdu4417(离散化+树状数组)
- POJ2299 树状数组+离散化
- poj2299 离散化+树状数组
- hdu4325 树状数组+离散化
- poj2299 树状数组+离散化
- poj2299离散化,树状数组
- hdu5862树状数组 离散化
- hdu5877dfs,树状数组离散化
- POJ2299 树状数组+离散化
- 工资管理 树状数组+离散化
- hdu5372(2015多校7)--Segment Game(树状数组)
- 2015 多校联赛 ——HDU5372(树状数组)
- RT-Thread finsh源码分析: finsh_token.h
- Qt_VS问题
- iOS8 UISearchViewController搜索功能讲解
- Java笔试面试题010
- Android BroadCast 广播的两种注册方式和粘性广播实现
- hdu5372 离散化+树状数组
- HDU 3642 Get The Treasury (线段树扫描线进阶--求长方体重叠3次或以上的体积)
- [搜索]hdu5336
- linux之wait函数
- 关于android:configChanges
- 088 Merge Sorted Array [Leetcode]
- POJ 1285 - Combinations, Once Again 泛化背包!
- BRISK: Binary Robust Invariant Scalable Keypoints
- Swift-分支