# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20204 | kipa00 | 컬러볼 (KOI15_ball) | C++98 | 140 ms | 40 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX = 200001;
pair<int, pair<int, int> > datas[MAX];
unsigned int sum[MAX], partial_sum[MAX], lastsum[MAX];
int lasts[MAX], lastsi[MAX];
int main() {
int i, n, last = -1;
scanf("%d", &n);
for (i=0; i<n; ++i) {
scanf("%d%d", &datas[i].second.first, &datas[i].first);
datas[i].second.second = i;
lasts[i] = -1;
}
stable_sort(datas, datas + n);
for (i=0; i<n; ++i) {
if (i) {
sum[i] = sum[i - 1] + datas[i - 1].first;
partial_sum[i] = lastsum[datas[i].second.first];
lastsum[datas[i].second.first] = lastsum[datas[i].second.first] + datas[i].first;
} else {
lastsum[datas[0].second.first] = datas[0].first;
}
}
for (i=0; i<n; ++i) {
if (last == datas[i].first) {
sum[i] = sum[i - 1];
} else {
last = datas[i].first;
}
if (lasts[datas[i].second.first] == datas[i].first) {
partial_sum[i] = partial_sum[lastsi[datas[i].second.first]];
} else {
lasts[datas[i].second.first] = datas[i].first;
lastsi[datas[i].second.first] = i;
}
}
for (i=0; i<n; ++i) {
datas[i].second.first = sum[i] - partial_sum[i];
datas[i].first = datas[i].second.second;
}
stable_sort(datas, datas + n);
for (i=0; i<n; ++i) {
printf("%d\n", datas[i].second.first);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |