Submission #977322

# Submission time Handle Problem Language Result Execution time Memory
977322 2024-05-07T18:14:57 Z alexdd Zalmoxis (BOI18_zalmoxis) C++17
40 / 100
267 ms 83276 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,cnt;
set<pair<int,int>> rez;
vector<int> pozs[31];
int a[5000005],inita[5000005];
int nxt[5000005][2],prec[5000005][2];
void baga_dupa(int p, int x, int c)
{
    int pnxt = nxt[p][c];
    nxt[p][c] = x;
    nxt[x][c] = pnxt;

    prec[x][c] = p;
    prec[pnxt][c] = x;
}
void scoate(int p, int c)
{
    nxt[prec[p][c]][c] = nxt[p][c];
    prec[nxt[p][c]][c] = prec[p][c];
}
vector<int> aux;
void calc(int x)
{
    if(k==0 || x==0)
    {
        aux.push_back(x);
        return;
    }
    k--;
    calc(x-1);
    calc(x-1);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    int initn=n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        inita[i]=a[i];
        prec[i][0]=prec[i][1]=i-1;
        nxt[i][0]=nxt[i][1]=i+1;
        pozs[a[i]].push_back(i);
    }
    nxt[n][0]=nxt[n][1]=0;
    for(int i=0;i<30;i++)
    {
        sort(pozs[i].begin(),pozs[i].end());
        for(int j=(int)pozs[i].size()-1;j>=0;j--)
        {
            if(j>0 && nxt[pozs[i][j-1]][0] == pozs[i][j])
            {
                //cout<<i<<" zzz\n";
                pozs[i+1].push_back(pozs[i][j]);

                a[pozs[i][j]]++;
                scoate(pozs[i][j-1],0);
                j--;
            }
            else
            {
                pozs[i+1].push_back(pozs[i][j]);

                k--;
                n++;
                a[n]=inita[n]=i;
                baga_dupa(pozs[i][j],n,1);
                a[pozs[i][j]]++;
            }
        }
        /*cout<<i<<"    ";
        int cur=1;
        while(cur!=0)
        {
            cout<<a[cur]<<" ";
            cur = nxt[cur][0];
        }
        cout<<"\n";*/
    }
    int cur=1;
    for(int i=1;i<=n;i++)
    {
        if(cur<=initn) aux.push_back(inita[cur]);
        else calc(inita[cur]);
        cur = nxt[cur][1];
    }
    for(auto x:aux)
        cout<<x<<" ";
    return 0;
}
/**
5 1
29 27 25 25 28

1 5
29
*/
# Verdict Execution time Memory Grader output
1 Correct 258 ms 82068 KB Output is correct
2 Correct 265 ms 82420 KB Output is correct
3 Correct 259 ms 82452 KB Output is correct
4 Correct 261 ms 82376 KB Output is correct
5 Correct 257 ms 82648 KB Output is correct
6 Correct 250 ms 83028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 267 ms 82440 KB not a zalsequence
2 Incorrect 246 ms 83276 KB not a zalsequence
3 Incorrect 261 ms 80360 KB not a zalsequence
4 Incorrect 258 ms 82424 KB not a zalsequence
5 Incorrect 259 ms 82844 KB not a zalsequence
6 Correct 256 ms 82192 KB Output is correct
7 Correct 262 ms 83236 KB Output is correct
8 Incorrect 260 ms 82300 KB not a zalsequence
9 Incorrect 257 ms 74212 KB not a zalsequence
10 Incorrect 115 ms 41900 KB not a zalsequence
11 Incorrect 173 ms 55688 KB not a zalsequence
12 Incorrect 52 ms 16568 KB not a zalsequence
13 Incorrect 56 ms 16488 KB not a zalsequence
14 Incorrect 53 ms 16552 KB not a zalsequence