# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
796330 | YassineBenYounes | Stone Arranging 2 (JOI23_ho_t1) | C++17 | 335 ms | 17716 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>
typedef long long ll;
#define pii pair<int, int>
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
////////////////////Only Clear Code//////////////////////////
void usaco_problem(){
freopen("milkvisits.in", "r", stdin);
freopen("milkvisits.out", "w", stdout);
}
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const int mx = 3e5+5;
const int mxnd = mx*33;
const int LOG = 25;
const ll inf = 1e18;
const ll mod = 1e8;
int arr[mx];
void run_case(){
int n;cin >> n;
stack<pii> st;
for(int i = 0; i < n;i++){
cin >> arr[i];
}
map<int, int> found;
for(int i = 0; i < n;i++){
if(!found[arr[i]]){
st.push({arr[i], i});
found[arr[i]] = 1;
continue;
}
while(st.top().ff != arr[i]){
found[st.top().ff] = 0;
st.pop();
}
st.pop();
st.push({arr[i], i});
}
vector<pii> v;
while(!st.empty()){
v.push_back({st.top().ss, st.top().ff});
st.pop();
}
sort(v.begin(), v.end());
int cur = 0;
for(int i = 0; i < v.size();i++){
for(int j = cur;j <= v[i].ff;j++){
arr[j] = v[i].ss;
}
cur = v[i].ff+1;
}
for(int i = 0; i < n;i++){
cout << arr[i] << endl;
}
}
int main(){
speed;
int t = 1;
//cin >> t;
while(t--){
run_case();
}
}
/*
NEVER GIVE UP!
DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
Your Guide when stuck:
- Continue keyword only after reading the whole input
- Don't use memset with testcases
- Check for corner cases(n=1, n=0)
- Check where you declare n(Be careful of declaring it globally and in main)
*/
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... |