记录编号 |
232265 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列 |
最终得分 |
100 |
用户昵称 |
liu_runda |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.070 s |
提交时间 |
2016-02-29 15:17:46 |
内存使用 |
0.66 MiB |
显示代码纯文本
- #include<cstdio>
- #include<cstring>
- int a[53000],c[33000];
- int shun[53000];
- int lowbit(int x){return x&-x;}
- void update(int x){
- for(int i=x;i<33000;i+=lowbit(i))c[i]++;
- }
- int sum(int x){
- int ans=0;
- for(int i=x;i;i-=lowbit(i))ans+=c[i];
- return ans;
- }
- int read(){
- char ch;int x;
- while(ch=getchar(),ch>'9'||ch<'0');
- x=ch-48;
- while(ch=getchar(),ch<='9'&&ch>='0')x=x*10+ch-48;
- return x;
- }
- int main(){
- freopen("queueb.in","r",stdin);
- freopen("queueb.out","w",stdout);
- int n;scanf("%d",&n);
- long long ans=0;
- for(int i=0;i<n;++i){
- scanf("%d",a+i);
- a[i]++;
- update(a[i]);
- shun[i]=sum(a[i]-1);
- }
- memset(c,0,sizeof(c));
- for(int i=n-1;i>=0;--i){
- update(a[i]);
- ans+=shun[i]*sum(a[i]-1);
- }
- printf("%lld",ans);
- fclose(stdin);fclose(stdout);
- return 0;
- }