树状数组BITLA 4329
来源:互联网 发布:macos 配置软件 编辑:程序博客网 时间:2024/06/05 12:15
我去,数组最大值 跟 数据最大值 没搞清楚,WA了好多次都看不出来错在哪。这种错误一旦犯了,小数据根本看不不出来。。
#include <iostream>#include <fstream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;#define N 100005int lowbit[N], low[N], a[N];long long c[N], n;void Init(){ for (int i=1;i<N;i++) lowbit[i]=i&(-i);}void init(){ for (int i=0;i<N;i++) c[i]=0;}void add(int x,int d){ while (x<N) { c[x]+=d; x+=lowbit[x]; }}long long sum(int x){ long long js=0; while (x) { js+=c[x]; x-=lowbit[x]; } return js;}int main(){ //freopen("1.in","r",stdin); int T, n1; long long ans; cin>>T; Init(); while (T--){ scanf("%d",&n1); n=n1; init(); for (int i=1;i<=n;i++) { scanf("%d",&a[i]); low[i]=sum(a[i]); add(a[i],1); } init(); ans=0; add(a[n],1); for (int j=n-1;j>1;j--){ long long i=j, tmp=sum(a[i]); ans+=low[i]*(n-i-tmp)+(i-1-low[i])*tmp; add(a[i],1); } cout<<ans<<endl; } return 0;}
- 树状数组BITLA 4329
- LA 4329 树状数组
- LA 4329 树状数组
- LA 4329(树状数组)
- LA 4329(树状数组)
- LA 4329 树状数组入门
- UVALIVE 4329(树状数组)
- UVALive 4329 (树状数组)
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- HDU3716 Jenga
- NS2仿真过程中需要的语言及基本组件
- C++中的new与delete总结
- linux下C语言文件的创建打开和关闭
- ios中设置N秒后执行一个函数
- 树状数组BITLA 4329
- sqlserver 简单锁实例
- Sphere
- 【转】Ubuntu(Linux)下配置IP地址的方法
- 继续做开发,新阶段
- HTTP协议详解
- httpClient获取Jsoup解析网页
- 超市排队随想录
- ubuntu软件源出错