Submission #846534

#TimeUsernameProblemLanguageResultExecution timeMemory
846534lovrotEditor (BOI15_edi)C++17
100 / 100
210 ms27932 KiB
#include <cstdio> 

using namespace std; 

const int N = 3e5 + 10;
const int LOG = 19;

int n, A[N];
int UP[N][LOG];

int climb(int u, int val) {
    for(int i = LOG - 1; i >= 0; --i)
        if(A[UP[u][i]] <= val) {
            u = UP[u][i];
        }
    if(A[u] > val) return u;
    return UP[u][0];
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", A + i); 
        if(A[i] < 0) {
            UP[i][0] = climb(climb(i - 1, A[i]) - 1, A[i]);
            for(int j = 1; j < LOG; ++j) UP[i][j] = UP[UP[i][j - 1]][j - 1]; 
        }   
        printf("%d\n", A[climb(i, -1)]);
    }   
    return 0;
}

Compilation message (stderr)

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