HDU 5124 树状数组+map操作
来源:互联网 发布:京华科讯软件 编辑:程序博客网 时间:2024/06/07 22:16
看到这道题毫无疑问就是线段树做,在2个小时的时间卡死在这道题了。。。一直觉得会超内存,后来看了题解才知道自己真是笨的可以。。。题目做的太少的缘故吧。。。这道题正好是点更新,果断放弃了线段树,用树状数组来搞(结果到最后也没有更新,反正趁机又复习了一下树状数组),第一次用map,感觉真是好用啊。。。下面是ac代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <map>using namespace std;const int maxn = 100005;int a[maxn<<1],c[maxn<<1],n;map <long long,int> u;int lowbit(int x){ return x&(-x);}void init(){ memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) { for(int j=i-lowbit(i)+1;j<=i;j++) { c[i]+=a[j]; } }}int Sum(int i){ int sum=0; while(i) { sum+=c[i]; i-=lowbit(i); } return sum;}void change(int i,int x){ while(i<=n) { c[i]+=x; i+=lowbit(i); }}int main(){ int tCase; scanf("%d",&tCase); while(tCase--) { int N; scanf("%d",&N); n=0; u.clear(); while(N--) { long long x,y; scanf("%I64d%I64d",&x,&y); u[x]=u[x]+1; u[y+1]=u[y+1]-1; } map <long long,int> :: iterator iter; for(iter=u.begin();iter!=u.end();iter++) { a[++n]=iter->second; } init(); int ans=0; for(int i=0;i<n;i++) { int sum=Sum(i); if(ans<sum) ans=sum; } printf("%d\n",ans); } return 0;}
0 0
- HDU 5124 树状数组+map操作
- hdu 4630 树状数组+离线操作+GCD
- hdu 3874 Necklace 树状数组 离线操作
- HDU 4417 Super Mario(线段树||树状数组+离线操作 之树状数组篇)
- hdu 5124 lines(树状数组)
- hdu 4417 Super Mario 树状数组+离线操作
- HDU 4630 No Pain No Game 树状数组+离线操作
- hdu 3333 Turing Tree(树状数组离线操作)
- HDU 3874 Necklace(树状数组的离线操作)
- HDU 3874 Necklace(树状数组 && 离线操作)
- HDU 4417 Super Mario [树状数组+离线操作]【数据结构】
- HDU 3874 Necklace (树状数组+离线操作)
- HDU-4417:Super Mario(树状数组+离线操作)
- hdu-4638-Group-(树状数组,离线操作)
- HDU 1394 树状数组
- 树状数组 hdu
- hdu 1166 树状数组
- HDU 2838 树状数组
- ubuntu在recovery模式下更改用户密码
- Android Loader(四) 自定义Loader从网络中获取文本数据
- 【Python爬虫】批量抓取网页上的视频
- 《读书笔记》设计模式——装饰模式
- 存储管理-分区分配与回收算法(Java简单实现)
- HDU 5124 树状数组+map操作
- char、varchar、nchar、nvarchar的区别
- Java面试题--基础知识部分
- hdoj problem 3177 Crixalis's Equipment(贪心题)
- PhpMyAdmin漏洞利用总结with Metasploit
- 利用后台SQL查询语句拿webshell
- hdoj problem 5037 Frog(贪心)
- 图形
- 巧用“Delegate”实现AOP事务