QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404736 | #7616. Jump Graph | ucup-team3396# | WA | 3ms | 171564kb | C++14 | 1.3kb | 2024-05-04 16:06:28 | 2024-05-04 16:06:30 |
Judging History
answer
#pragma GCC optimize(2,3,"Ofast","inline")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define lowbit(i) (i&(-i))
#define mid ((l+r)>>1)
using namespace std;
int a[1000005];
int stk[1000005],top;
int tol[20][1000005],tor[20][1000005];
int tagl[20][1000005],tagr[20][1000005];
int pre[1000005];
signed main(){
int n; cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
{
top=0;
for(int i=1;i<=n;i++){
while(top&&a[stk[top]]<a[i]) top--;
if(top) tol[0][i]=stk[top];
else tol[0][i]=1;
stk[++top]=i;
}
}
{
top=0;
for(int i=n;i>=1;i--){
while(top&&a[stk[top]]<a[i]) top--;
if(top) tor[0][i]=stk[top];
else tor[0][i]=n;
stk[++top]=i;
}
}
for(int j=1;j<=19;j++) for(int i=1;i<=n;i++) tor[j][i]=tor[j-1][tor[j-1][i]],tol[j][i]=tol[j-1][tol[j-1][i]];
for(int i=1;i<=n;i++) tagl[19][i]=tagr[19][i]=1;
for(int j=19;j>=1;j--) for(int i=1;i<=n;i++) tagl[j-1][i]+=tagl[j][i],tagl[j-1][tol[j-1][i]]+=tagl[j][i];
for(int j=19;j>=1;j--) for(int i=1;i<=n;i++) tagr[j-1][i]+=tagr[j][i],tagr[j-1][tor[j-1][i]]+=tagr[j][i];
for(int i=1;i<=n;i++) pre[i]+=tagl[0][i],pre[i+1]-=tagr[0][i];
for(int i=1;i<=n;i++) pre[i]+=pre[i-1];
for(int i=1;i<=n;i++){
cout<<((1ll<<19))*n-pre[i]<<" ";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 171564kb
input:
6 1 6 3 2 5 4
output:
11 7 7 7 6 8
result:
ok single line: '11 7 7 7 6 8 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 171448kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 171484kb
input:
36 9 29 1 3 14 31 24 21 10 18 22 16 8 7 15 12 17 19 25 28 27 34 11 6 32 4 20 13 2 35 23 26 33 36 30 5
output:
101 98 99 99 100 87 81 79 79 79 73 72 71 71 70 72 72 77 83 94 107 100 120 120 116 118 116 116 116 113 142 142 143 143 175 175
result:
wrong answer 1st lines differ - expected: '92 89 90 90 91 78 73 71 71 71 ...110 107 136 136 137 136 168 168', found: '101 98 99 99 100 87 81 79 79 7...16 113 142 142 143 143 175 175 '