# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44640 | RayaBurong25_1 | Editor (BOI15_edi) | C++17 | 361 ms | 66036 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |