poj 3378 二维树状数组
思路:直接用long long 保存会WA。用下高精度加法就行了。
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define Maxn 50010
#define Maxm 80002
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 100000
#define lowbit(x) (x&(-x))
#define mod 1000000000
using namespace std;
LL c[Maxn][][];
int n,num[Maxn];
struct OO{
LL val[];
};
struct PP{
int val,i;
int operator<(const PP &temp) const{
return val<temp.val;
}
}sorted[Maxn];
void update(int pos,int num,OO temp)
{
while(pos<=n){
c[pos][num][]+=temp.val[];
c[pos][num][]+=temp.val[];
c[pos][num][]+=c[pos][num][]/mod;
c[pos][num][]%=mod;
pos+=lowbit(pos);
}
}
OO Sum(int pos,int num)
{
OO sum;
sum.val[]=sum.val[]=;
while(pos){
sum.val[]+=c[pos][num][];
sum.val[]+=c[pos][num][];
sum.val[]+=sum.val[]/mod;
sum.val[]%=mod;
pos-=lowbit(pos);
}
return sum;
}
int main()
{
int i,j;
//freopen("ttt.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
memset(c,,sizeof(c));
for(i=;i<=n;i++){
scanf("%d",num+i);
sorted[i].val=num[i];
sorted[i].i=i;
}
sort(sorted+,sorted++n);
int cnt=;
for(i=;i<=n;i++){
if(sorted[i].val!=sorted[i-].val){
num[sorted[i].i]=++cnt;
}
else num[sorted[i].i]=cnt;
}
OO sum;
sum.val[]=sum.val[]=;
OO temp;
for(i=;i<=n;i++){
temp=Sum(num[i]-,);
sum.val[]+=temp.val[];
sum.val[]+=temp.val[];
sum.val[]+=sum.val[]/mod;
sum.val[]%=mod;
temp.val[]=;
temp.val[]=;
update(num[i],,temp);
for(j=;j>=;j--)
update(num[i],j,Sum(num[i]-,j-));
}
if(sum.val[]){
printf("%I64d",sum.val[]);
cout<<right<<setw()<<setfill('')<<sum.val[]<<endl;
}
else printf("%I64d\n",sum.val[]);
}
return ;
}
poj 3378 二维树状数组的更多相关文章
- POJ 1195 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18489 Accepted: 8558 De ...
- poj 2029 二维树状数组
思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- poj 2155 (二维树状数组 区间修改 求某点值)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33682 Accepted: 12194 Descript ...
- Mobile phones POJ - 1195 二维树状数组求和
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
随机推荐
- UI:tomcat(说话小程序)、相框动画、UISgmentcontrol、UISwitch
UISegmentedControl 分段控件 //1. UISegmentedControl 分段控件 (就是一个一个的按钮) //分段显示的标题是以一个数组存储的 NSArray * titles ...
- ASP.NET MVC 修改视图的默认路径(MVC2,MVC3)
ASP.NET MVC2 修改视图的默认路径 步骤:1.编写继承自WebFormViewEngine的类,重写视图路径 2.在Application_Start()中添加语句: ViewEngines ...
- oracle 创建同义词
1.语法: 同义词 (SYNONMY) CREATE SYNONYM同义词名FOR 表名; CREATE SYNONYM同义词名FOR 表名@数据库链接名; Create synonym synony ...
- VC++内存区域
转载声明:本文转载自http://blog.csdn.net/sjxbf/article/details/6441730 一.预备知识—程序的内存分配 一个由c/c++编译的程序占用的内存分为以下几个 ...
- cdoj 71 I am Lord Voldemort 水题
I am Lord Voldemort Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/ ...
- Delphi开发OCX详细步骤总结
首先要弄明白你要写的OCX是用在客户端还是用在服务器端 假如用在客户端: 1.创建 打开delphi 7,选择菜单"new"->"other"- ...
- ORA-01489: result of string concatenation is too long
ORA-01489: result of string concatenation is too long Cause: String concatenation result is more tha ...
- mysql sort 性能优化
http://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html 这段时间mysql 数据库的性能明显降低,iowait达到了30, ...
- jquery批量设置属性readonly和disabled
分享下Jquery的api中对元素应用disabled和readonly属性的方法. 1,readonly 属性设置 $('input').attr("readonly",&quo ...
- 项目源码--Android答题类游戏源码
下载源码 技术要点: 1. 精致的答题UI 2. Android的Http通信技术 3. Android数据库QLITE与其他数据存储技术 4. Android在线音乐背景技术 5. Android答 ...