QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225122 | #7616. Jump Graph | ucup-team133 | WA | 1ms | 3552kb | C++17 | 4.2kb | 2023-10-24 00:11:48 | 2023-10-24 00:11:49 |
Judging History
answer
//#define _GLIBCXX_DEBUG
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i+=1)
#define append push_back
#define all(x) (x).begin(), (x).end()
template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<class T>
bool chmin(T &a, T b){
if (a>b){
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b){
if (a<b){
a = b;
return true;
}
return false;
}
template<class T>
T sum(vec<T> x){
T res=0;
for (auto e:x){
res += e;
}
return res;
}
template<class T>
void printv(vec<T> x){
for (auto e:x){
cout<<e<<" ";
}
cout<<"\n";
}
template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
os << "{";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ", ";
}
}
os << "}" ;
return os;
}
template<class T>
ostream& operator<<(ostream& os, const deque<T>& A){
os << "deque{[";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ", ";
}
}
os << "]}" ;
return os;
}
template<class T>
ostream& operator<<(ostream& os, const pair<T,T>& A){
os << "(";
os << A.first ;
os << ", ";
os << A.second;
os << ")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const tuple<T,T,T>& A){
auto [a,b,c] = A;
os << "(";
os << a;
os << ",";
os << b;
os << ",";
os << c;
os << ")";
return os;
}
void solve(){
int N;
cin>>N;
vec<int> P(N),pos(N);
rep(i,N){
cin>>P[i];
P[i]--;
pos[P[i]] = i;
}
vec<int> left(N,0),right(N,N-1);
vec<int> left_st;
rep(i,N){
while (!left_st.empty()){
int idx = left_st.back();
if (P[idx] < P[i]){
left_st.pop_back();
}
else{
break;
}
}
if (!left_st.empty()){
left[i] = left_st.back();
}
left_st.push_back(i);
}
vec<int> right_st;
for (int i=N-1;0<=i;i--){
while (!right_st.empty()){
int idx = right_st.back();
if (P[idx] < P[i]){
right_st.pop_back();
}
else{
break;
}
}
if (!right_st.empty()){
right[i] = right_st.back();
}
right_st.push_back(i);
}
vec<ll> imos(N+1,0);
vec<ll> propagate_add(N,1);
rep(val,N){
int idx = pos[val];
int L = left[idx],R = right[idx];
imos[L] -= propagate_add[idx];
imos[R+1] += propagate_add[idx];
imos[idx] -= 1;
imos[idx+1] += 1;
if (L == 0){
if (R == N-1) continue;
propagate_add[R] += propagate_add[idx];
}
else{
if (R == N-1){
propagate_add[L] += propagate_add[idx];
}
else{
if (P[L] < P[R]){
propagate_add[R] += propagate_add[idx];
}
else{
propagate_add[L] += propagate_add[idx];
}
}
}
}
vec<ll> maximum_dist(N,1);
for (int val=N-1;0<=val;val--){
int idx = pos[val];
int L = left[idx],R = right[idx];
if (L == 0){
if (R == N-1) continue;
maximum_dist[idx] = 1 + maximum_dist[R];
}
else{
if (R == N-1){
maximum_dist[idx] = 1 + maximum_dist[L];
}
else{
if (P[L] < P[R]){
maximum_dist[idx] = 1 + maximum_dist[R];
}
else{
maximum_dist[idx] = 1 + maximum_dist[L];
}
}
}
}
rep(val,N){
imos[0] += maximum_dist[val] + 1;
}
rep(i,N){
imos[i+1] += imos[i];
cout << imos[i] << " ";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
T = 1;
while (T--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3476kb
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: 3436kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 3424kb
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:
92 89 90 90 91 78 73 71 71 71 65 65 64 64 63 65 65 70 74 85 95 91 111 111 109 111 110 110 110 107 136 136 137 136 168 168
result:
ok single line: '92 89 90 90 91 78 73 71 71 71 ...10 107 136 136 137 136 168 168 '
Test #4:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
63 30 17 34 8 29 57 2 62 35 27 24 22 54 53 60 37 31 19 1 5 20 14 3 36 38 40 56 39 50 32 51 9 15 52 55 45 63 41 6 47 23 7 33 10 26 61 16 58 43 42 44 48 28 12 49 11 59 4 21 25 46 13 18
output:
204 204 202 204 204 204 209 191 197 196 195 195 194 198 179 176 172 170 170 170 170 172 172 172 179 188 186 187 186 187 185 187 187 188 191 193 167 202 202 198 199 199 197 199 199 183 190 183 183 183 183 184 185 185 184 187 181 190 190 191 190 191 191
result:
ok single line: '204 204 202 204 204 204 209 19...87 181 190 190 191 190 191 191 '
Test #5:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
110 70 59 102 66 81 43 31 26 52 23 88 49 9 7 76 108 25 101 89 73 4 22 77 94 64 24 16 58 47 30 28 45 68 15 84 36 21 78 56 46 32 62 65 55 61 20 74 2 83 33 105 110 50 60 85 42 96 98 6 10 41 51 97 8 72 86 69 93 82 67 100 57 75 1 106 11 40 35 17 39 18 14 34 53 92 12 54 3 95 103 99 80 5 27 37 29 63 13 90 ...
output:
386 386 377 379 375 375 374 374 373 376 372 377 376 376 376 344 359 344 341 339 339 339 340 323 325 324 324 322 321 320 320 320 321 329 315 322 322 313 314 313 313 313 314 317 316 317 316 320 319 331 331 306 357 357 357 358 358 352 354 354 355 356 352 353 353 353 354 353 354 354 352 365 364 365 350 ...
result:
ok single line: '386 386 377 379 375 375 374 37...87 387 386 386 385 389 388 407 '
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3432kb
input:
192 186 25 95 115 187 44 154 54 80 121 89 117 68 74 27 137 171 112 22 60 6 109 97 14 101 166 82 126 15 69 92 51 174 162 65 156 132 150 56 138 20 93 85 103 164 26 77 124 170 34 185 188 116 98 120 123 148 16 100 49 53 88 179 102 94 169 96 37 140 48 146 40 125 141 45 129 11 19 175 43 144 184 5 10 7 2 8...
output:
697 697 697 698 654 658 649 650 650 648 649 647 648 647 648 648 644 649 649 648 649 646 647 647 647 645 653 650 651 651 651 652 636 654 654 651 652 648 649 645 646 645 646 646 645 656 656 657 657 670 670 663 713 713 713 715 713 714 711 712 712 713 697 702 702 695 696 696 695 697 693 696 696 694 695 ...
result:
wrong answer 1st lines differ - expected: '693 693 693 694 649 653 644 64...834 840 839 838 836 836 836 837', found: '697 697 697 698 654 658 649 65...39 845 841 839 837 837 837 838 '