Submission #18037

#TimeUsernameProblemLanguageResultExecution timeMemory
18037gs14004컬러볼 (KOI15_ball)C++14
0 / 25
125 ms7188 KiB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

lint ret[200005];
lint sum[200005], fsum;

struct elem{int c, s, i;}a[200005];
int n;

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d %d",&a[i].c, &a[i].s);
		a[i].i = i;
	}
	sort(a, a+n, [&](const elem &a, const elem &b){
		return a.s < b.s;
	});
	for(int i=0; i<n; i++){
		int e = i;
		while(e < n && a[e].s == a[i].s) e++;
		for(int j=i; j<e; j++){
			ret[a[i].i] = fsum - sum[a[i].c];
		}
		for(int j=i; j<e; j++){
			fsum += a[i].s;
			sum[a[i].c] += a[i].s;
		}
	}
	for(int i=0; i<n; i++){
		printf("%lld\n",ret[i]);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...