Submission #957682

#TimeUsernameProblemLanguageResultExecution timeMemory
957682VinhLuuStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
154 ms54468 KiB
#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]);
    }
    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[i].empty()){
            b[vr[i][0]] = p[i];
            for(int j = vr[i][0]; j <= vr[i].back(); j ++) b[j] = p[i];
        }
    }
    for(int i = 1; i <= n; i ++) cout << b[i] << "\n";
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:56:17: warning: unused variable 'v' [-Wunused-variable]
   56 |             int v = i;
      |                 ^
Main.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...