5410 2023. 05. 13 11:34:21 TomaSajt Barátok cpp17 Accepted 100/100 263ms 26448 KiB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template <class T>
using itree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct person {
  int pos, range;
};

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<person> people(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    people[i] = {i, a};
  }
  sort(people.begin(), people.end(),
       [](person a, person b) { return a.range > b.range; });
  itree<int> positions;
  ll cnt = 0;
  for (person &p : people) {
    cnt += positions.order_of_key(p.pos + p.range + 1) -
           positions.order_of_key(p.pos - p.range);
    positions.insert(p.pos);
  }
  cout << cnt;
  return 0;
}
Subtask Sum Test Verdict Time Memory
subtask1 0/0
1 Accepted 3ms 1828 KiB
2 Accepted 134ms 15452 KiB
subtask2 11/11
3 Accepted 134ms 15452 KiB
4 Accepted 3ms 2140 KiB
5 Accepted 6ms 2880 KiB
6 Accepted 6ms 3216 KiB
7 Accepted 6ms 3432 KiB
8 Accepted 6ms 3384 KiB
9 Accepted 4ms 3388 KiB
10 Accepted 4ms 3388 KiB
11 Accepted 4ms 3724 KiB
subtask3 12/12
12 Accepted 4ms 3724 KiB
13 Accepted 250ms 24936 KiB
14 Accepted 229ms 25112 KiB
15 Accepted 241ms 25320 KiB
16 Accepted 136ms 25532 KiB
17 Accepted 216ms 25944 KiB
18 Accepted 128ms 25692 KiB
19 Accepted 152ms 25820 KiB
subtask4 31/31
20 Accepted 152ms 25820 KiB
21 Accepted 204ms 25536 KiB
22 Accepted 219ms 25692 KiB
23 Accepted 129ms 25848 KiB
24 Accepted 167ms 26120 KiB
25 Accepted 219ms 25896 KiB
26 Accepted 234ms 25896 KiB
27 Accepted 190ms 26024 KiB
28 Accepted 252ms 25956 KiB
29 Accepted 171ms 25956 KiB
subtask5 46/46
30 Accepted 171ms 25956 KiB
31 Accepted 254ms 25960 KiB
32 Accepted 257ms 26216 KiB
33 Accepted 263ms 26168 KiB
34 Accepted 143ms 26176 KiB
35 Accepted 250ms 26180 KiB
36 Accepted 130ms 26304 KiB
37 Accepted 166ms 26296 KiB
38 Accepted 170ms 26304 KiB
39 Accepted 231ms 26448 KiB
40 Accepted 129ms 26432 KiB
41 Accepted 218ms 26404 KiB
42 Accepted 252ms 26408 KiB
43 Accepted 246ms 26312 KiB
44 Accepted 188ms 26312 KiB
45 Accepted 250ms 26312 KiB