Submission #555973

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
5559732022-05-02 04:00:12joelauRainforest Jumps (APIO21_jumps)C++14
100 / 100
1170 ms66104 KiB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n, p1[200005][20], p2[200005][20], p3[200005][20], p4[200005][20], X[200005];
stack<int> s;
void init(int N, std::vector<int> H) {
n = N;
for (int i = 0; i < N; ++i) X[i] = H[i];
memset(p1,-1,sizeof(p1));
memset(p2,-1,sizeof(p2));
memset(p3,-1,sizeof(p3));
memset(p4,-1,sizeof(p4));
for (int i = 0; i < N; ++i) {
while (!s.empty() && H[i] >= H[s.top()]) s.pop();
if (!s.empty()) p1[i][0] = p3[i][0] = s.top();
s.push(i);
}
while (!s.empty()) s.pop();
for (int i = N-1; i >= 0; --i) {
while (!s.empty() && H[i] >= H[s.top()]) s.pop();
if (!s.empty()) p2[i][0] = p4[i][0] = s.top();
s.push(i);
}
for (int i = 0; i < N; ++i) if (p1[i][0] == -1 || (p1[i][0] != -1 && p2[i][0] != -1 && H[p1[i][0]] < H[p2[i][0]])) swap(p1[i][0], p2[i][0]);
for (int k = 1; k < 20; ++k) for (int i = 0; i < N; ++i) {
if (p1[i][k-1] == -1) p1[i][k] = -1;
else p1[i][k] = p1[p1[i][k-1]][k-1];
if (p2[i][k-1] == -1) p2[i][k] = -1;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...