QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#464179 | #7616. Jump Graph | kia | WA | 0ms | 32332kb | C++17 | 2.9kb | 2024-07-05 21:21:19 | 2024-07-05 21:21:19 |
Judging History
answer
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 19;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int t, n, q[N], p[N], mx[lg][N], ch[2][N];
ll ans[N], now, dp[3][N], subt[N];
int get(int l, int r) {
int maxi = l;
for(int i=lg-1; i>=0; i--) {
if(l+(1<<i)-1 <= r) {
maxi = (p[maxi]<p[mx[i][l]] ? mx[i][l] : maxi);
l += (1<<i);
}
}
return maxi;
}
int divide(int l, int r) {
if(r<l) return 0;
int mid = get(l, r);
int lft=divide(l, mid-1), rgt=divide(mid+1, r);
ch[0][mid] = lft, ch[1][mid] = rgt;
subt[mid]++; subt[mid]+=subt[lft]; subt[mid]+=subt[rgt];
// cout<<mid<<" => "<<lft<<' '<<rgt<<endl;
return mid;
}
void dfs(int v) {
if(v == 0) return;
dfs(ch[0][v]); dfs(ch[1][v]);
dp[0][v] += (dp[2][ch[0][v]]);
dp[0][v] += (dp[1][ch[1][v]]);
dp[1][v] = 1ll + subt[ch[1][v]] + dp[1][ch[0][v]] + dp[1][ch[1][v]];
dp[2][v] = 1ll + subt[ch[0][v]] + dp[2][ch[0][v]] + dp[2][ch[1][v]];
// cout<<v<<" =====> "<<dp[0][v]<<endl;
}
void dfs2(int v) {
if(v == 0) return;
ans[v] = now + (n - subt[v]) + dp[0][v];
now += dp[1][ch[1][v]];
dfs2(ch[0][v]);
now -= dp[1][ch[1][v]];
now += dp[2][ch[0][v]];
dfs2(ch[1][v]);
now -= dp[2][ch[0][v]];
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>p[i], mx[0][i]=i, q[p[i]]=i;
for(int i=n; i>=1; i--) {
for(int j=1; j<lg; j++) {
int x=mx[j-1][i], y=mx[j-1][min(n,i+(1<<(j-1)))];
mx[j][i] = (p[x]>p[y] ? x : y);
}
}
divide(1, n);
dfs(q[n]);
dfs2(q[n]);
for(int i=1; i<=n; i++) cout<<ans[i]<<' ';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 32332kb
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: 32312kb
input:
2 1 2
output:
1 1
result:
ok single line: '1 1 '
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 32244kb
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 '