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 33#include < algorithm>
44#include < vector>
55namespace cp_algo {
6+ // coords is a range of reference_wrapper<T>
67 std::vector<int > compress_coords (auto &coords) {
7- static_assert (std::is_pointer_v<std::ranges::range_value_t <decltype (coords)>>);
88 std::vector<int > original;
99 original.reserve (size (coords));
10- std::ranges::sort (coords, {}, []( int * x) { return *x;} );
10+ std::ranges::sort (coords);
1111 int idx = -1 , prev = -1 ;
12- for (auto x: coords) {
13- if (* x != prev) {
12+ for (auto & x: coords) {
13+ if (x != prev) {
1414 idx++;
15- prev = * x;
16- original.push_back (* x);
15+ prev = x;
16+ original.push_back (x);
1717 }
18- *x = idx;
18+ x. get () = idx;
1919 }
2020 return original;
2121 }
Original file line number Diff line number Diff line change @@ -12,16 +12,16 @@ void solve() {
1212 int n, q;
1313 cin >> n >> q;
1414 vector a (n, 0 );
15- vector<int * > coords;
15+ vector<reference_wrapper< int > > coords;
1616 for (auto &it: a) {
1717 cin >> it;
18- coords.push_back (&it );
18+ coords.push_back (ref (it) );
1919 }
2020 vector queries (q, pair{0 , 0 });
2121 for (auto &[t, x]: queries) {
2222 cin >> t >> x;
2323 if (t != 2 ) {
24- coords.push_back (&x );
24+ coords.push_back (ref (x) );
2525 }
2626 }
2727 auto values = cp_algo::compress_coords (coords);
You can’t perform that action at this time.
0 commit comments