forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoci.cpp
119 lines (100 loc) · 2.24 KB
/
coci.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Fenwick {
vector<ll> tree;
Fenwick(int n) {
tree.resize(n,0);
}
Fenwick(const vector<ll>& val) {
tree.resize(val.size(),0);
for(int i = 0; i < val.size(); i++) {
increase(i, val[i]);
}
}
void increase(int i, ll d) {
for(; i<tree.size(); i |= i+1) tree[i] += d;
}
ll sum(int i) {
ll s = 0;
for(; i > 0; i &= i-1) s += tree[i-1];
return s;
}
// [l,r)
ll sum(int l, int r) {
return sum(r) - sum(l);
}
};
struct people {
int pos;
int round1;
int round2;
int worse;
int better;
};
bool cmp(people& p1, people& p2) {
if(p1.round1 == p2.round1) {
return p1.round2 > p2.round2;
}
return p1.round1 < p2.round1;
}
bool cmp2(people& p1, people& p2) {
return p1.pos < p2.pos;
}
void solve(vector<people>& p, bool strictlygreater) {
Fenwick f(652);
for(int i = 0; i < p.size(); i++) {
if(strictlygreater) {
p[i].better = f.sum(p[i].round2+1, 651);
f.increase(p[i].round2, 1);
}
else {
p[i].worse = f.sum(p[i].round2);
f.increase(p[i].round2, 1);
}
}
}
int main() {
int n;
cin >> n;
vector<people> p(n);
for(int i = 0; i < n; i++) {
p[i].pos = i;
cin >> p[i].round1 >> p[i].round2;
}
sort(p.begin(), p.end(), cmp);
solve(p, false);
for(auto& i : p) {
i.round1 *= -1;
i.round2 *= -1;
}
sort(p.begin(), p.end(), cmp);
for(auto& i : p) {
i.round1 *= -1;
i.round2 *= -1;
}
solve(p, true);
map<int,int> cnts1;
map<int,int> cnts2;
for(auto& i : p) {
if(i.round1 == 0) {
cnts1[i.round2]++;
}
if(i.round2 == 0) {
cnts2[i.round1]++;
}
}
int zeros = 0;
for(auto& i : p) {
if(i.round1 == 650) {
i.worse += cnts1[i.round2];
}
if(i.round2 == 650) {
i.worse += cnts2[i.round1];
}
}
sort(p.begin(), p.end(), cmp2);
for(auto i : p) {
cout << (i.better+1) << " " << (p.size() - i.worse) << endl;
}
}