# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127263 | Kerim | Editor (BOI15_edi) | C++20 | 3070 ms | 8320 KiB |
// O(n^2)
#include <cstdio>
#include <vector>
using namespace std;
struct op {
int poz;
int wsk;
bool aktyw;
op(int edy) {
if (edy < 0)
poz = -edy;
else
wsk = edy, poz = 0;
aktyw = false;
}
};
vector<op> oper;
void dezaktywuj(int x) {
int i = 0;
while (1){
if (i)
oper[x].aktyw = true;
else
oper[x].aktyw = false;
if (oper[x].poz > 0)
x = oper[x].wsk;
else
break;
i ^= 1;
}
}
void aktywuj(int x) {
oper[x].aktyw = true;
if (oper[x].poz > 0) {//undo
int i = x - 1;
while (oper[i].poz >= oper[x].poz || !oper[i].aktyw)
--i;
oper[x].wsk = i;
dezaktywuj(i);
}
}
int wynik() {
for (int i = oper.size() - 1; i >= 0; --i)
if (oper[i].poz == 0 && oper[i].aktyw)
return oper[i].wsk;
return 0;
}
int n;
int main() {
// freopen("file.in", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int edy;
scanf("%d", &edy);
oper.push_back(op(edy));
aktywuj(i);
printf("%d\n", wynik());
}
}
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... |