Submission #13859

# Submission time Handle Problem Language Result Execution time Memory
13859 2015-04-08T07:50:27 Z gs14004 사회적 불평등 (TOKI14_social) C++14
0 / 100
49 ms 2176 KB
#include <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
const int MAX = 10000;
typedef long long lint;

int n;
pi a[100005];

struct bit{
    lint tree[10005];
    int lim;
    void init(int n){
        memset(tree,0,sizeof(tree));
        lim = n + 1;
    }
    void add(int x, lint v){
        x++;
        while(x < lim){
            tree[x] += v;
            x += x & -x;
        }
    }
    lint S(int x){
        x++;
        lint ret = 0;
        while(x){
            ret += tree[x];
            x -= x & -x;
        }
        return ret;
    }
    lint sum(int x, int y){
        return S(y) - S(x-1);
    }
}bit1, bit2, bit3, bit4;

lint solve(){
    lint ret = 0;
    bit1.init(MAX);
    bit2.init(MAX);
    bit3.init(MAX);
    bit4.init(MAX);
    for (int i=n-1; i>=0; i--) {
        ret += 1ll * bit1.sum(a[i].second+1,MAX) * a[i].first * a[i].second;
        ret += 1ll * bit2.sum(a[i].second+1,MAX);
        ret -= 1ll * a[i].first * bit3.sum(a[i].second+1,MAX);
        ret -= 1ll * a[i].second * bit4.sum(a[i].second+1,MAX);
        bit1.add(a[i].second,1);
        bit2.add(a[i].second,1ll * a[i].first * a[i].second);
        bit3.add(a[i].second,a[i].second);
        bit4.add(a[i].second,a[i].first);
    }
    return ret;
}


int main(){
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a[i].first,&a[i].second);
    }
    sort(a,a+n);
    lint ret = solve();
    for (int i=0; i<n; i++) {
        a[i].second = MAX + 1 - a[i].second;
    }
    ret += solve();
    printf("%lld",ret);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
4 Correct 0 ms 2176 KB Output is correct
5 Incorrect 0 ms 2176 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2176 KB Output is correct
2 Correct 25 ms 2176 KB Output is correct
3 Correct 14 ms 2176 KB Output is correct
4 Correct 19 ms 2176 KB Output is correct
5 Incorrect 22 ms 2176 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2176 KB Output is correct
2 Correct 29 ms 2176 KB Output is correct
3 Incorrect 25 ms 2176 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2176 KB Output is correct
2 Correct 37 ms 2176 KB Output is correct
3 Correct 49 ms 2176 KB Output is correct
4 Incorrect 20 ms 2176 KB Output isn't correct
5 Halted 0 ms 0 KB -