Submission #20204

#TimeUsernameProblemLanguageResultExecution timeMemory
20204kipa00컬러볼 (KOI15_ball)C++98
25 / 25
140 ms40 KiB
#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)

ball.cpp: In function 'int main()':
ball.cpp:12:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
ball.cpp:14:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &datas[i].second.first, &datas[i].first);
                                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...