-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10800.cpp
More file actions
71 lines (62 loc) · 1.52 KB
/
10800.cpp
File metadata and controls
71 lines (62 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ft first
#define sd second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vvpii = vector<vpii>;
using vvpll = vector<vpll>;
using vvs = vector<vs>;
int total,n,c,v;;
int sum[200001];
int color[200001];
int valCnt[2001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
vpii d;
for(int i=0;i<n;i++){
cin>>color[i]>>v;
d.emplace_back(v,i);
}
sort(all(d),[&](const auto &a , const auto &b){
if(a.first<b.first)return true;
if(a.first>b.first)return false;
if(color[a.second]<color[b.second])return true;
return false;
});
vi ans(n);
int curVal = d[0].first;
int idx = d[0].second;
int same=0;
for(auto cur : d){
if(curVal!=cur.first||color[idx]!=color[cur.second]){
sum[color[idx]]+=same*curVal;
same=0;
curVal = cur.first;
idx = cur.second;
}
idx = cur.second;
total+=curVal;
valCnt[curVal]++;
ans[idx] = total-sum[color[idx]]-(valCnt[curVal])*curVal;
same++;
}
for(int x : ans){
cout<<x<<"\n";
}
}