# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
957678 | VinhLuu | Stone Arranging 2 (JOI23_ho_t1) | C++17 | 2064 ms | 34140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int oo = 2e18;
int n, a[N], b[N], t, p[N];
vector<int> vr[N];
int c[N];
void sub1(){
for(int i = 1; i <= n; i ++){
c[i] = a[i];
for(int j = i - 1; j >= 1; j --){
if(c[j] == c[i]){
for(int k = j; k <= i; k ++) c[k] = a[i];
break;
}
}
}
for(int i = 1; i <= n; i ++) cout << c[i] << "\n";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n;
set<int> s;
for(int i = 1; i <= n; i ++){
cin >> a[i];
s.insert(a[i]);
}
sub1();
return 0;
for(auto j : s) p[++t] = j;
for(int i = 1; i <= n; i ++) a[i] = lower_bound(p + 1, p + t + 1, a[i]) - p;
vector<int> cur;
for(int i = 1; i <= n; i ++){
if(!vr[a[i]].empty()){
int u = vr[a[i]].back();
int v = i;
while(!cur.empty() && cur.back() > u){
int tmp = cur.back();
vr[a[tmp]].pop_back();
cur.pop_back();
}
}
vr[a[i]].pb(i);
cur.pb(i);
}
for(int i = 1; i <= t; i ++){
if(!vr[p[i]].empty()){
b[vr[p[i]][0]] = p[i];
for(int j = vr[p[i]][0]; j <= vr[p[i]].back(); j ++) b[j] = p[i];
}
}
for(int i = 1; i <= n; i ++) cout << b[i] << "\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... |