Submission #44640

#TimeUsernameProblemLanguageResultExecution timeMemory
44640RayaBurong25_1Editor (BOI15_edi)C++17
100 / 100
361 ms66036 KiB
#include <stdio.h>
#include <vector>
int Val[300005];
typedef struct node node;
struct node
{
    int level[20];
    int last;
    int next[20];
};
node Last[300005];
// std::vector<std::pair<int, int> > Last[300005];
int max(int a, int b)
{
    return (a > b)?a:b;
}
int main()
{
    int N;
    scanf("%d", &N);
    int i, x;
    // std::vector<std::pair<int, int> >::iterator it;
    int j, k;
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &x);
        if (x > 0)
        {
            Val[i] = x;
            // Last[i] = Last[i - 1];
            // Last[i].push_back({0, i - 1});
            // Last[i] = {0, i - 1, i - 1};
            Last[i].level[0] = 0;
            Last[i].last = i - 1;
            Last[i].next[0] = i - 1;
            for (k = 1; k < 20; k++)
            {
                Last[i].level[k] = max(Last[i].level[k - 1], Last[Last[i].next[k - 1]].level[k - 1]);
                Last[i].next[k] = Last[Last[i].next[k - 1]].next[k - 1];
            }
            printf("%d\n", Val[i]);
        }
        else
        {
            // it = Last[i - 1].end();
            // it--;
            // while (it->first <= x) it--;
            j = i - 1;
            for (k = 19; k >= 0; k--)
            {
                if (Last[j].level[k] <= x)
                {
                    j = Last[j].next[k];
                }
            }
            // j = i - 1;
            // while (Last[j].level <= x) j = Last[j].next;
            j = Last[j].last;
            Val[i] = Val[j];
            // Last[i] = Last[it->second];
            // Last[i].push_back({x, i - 1});
            // Last[i] = {x, i - 1, j};
            Last[i].level[0] = x;
            Last[i].last = i - 1;
            Last[i].next[0] = j;
            for (k = 1; k < 20; k++)
            {
                Last[i].level[k] = max(Last[i].level[k - 1], Last[Last[i].next[k - 1]].level[k - 1]);
                Last[i].next[k] = Last[Last[i].next[k - 1]].next[k - 1];
            }
            printf("%d\n", Val[i]);
        }
    }
}

Compilation message (stderr)

edi.cpp: In function 'int main()':
edi.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
edi.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...