#include<cstdio>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
ll seg[2000000];
ll a[500100], ch[500100], dap[500100];
vector<ll> vt;
ll getidx(ll x) {
return lower_bound(vt.begin(), vt.end(), x) - vt.begin();
}
ll update(ll pos, ll val, ll node, ll x, ll y)
{
if (pos < x || pos > y)return seg[node];
if (x == y)return seg[node] = val;
ll mid = (x + y) / 2;
return seg[node] = max(update(pos, val, node * 2, x, mid), update(pos, val, node * 2 + 1, mid + 1, y));
}
ll query(ll lo, ll hi, ll node, ll x, ll y)
{
if (hi < x || y < lo)return 0;
if (lo <= x&&y <= hi)return seg[node];
ll mid = (x + y) / 2;
return max(query(lo, hi, node * 2, x, mid), query(lo, hi, node * 2 + 1, mid + 1, y));
}
int main()
{
ll n;
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
vt.push_back(a[i]);
}
sort(vt.begin(), vt.end());
vt.erase(unique(vt.begin(), vt.end()), vt.end());
for (int i = 1; i <= n; i++)
a[i] = getidx(a[i]);
int t = vt.size();
for (int i = 1; i <= n; i++)
{
ch[i] = query(a[i], n - 1, 1, 0, t - 1);
update(a[i], i, 1, 0, t - 1);
}
int prev = 0;
for (int i = 2; i <= n; i++)
{
if (i - ch[i] - 1 > prev)
{
for (int y = prev + 1; y <= i - ch[i] - 1; y++)
dap[y] = i - y;
prev = i - ch[i] - 1;
}
}
for (int i = 1; i <= n; i++) {
if (dap[i])
printf("%lld ", dap[i]);
else
printf("-1 ");
}
}
Compilation message
box.cpp: In function 'int main()':
box.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
~~~~~^~~~~~~~~~~~
box.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &a[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
4 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
4 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
708 KB |
Output is correct |
12 |
Correct |
5 ms |
708 KB |
Output is correct |
13 |
Correct |
5 ms |
748 KB |
Output is correct |
14 |
Correct |
47 ms |
3312 KB |
Output is correct |
15 |
Correct |
75 ms |
5252 KB |
Output is correct |
16 |
Correct |
123 ms |
6332 KB |
Output is correct |
17 |
Correct |
392 ms |
14200 KB |
Output is correct |
18 |
Correct |
526 ms |
20876 KB |
Output is correct |
19 |
Correct |
579 ms |
24192 KB |
Output is correct |
20 |
Correct |
730 ms |
26756 KB |
Output is correct |
21 |
Correct |
738 ms |
26756 KB |
Output is correct |