QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576621 | #7939. High Towers | HuTao | RE | 0ms | 0kb | C++14 | 1.5kb | 2024-09-19 21:19:09 | 2024-09-19 21:19:09 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, a[N];
int sta[N], tt;
int ne[N];
int nxt[N], st[N];
int res[N];
inline void Init()
{
for(int i = n; i >= 1; i -- )
{
while(tt && a[sta[tt]] <= a[i]) tt -- ;
ne[i] = tt ? sta[tt] : n + 1;
sta[ ++ tt] = i;
}
}
inline void Work(int L, int R, int D, int &ID)
{
if(L > R) return ;
int c = ne[L];
if(c > R)
{
Work(L + 1, R, D + 1, ID);
res[L] = ++ ID;
return ;
}
int t = c;
while(t > L && a[t - 1] == a[L]) t -- ;
nxt[L] = t;
for(int i = t; i < c; i ++ ) nxt[i] = i + 1;
Work(L + 1, t - 1, a[L] - (t - L - 1), ID);
int l = c - L + 1, s = a[L] - D - l;
// printf("#%d %d %d %d %d\n", L, R, c, l, s);
// exit(0);
while(c <= R)
{
int d = a[c] - D - s + 1 - l + c;
// printf("*%d %d %d %d %d\n", c, d, s, l, a[c]);
if(d > R) break;
if(d == c + 1 || a[d - 1] - D <= s + d - c)
{
Work(c + 1, d - 1, a[c] - (d - c - 1), ID);
nxt[c] = d;
s -- , l = d - L + 1, c = d;
}
else
{
Work(c + 1, d - 2, a[c] - (d - c - 2), ID);
nxt[c] = d - 1, st[d - 1] = 1;
l = d - c, c = d - 1;
}
}
Work(c + 1, R, a[c] - (R - c), ID);
for(int i = L; i; i = nxt[i]) res[i] = ID += !st[i];
}
int main()
{
freopen("data", "r", stdin);
freopen("std", "w", stdout);
scanf("%d", &n);
for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i]), a[i] ++ ;
int id = 0;
Init(), Work(1, n, 0, id);
for(int i = 1; i <= n; i ++ ) printf("%d ", res[i]);
puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
6 3 3 4 2 5 1