#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[j].i] = fsum - sum[a[j].c];
}
for(int j=i; j<e; j++){
fsum += a[j].s;
sum[a[j].c] += a[j].s;
}
i = e-1;
}
for(int i=0; i<n; i++){
printf("%lld\n",ret[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
7188 KB |
Output is correct |
2 |
Correct |
88 ms |
7188 KB |
Output is correct |
3 |
Correct |
79 ms |
7188 KB |
Output is correct |
4 |
Correct |
90 ms |
7188 KB |
Output is correct |
5 |
Correct |
119 ms |
7188 KB |
Output is correct |
6 |
Correct |
0 ms |
7188 KB |
Output is correct |
7 |
Correct |
0 ms |
7188 KB |
Output is correct |
8 |
Correct |
0 ms |
7188 KB |
Output is correct |
9 |
Correct |
0 ms |
7188 KB |
Output is correct |
10 |
Correct |
0 ms |
7188 KB |
Output is correct |
11 |
Correct |
96 ms |
7188 KB |
Output is correct |
12 |
Correct |
71 ms |
7188 KB |
Output is correct |
13 |
Correct |
86 ms |
7188 KB |
Output is correct |
14 |
Correct |
84 ms |
7188 KB |
Output is correct |
15 |
Correct |
75 ms |
7188 KB |
Output is correct |
16 |
Correct |
71 ms |
7188 KB |
Output is correct |
17 |
Correct |
82 ms |
7188 KB |
Output is correct |
18 |
Correct |
73 ms |
7188 KB |
Output is correct |
19 |
Correct |
92 ms |
7188 KB |
Output is correct |
20 |
Correct |
95 ms |
7188 KB |
Output is correct |