Submission #1043999

# Submission time Handle Problem Language Result Execution time Memory
1043999 2024-08-05T06:16:40 Z 12345678 Editor (BOI15_edi) C++17
0 / 100
1 ms 860 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=5e3+5;

int n, a, t[nx], vl[nx], p[nx], sz[nx], c[nx], cnt[nx];
vector<int> d[nx], g[nx];
set<int> s;

void dfs(int u, int rt)
{
    c[u]=rt;
    for (auto v:g[u]) dfs(v, rt);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) 
    {
        cin>>t[i];
        sz[i]=1;
        if (t[i]<0) t[i]=-t[i], d[t[i]].push_back(i);
        else vl[i]=t[i], t[i]=0;
    }
    for (int i=n; i>=1; i--)
    {
        for (auto x:d[i])
        {
            int y=x;
            while (t[y]>=t[x]||((sz[y]%2)==0)) y--;
            sz[y]+=sz[x];
            g[y].push_back(x);
        }
    }
    s.insert(0);
    for (int i=1; i<=n; i++) if (!t[i]) dfs(i, i);
    //for (int i=1; i<=n; i++) cout<<"c "<<i<<' '<<c[i]<<'\n';
    for (int i=1; i<=n; i++)
    {
        cnt[c[i]]++;
        if ((cnt[c[i]]%2)==1) s.insert(c[i]);
        else s.erase(c[i]);
        cout<<vl[*prev(s.end())]<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -