54312023-05-25 18:44:15111Barátokcpp14Accepted 100/100344ms58176 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
	int N;
	cin >> N;
	vector<int> v(N + 1);
	vector<vector<int>> u(N + 1);
	vector<vector<int>> w(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		u[max(1, i - v[i])].push_back(i);
		w[min(N, i)].push_back(i);
	}
	ordered_set<int> s;
	long long x = 0;
	for (int i = 1; i <= N; i++) {
		for (int j : u[i]) {
			s.insert(j);
		}
		x += s.order_of_key(min(N + 1, i + v[i] + 1)) - s.order_of_key(max(1, i - v[i])) - 1;
		for (int j : w[i]) {
			s.erase(j);
		}
	}
	cout << x << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1872 KiB
2Accepted189ms31456 KiB
subtask211/11
3Accepted189ms31456 KiB
4Accepted3ms2336 KiB
5Accepted7ms3472 KiB
6Accepted7ms3724 KiB
7Accepted7ms3996 KiB
8Accepted7ms4004 KiB
9Accepted7ms4340 KiB
10Accepted4ms4072 KiB
11Accepted7ms4216 KiB
subtask312/12
12Accepted7ms4216 KiB
13Accepted164ms43812 KiB
14Accepted151ms44016 KiB
15Accepted162ms43960 KiB
16Accepted97ms47396 KiB
17Accepted158ms44328 KiB
18Accepted87ms48844 KiB
19Accepted142ms46088 KiB
subtask431/31
20Accepted142ms46088 KiB
21Accepted137ms44408 KiB
22Accepted149ms44456 KiB
23Accepted90ms48472 KiB
24Accepted136ms45328 KiB
25Accepted344ms51564 KiB
26Accepted333ms48256 KiB
27Accepted317ms54488 KiB
28Accepted275ms45888 KiB
29Accepted293ms56692 KiB
subtask546/46
30Accepted293ms56692 KiB
31Accepted174ms45116 KiB
32Accepted211ms45700 KiB
33Accepted263ms46296 KiB
34Accepted123ms48372 KiB
35Accepted256ms47880 KiB
36Accepted104ms49836 KiB
37Accepted277ms57980 KiB
38Accepted289ms58176 KiB
39Accepted337ms52832 KiB
40Accepted105ms50256 KiB
41Accepted324ms52484 KiB
42Accepted282ms46468 KiB
43Accepted293ms47652 KiB
44Accepted310ms55444 KiB
45Accepted310ms49280 KiB