QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227902 | #7616. Jump Graph | wullaaa | WA | 0ms | 26380kb | C++14 | 948b | 2023-10-28 08:46:52 | 2023-10-28 08:46:53 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N=3e5+5;
int n,a[N],stk[N],top;
int f1[N],f2[N],sz1[N],sz2[N];
vector<int> s1[N],s2[N];
void dfs1(int x){
sz1[x]=1;
for(auto y:s1[x]) dfs1(y),sz1[x]+=sz1[y];
}
void dfs2(int x){
sz2[x]=1;
for(auto y:s2[x]) dfs2(y),sz2[x]+=sz2[y];
}
ll val1[N],val2[N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i){
while(top&&a[i]>a[stk[top]]) --top;
if(top) f1[i]=stk[top],s1[stk[top]].pb(i);
stk[++top]=i;
}
top=0;
for(int i=n;i;--i){
while(top&&a[i]>a[stk[top]]) --top;
if(top) f2[i]=stk[top],s2[stk[top]].pb(i);
stk[++top]=i;
}
for(int i=n;i;--i) if(!f1[i]) dfs1(i);
for(int i=1;i<=n;++i) if(!f2[i]) dfs2(i);
for(int i=n;i;--i) val1[i]=sz1[i+1]+val1[i+1];
for(int i=1;i<=n;++i) val2[i]=sz2[i-1]+val2[i-1],printf("%lld ",val1[i]+val2[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24104kb
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: 24280kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 26380kb
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 '