| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1308860 | thuhienne | Stone Arranging 2 (JOI23_ho_t1) | C++20 | 103 ms | 18076 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define thuhien ""
#define re exit(0);
const int maxn = 200009;
int n,arr[maxn];
pair <int,int> range[maxn];
vector <int> X;
struct seg {
int l,r,color;
const bool operator < (const seg & other) const {
return l < other.l;
}
const bool operator > (const seg & other) const {
return r > other.r;
}
};
set <seg> freq;
set <seg>::iterator it;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> arr[i];
X.push_back(arr[i]);
}
sort(X.begin(),X.end());
X.resize(unique(X.begin(),X.end()) - X.begin());
for (int i = 1;i <= n;i++) {
arr[i] = lower_bound(X.begin(),X.end(),arr[i]) - X.begin() + 1;
}
for (int i = 1;i <= n;i++) {
if (!range[arr[i]].first) {
freq.insert({i,i,arr[i]});
range[arr[i]] = {i,i};
} else {
int l = range[arr[i]].first,r = range[arr[i]].second;
it = freq.find({l,r,arr[i]});
range[arr[i]] = {it->l,i};
it = freq.erase(it);
while (it != freq.end()) {
range[it->color] = {0,0};
it = freq.erase(it);
}
freq.insert({range[arr[i]].first,range[arr[i]].second,arr[i]});
}
}
for (seg x : freq) {
for (int i = x.l;i <= x.r;i++) cout << X[x.color - 1] << '\n';
}
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
