思路:直接用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 二维树状数组的更多相关文章

  1. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  2. poj 2029 二维树状数组

    思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...

  3. poj 2155 (二维树状数组 区间修改 求某点值)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33682   Accepted: 12194 Descript ...

  4. Mobile phones POJ - 1195 二维树状数组求和

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  5. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  6. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  7. POJ 2155 Matrix(二维树状数组,绝对具体)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Descripti ...

  8. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  9. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

随机推荐

  1. CFileDialog 、CFile 如何进行文件操作 [转]

    如何进行文件操作 [1]显示对话框,取得文件名 CString FilePathName; CFileDialog dlg(TRUE);//TRUE为OPEN对话框,FALSE为SAVE AS对话框 ...

  2. Julien Nioche谈Apache Nutch 2的特性及产品路线图

    原文地址: http://www.infoq.com/cn/articles/nioche-apache-nutch2 开源的Web搜索框架Apache Nutch的2.1版本已于2012年10月5日 ...

  3. 初步认识pg_control文件之一

    这个据说是PostgreSQL的control file. 到底如何呢,先看看改名后如何,把pg_control文件改名,然后启动 Postgres,运行时得到信息: [postgres@pg101 ...

  4. WEB前端性能优化小结

    转:http://www.gafish.net/archives/1514 对前端开发工程师来说,前端性能优化的重要性是不言而喻的,最为大家所知的是YSLOW的23条优化规则,在我的理解中,性能优化不 ...

  5. CSDN问答频道“华章杯”7月排行榜活动开始,丰厚奖品等你拿

    CSDN问答频道月度排行榜,是CSDN问答频道从3月开始举办的活动,旨在鼓励更多用户参与提问和解答,创造一个良好的互帮互助氛围,使参与者在问和答的过程中得到技术水平的提升,也希望大家能在技术交流中结交 ...

  6. C++学习笔记之继承

    一.基类和派生类 很多时候,一个类的对象也“是”另一个类的对象,如矩形是四边形,在C++中,矩形类Rectangle可以由四边形类Quad继承而来,于是,四边形类Quad是基类,矩形类Rectangl ...

  7. Android Recovery Ui 分析

    Android  recovery和android本质上是两个独立的rootfs, 仅仅是recovery这个rootfs存在的意义就是为android这个rootfs服务,因此被解释为Android ...

  8. boost::token_compress_on

    对于场景:string s = "123456",用"3","4"切分,默认情况下(boost::token_compress_off),切 ...

  9. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  10. C#中正则表达式只取前N个匹配结果

    用Regex.Matches方法可以得到同指定正则表达式对应的所有匹配结果.有时,所有匹配结果可能有成千上万个,考虑到性能效率的因素,只需要取出前N个匹配结果.下面的代码演示了做法: 需求:取字符串中 ...