이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
const int MAX = 10000;
int n;
pi a[100005];
int elem[10005], t[10005];
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);
int p = 0;
long long ret = 0;
for (int i=1; i<=MAX; i++) {
int j = p;
while (j < n && a[j].first == i) j++;
while (p < j) {
long long q = 0;
for (int k=a[p].second; k<=MAX; k++) {
q += t[k] * (k - a[p].second);
}
for (int k=a[p].second; k; k--) {
q += t[k] * (a[p].second - k);
}
elem[a[p].second]++;
p++;
ret += q;
}
for (int k=1; k<=MAX; k++) {
t[k] += elem[k];
}
}
printf("%lld",ret);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |