[ create a new paste ] login | about

Link: http://codepad.org/F7qM6i7W    [ raw code | output | fork ]

didyxdi - C++, pasted on Sep 3:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;

struct node
{
    int pos,v;
};

int n;
node a[20005];
long long update[2][100000];//(树状数组)update[0][x]中存放当前比位置x小的个数 ;update[1][x]中存放当前比位置x小的位置之和!!! 
long long ans;//注意数据范围,本题应取long long 

bool cmp(node x,node y)
{
    if(x.v<y.v) return true;
    if(x.v==y.v && x.pos<y.pos) return true;
    return false;
}

void cln()
{
    memset(a,0,sizeof(a));
    memset(update,0,sizeof(update));
    ans=0;
}

void add(int t,long long x,int p)
{
    while(p<40000)
    {
        update[t][p]+=x;
        p+=p& -p;
    }
}

long long sum(int t,int p)
{
    long long s=0;
    while(p>0)
    {
        s+=update[t][p];
        p-=p& -p;
    }
    return s;
}

void ipt()
{
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i].v,&a[i].pos);
    sort(a+1,a+n+1,cmp);
}

void solve()
{
    for(long long i=1;i<=n;i++)
    {
        long long t=sum(0,a[i].pos);
        long long s1,s2;
        s1=sum(1,a[i].pos);
        s2=sum(1,20000);
        ans+=a[i].v*((t*a[i].pos-s1)+(s2-s1-(i-1-t)*a[i].pos));//分类讨论 
        add(0,1,a[i].pos);
        add(1,(long long)a[i].pos,a[i].pos);
    }
}

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        cln();
        ipt();
        solve();
        printf("%I64d\n",ans);
    }
    return 0;
}


Output:
1
2
Line 22: error: ISO C++ does not support 'long long'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: