#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 5e5 + 20;
int a[maxn] , par[maxn];
bool active[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
memset(active , 1 , sizeof active);
for(int i = 1; i <= n; i++)
{
cin >> a[i];
if(a[i] < 0)
{
for(int j = i - 1; j >= 0; j--)
if(active[j] && -a[j] < -a[i])
{
par[i] = j;
while(a[j] < 0)
{
active[j] ^= 1;
j = par[j];
}
active[j] ^= 1;
break;
}
}
for(int j = i; j >= 0; j--)
if(active[j] && a[j] > 0)
{
cout << a[j] << endl;
break;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
14 ms |
896 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1196 ms |
6660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3093 ms |
3260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
14 ms |
896 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |