Submission #544655

#TimeUsernameProblemLanguageResultExecution timeMemory
544655pokmui9909컬러볼 (KOI15_ball)C++17
25 / 25
79 ms12212 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll S = 200005; struct ball { ll n, c, s; bool operator<(const ball &k) const { if(s == k.s) return c < k.c; else return s < k.s; } bool operator==(const ball &k) const { return (c==k.c && s==k.s); } }ar[S]; ll c[S], s[S]; ll ans[S]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); ll n; cin >> n; for(ll i = 1; i <= n; i++) { cin >> ar[i].c >> ar[i].s; ar[i].n = i; } sort(ar + 1, ar + n + 1); ll sum = 0; for(ll i = 1; i <= n; i++) { c[ar[i].c] += ar[i].s; s[ar[i].s] += ar[i].s; sum += ar[i].s; ans[ar[i].n] = sum-c[ar[i].c]-s[ar[i].s]+ar[i].s; if(ar[i - 1] == ar[i]) ans[ar[i].n] = ans[ar[i - 1].n]; } for(ll i = 1; i <= n; i++) cout << ans[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...