QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576515 | #7939. High Towers | HuTao | TL | 1ms | 9940kb | C++14 | 1.4kb | 2024-09-19 20:45:47 | 2024-09-19 20:45:48 |
Judging History
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(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()
{
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: 100
Accepted
time: 1ms
memory: 9940kb
input:
6 3 3 4 2 5 1
output:
3 4 5 1 6 2
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
4 3 3 3 3
output:
4 3 2 1
result:
ok
Test #3:
score: -100
Time Limit Exceeded
input:
264668 5 5 5 5 9 5 5 5 7 3 5 3 11 9 9 9 8 9 8 9 12 4 4 9 5 5 6 4 12 4 7 5 6 5 18 12 6 12 11 11 11 11 11 11 12 19 5 5 8 6 6 6 26 7 7 7 8 6 7 6 6 12 10 6 9 8 8 8 10 4 22 4 4 6 3 6 4 4 8 5 5 5 7 3 8 6 6 6 6 8 3 5 3 6 4 4 8 5 5 5 10 6 6 6 6 17 4 12 5 11 6 10 7 9 8 8 16 5 5 5 8 4 4 12 8 7 7 8 6 9 4 14 5 ...