QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224473 | #7616. Jump Graph | ucup-team987# | WA | 0ms | 3872kb | C++20 | 786b | 2023-10-23 02:57:47 | 2023-10-23 02:57:48 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
vector<long long>solve(const vector<int>&P)
{
const int N=P.size();
vector<long long>ret(N+1,0LL);
vector<int>pos;
for(int i=N;i--;)
{
while(!pos.empty()&&P[pos.back()]<P[i])
{
ret[pos.back()+1]-=i+1;
pos.pop_back();
}
pos.push_back(i);
ret[i+1]+=i+1;
}
for(int i=0;i<N;i++)ret[i+1]+=ret[i];
ret.pop_back();
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<int>P(N);
for(int i=0;i<N;i++)cin>>P[i];
vector<long long>R=solve(P);
reverse(P.begin(),P.end());
vector<long long>L=solve(P);
reverse(L.begin(),L.end());
for(int i=0;i<N;i++)cout<<L[i]+R[i]<<(i+1==N?"\n":" ");
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
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: 3872kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3648kb
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...116 113 142 142 143 143 175 175'