-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP5864.cpp
56 lines (52 loc) · 1.38 KB
/
P5864.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
#include "header.h"
struct rec
{
int val;
int id;
rec(int v, int i):val(v), id(i) {}
bool operator < (const rec& b)
{
return this->val < b.val;
}
};
class Solution {
public:
int numberOfWeakCharacters(vector<vector<int>>& properties) {
vector<int> atkOrd(100001, false), defOrd(10001, false);
vector<rec> atk, def;
atk.reserve(properties.size());
def.reserve(properties.size());
for (int i=0; i<properties.size(); i++)
{
atk.emplace_back(properties[i][0], i);
def.emplace_back(properties[i][1], i);
}
sort(atk.begin(), atk.end());
sort(def.begin(), def.end());
int n = properties.size();
int curA = 0, cntA = 0, ordA = 0;
int curD = 0, cntD = 0, ordD = 0;
int numA[10001], numD[10001];
for (int i=0; i<n; i++)
{
if (atk[i].val>curA)
{
ordA += cntA;
cntA = 0;
}
cntA++;
numA[atk[i].id] = ordA;
if (def[i].val>curD)
{
ordD += cntD;
cntD = 0;
}
cntD++;
numD[def[i].id] = ordD;
}
cout << cntA << " " << cntD << endl;
for (int i=0; i<n; i++)
cout << numA[i] << " " << numD[i] << endl;
return 0;
}
};