54102023-05-13 11:34:21TomaSajtBarátokcpp17Accepted 100/100263ms26448 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted134ms15452 KiB
subtask211/11
3Accepted134ms15452 KiB
4Accepted3ms2140 KiB
5Accepted6ms2880 KiB
6Accepted6ms3216 KiB
7Accepted6ms3432 KiB
8Accepted6ms3384 KiB
9Accepted4ms3388 KiB
10Accepted4ms3388 KiB
11Accepted4ms3724 KiB
subtask312/12
12Accepted4ms3724 KiB
13Accepted250ms24936 KiB
14Accepted229ms25112 KiB
15Accepted241ms25320 KiB
16Accepted136ms25532 KiB
17Accepted216ms25944 KiB
18Accepted128ms25692 KiB
19Accepted152ms25820 KiB
subtask431/31
20Accepted152ms25820 KiB
21Accepted204ms25536 KiB
22Accepted219ms25692 KiB
23Accepted129ms25848 KiB
24Accepted167ms26120 KiB
25Accepted219ms25896 KiB
26Accepted234ms25896 KiB
27Accepted190ms26024 KiB
28Accepted252ms25956 KiB
29Accepted171ms25956 KiB
subtask546/46
30Accepted171ms25956 KiB
31Accepted254ms25960 KiB
32Accepted257ms26216 KiB
33Accepted263ms26168 KiB
34Accepted143ms26176 KiB
35Accepted250ms26180 KiB
36Accepted130ms26304 KiB
37Accepted166ms26296 KiB
38Accepted170ms26304 KiB
39Accepted231ms26448 KiB
40Accepted129ms26432 KiB
41Accepted218ms26404 KiB
42Accepted252ms26408 KiB
43Accepted246ms26312 KiB
44Accepted188ms26312 KiB
45Accepted250ms26312 KiB