QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242225#7616. Jump GraphUNos_mariconesWA 4ms41040kbC++201.6kb2023-11-07 01:58:592023-11-07 01:58:59

Judging History

你现在查看的是最新测评结果

  • [2023-11-07 01:58:59]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:41040kb
  • [2023-11-07 01:58:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ff   first
#define ss   second
#define pb   push_back

typedef long long  ll;
typedef pair<ll,ll>  pii;

const ll N = 3e5 + 10;
const ll mod = 1e9 + 7;

ll st[8 * N], lazy[8 * N];

void propagate (ll node, ll l, ll r) {
  st[node] += lazy[node] * (r - l + 1);
  lazy[node << 1] += lazy[node];
  lazy[(node << 1) + 1] += lazy[node];
  lazy[node] = 0;
}

void update (ll node, ll l, ll r, ll a, ll b) {
  propagate(node, l, r);
  if (b < l || r < a) return;
  if (a <= l && r <= b) {
    lazy[node] = 1;
    propagate(node, l, r);
    return;
  }
  ll m = (l + r) >> 1;
  update (node << 1, l, m, a, b);
  update ((node << 1) + 1, m + 1, r, a, b);
  st[node] = st[node << 1] + st[(node << 1) + 1];
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifdef LOCAL
  freopen("input.txt","r",stdin);
  #endif // LOCAL

  ll n; cin >> n;
  vector <ll> p(n);
  for (auto &e : p) cin >> e;

  vector <pii> nx = {{n + 1, n}};
  vector <ll> ans(n);

  for (ll i = n - 1; i; --i) {
    while (nx.back().ff < p[i]) nx.pop_back();
    update (1, 0, n - 1, i, nx.back().ss - 1);
//    cout << "upd " << i << ' ' << nx.back().ss << '\n';
    ans[i - 1] += st[1];
    nx.push_back( {p[i], i} );
  }

  nx = {{n + 1, -1}};
  memset(lazy, 0, sizeof lazy);
  memset(st, 0, sizeof st);

  for (ll i = 0; i + 1 < n; ++i) {
    while (nx.back().ff < p[i]) nx.pop_back();
    update (1, 0, n - 1, nx.back().ss + 1, i);
    ans[i + 1] += st[1];
    nx.push_back ( {p[i], i} );
  }

  for (ll i = 0; i < n; ++i) cout << ans[i] << ' ';
  cout << '\n';

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 40980kb

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: 4ms
memory: 41040kb

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 41040kb

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 '