# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
13867 |
2015-04-09T06:52:30 Z |
gs14004 |
사회적 불평등 (TOKI14_social) |
C++14 |
|
69 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, int 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,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 |
1 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 |
Correct |
0 ms |
2176 KB |
Output is correct |
6 |
Correct |
0 ms |
2176 KB |
Output is correct |
7 |
Correct |
0 ms |
2176 KB |
Output is correct |
8 |
Correct |
0 ms |
2176 KB |
Output is correct |
9 |
Correct |
2 ms |
2176 KB |
Output is correct |
10 |
Correct |
0 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2176 KB |
Output is correct |
2 |
Correct |
26 ms |
2176 KB |
Output is correct |
3 |
Correct |
22 ms |
2176 KB |
Output is correct |
4 |
Correct |
15 ms |
2176 KB |
Output is correct |
5 |
Correct |
26 ms |
2176 KB |
Output is correct |
6 |
Correct |
25 ms |
2176 KB |
Output is correct |
7 |
Correct |
14 ms |
2176 KB |
Output is correct |
8 |
Correct |
21 ms |
2176 KB |
Output is correct |
9 |
Correct |
23 ms |
2176 KB |
Output is correct |
10 |
Correct |
23 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
2176 KB |
Output is correct |
2 |
Correct |
24 ms |
2176 KB |
Output is correct |
3 |
Correct |
24 ms |
2176 KB |
Output is correct |
4 |
Correct |
26 ms |
2176 KB |
Output is correct |
5 |
Correct |
25 ms |
2176 KB |
Output is correct |
6 |
Correct |
26 ms |
2176 KB |
Output is correct |
7 |
Correct |
26 ms |
2176 KB |
Output is correct |
8 |
Correct |
18 ms |
2176 KB |
Output is correct |
9 |
Correct |
23 ms |
2176 KB |
Output is correct |
10 |
Correct |
26 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2176 KB |
Output is correct |
2 |
Correct |
56 ms |
2176 KB |
Output is correct |
3 |
Correct |
50 ms |
2176 KB |
Output is correct |
4 |
Correct |
29 ms |
2176 KB |
Output is correct |
5 |
Correct |
34 ms |
2176 KB |
Output is correct |
6 |
Correct |
47 ms |
2176 KB |
Output is correct |
7 |
Correct |
42 ms |
2176 KB |
Output is correct |
8 |
Correct |
59 ms |
2176 KB |
Output is correct |
9 |
Correct |
62 ms |
2176 KB |
Output is correct |
10 |
Correct |
69 ms |
2176 KB |
Output is correct |