#include "treasure.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> encode(vector<pair<int, int>> P) {
// send all possible x, y
vector<int> Y;
vector<int> res;
for (auto& [x, y] : P) {
res.push_back(x);
res.push_back(y + 5e8 + 1);
Y.push_back(y);
}
sort(Y.begin(), Y.end());
sort(P.begin(), P.end());
int sum = 1e9 + 2;
for (int i = 0;i < (int)P.size();i++) {
int idx = lower_bound(Y.begin(), Y.end(), P[i].second) - Y.begin();
res.push_back(sum + idx);
sum += idx;
}
return res;
}
vector<pair<int, int>> decode(vector<int> S) {
vector<int> X;
vector<int> Y;
vector<int> pos;
sort(S.begin(), S.end());
int sum = 1e9 + 2;
for (auto& x : S) {
if (x <= 5e8) X.push_back(x);
else if (x <= 1e9 + 1) Y.push_back(x - 5e8 - 1);
else {
pos.push_back(x - sum);
sum = x;
}
}
int n = pos.size();
vector<pair<int, int>> ans;
for (int i = 0;i < n;i++) {
ans.push_back(pair<int, int>(X[i], Y[pos[i]]));
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |