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 ...
随机推荐
- inpuy type=date
http://www.w3schools.com/html/html_form_input_types.asp http://caniuse.com/#feat=input-datetime 浏览器兼 ...
- mvc api odata 查询选项之 $inlinecount ,$format 选项
网上百度“odata 语法”会出来很多结果,其中有一项是比较一致的,那就是odata支持一下几种语法: $filter 条件表达式 -- 对应sql语句的where条件查询,如:/Categorie ...
- RHEL 5.4下部署LVS(DR)+keepalived实现高性能高可用负载均衡
原文地址:http://www.cnblogs.com/mchina/archive/2012/05/23/2514728.html 一.简介 LVS是Linux Virtual Server的简写, ...
- 操作无法完成,因为文件夹已在另一个程序中打开(the action can't be completed because the folder or a file in it is open in another program)
解决方法: 启动任务管理器——性能——资源监视器——CPU选项卡——关联的句柄——搜索句柄 ——(输入)要删除的文件夹名——搜索到与文件夹名句柄相关联的进程 (由于此程序进程正在调用文件夹,才造成了对 ...
- 729 - The Hamming Distance Problem
// 题意: // 输入两个整数N, H,按照字典序输出所有长度为N,恰好包含H个1的01串 // 规模:1<=H<=N<=16 // 算法A:2^N枚举,输出1的个数为H的.采 ...
- 学习理论之正则化(Regularization)与模型选择
一.引言 对于一个学习问题,可以假设很多不同的模型,我们要做的是根据某一标准选出最好的模型.例如,在多项式回归中,对于我们的假设模型,我们最要紧的是决定 k 到底取多少合适,能不能有一种方法可以自动选 ...
- BZOJ 3930: [CQOI2015]选数 递推
3930: [CQOI2015]选数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pro ...
- pushState onpopstate
转载自:http://www.cnblogs.com/gaoxue/p/3885796.html 参考MDN: https://developer.mozilla.org/zh-CN/docs/DOM ...
- php 换行 空格分割处理
<?php function parse_specification($specification){ $rt=array(); $lines=array_filter(preg_split(& ...
- LeetCode29 Divide Two Integers
题目: Divide two integers without using multiplication, division and mod operator. If it is overflow, ...