File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
verify/structures/fenwick Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 3
3
#include < algorithm>
4
4
#include < vector>
5
5
namespace cp_algo {
6
+ // coords is a range of reference_wrapper<T>
6
7
std::vector<int > compress_coords (auto &coords) {
7
- static_assert (std::is_pointer_v<std::ranges::range_value_t <decltype (coords)>>);
8
8
std::vector<int > original;
9
9
original.reserve (size (coords));
10
- std::ranges::sort (coords, {}, []( int * x) { return *x;} );
10
+ std::ranges::sort (coords);
11
11
int idx = -1 , prev = -1 ;
12
- for (auto x: coords) {
13
- if (* x != prev) {
12
+ for (auto & x: coords) {
13
+ if (x != prev) {
14
14
idx++;
15
- prev = * x;
16
- original.push_back (* x);
15
+ prev = x;
16
+ original.push_back (x);
17
17
}
18
- *x = idx;
18
+ x. get () = idx;
19
19
}
20
20
return original;
21
21
}
Original file line number Diff line number Diff line change @@ -12,16 +12,16 @@ void solve() {
12
12
int n, q;
13
13
cin >> n >> q;
14
14
vector a (n, 0 );
15
- vector<int * > coords;
15
+ vector<reference_wrapper< int > > coords;
16
16
for (auto &it: a) {
17
17
cin >> it;
18
- coords.push_back (&it );
18
+ coords.push_back (ref (it) );
19
19
}
20
20
vector queries (q, pair{0 , 0 });
21
21
for (auto &[t, x]: queries) {
22
22
cin >> t >> x;
23
23
if (t != 2 ) {
24
- coords.push_back (&x );
24
+ coords.push_back (ref (x) );
25
25
}
26
26
}
27
27
auto values = cp_algo::compress_coords (coords);
You can’t perform that action at this time.
0 commit comments