Submission #798790

#TimeUsernameProblemLanguageResultExecution timeMemory
798790vjudge1Stone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
0 ms340 KiB


#include <bits/stdc++.h>


using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"

const int N = 2e5 + 9 , mod = 1e9 + 7;
ll  d[N] = {} , a[N] = {}, dp[N] = {}, b[N] , c[N];


void solve(){
    ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
    cin>>n;
    map<int,int>mp;
    for(i = 1; i <= n; i++){
        cin>>a[i];
    }
    deque<pair<int,int>>v;
    multiset<ll>st;
    for(i = 1; i <= n; i++){
        if(st.size() && st.find(a[i]) != st.end()){
            while(true){
                st.erase(st.find(v.back().fi));
                x = v.back().se;
                y = v.back().fi;
                v.pop_back();
                if(y == a[i])
                    break;
            }
            b[x] = a[i];
            c[x] = i;
        }
        v.pb({a[i] , i});
        st.insert(a[i]);
    }
    for(i = 1; i <= n; i++){
        if(b[i]){
        k = c[i] , x = b[i];
        while(i <= k){
                a[i] = x;
                i++;
        }
        i--;
        }
    }
    for(i = 1; i <= n; i++)
        cout<<a[i]<<"\n";
}

int main(){

     TL;
     /*
     #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
     #endif
     */
int t = 1;
//cin>>t;

while(t--)
     {
     solve();
     }

}
// Author : حسن

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:28:8: warning: unused variable 'q' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |        ^
Main.cpp:28:16: warning: unused variable 'j' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                ^
Main.cpp:28:20: warning: unused variable 'm' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                    ^
Main.cpp:28:26: warning: unused variable 'z' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                          ^
Main.cpp:28:30: warning: unused variable 's' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                              ^
Main.cpp:28:38: warning: unused variable 'f' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                      ^
Main.cpp:28:41: warning: unused variable 'l' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                         ^
Main.cpp:28:45: warning: unused variable 'r' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                             ^
Main.cpp:28:65: warning: unused variable 'mn' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                                 ^~
Main.cpp:28:78: warning: unused variable 'mx' [-Wunused-variable]
   28 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                                              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...