记录编号 |
118377 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.024 s |
提交时间 |
2014-09-06 15:14:31 |
内存使用 |
1.26 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
const int MAXN=50010;
int num[MAXN];
int sum[32768*3],n;
int l[MAXN],r[MAXN];
//==============function declaration============
int lowbit(int x);
int query(int x);
void update(int x);
//==============main code=======================
int main()
{
string FileName="queueb";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d",&n);
For(i,1,n)
{
scanf("%d",&num[i]);
num[i]++;
}
memset(sum,0,sizeof(sum));
For(i,1,n)
{
l[i]=query(num[i]-1);
update(num[i]);
}
memset(sum,0,sizeof(sum));
for(int i=n;i>=1;i--)
{
r[i]=query(num[i]-1);
update(num[i]);
}
/*For(i,1,n)
printf("%d %d\n",l[i],r[i]);*/
LL res=0;
For(i,1,n)
res+=l[i]*r[i];
printf("%lld\n",res);
#ifdef DEBUG
clock_t End_Time=clock();
cout<<endl<<endl<<"Time Used: "<<(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif
return 0;
}
//================fuction code====================
int lowbit(int x)
{
return x&-x;
}
int query(int x)
{
LL res=0;
while (x>0)
{
res+=sum[x];
x-=lowbit(x);
}
return res;
}
void update(int x)
{
while (x<=32767)
{
sum[x]++;
x+=lowbit(x);
}
}