Submission #650402

# Submission time Handle Problem Language Result Execution time Memory
650402 2022-10-13T16:44:21 Z depro Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 69772 KB
#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, q; cin >> n >> q;

	vector<pair<int, int>>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a.begin(), a.end());

	vector<pair<int, int>>queries(q);
	for (int i = 0; i < q; i++) {
		cin >> queries[i].first;
		queries[i].second = i;
	}

	set<int> s({-1, n});
	sort(queries.rbegin(), queries.rend());

	auto cal = [&](int l, int r) {
		return 1LL * (r - l + 1) * (r - l + 2) / 2;
	};

	vector<long long>ans(q);
	int cur = n - 1;
	long long cnt = 1LL * n * (n + 1) / 2;

	for (auto [val, id] : queries) {
		while(cur >= 0 && a[cur].first > val) {
			auto it = s.lower_bound(a[cur].second);
			int r = *it; r--;
			int l = *(--it); l++;
			cnt -= cal(l, r);
			cnt += cal(l, a[cur].second - 1);
			cnt += cal(a[cur].second + 1, r);

			s.insert(a[cur].second);
			cur--;
		}

		ans[id] = cnt;
	}

	for (long long x : ans) cout << x << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1620 KB Output is correct
2 Correct 24 ms 1724 KB Output is correct
3 Correct 18 ms 1560 KB Output is correct
4 Correct 16 ms 1620 KB Output is correct
5 Correct 23 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 8892 KB Output is correct
2 Correct 70 ms 9044 KB Output is correct
3 Correct 65 ms 8908 KB Output is correct
4 Correct 67 ms 9164 KB Output is correct
5 Correct 75 ms 8816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 9124 KB Output is correct
2 Correct 77 ms 9048 KB Output is correct
3 Correct 72 ms 8948 KB Output is correct
4 Correct 70 ms 9420 KB Output is correct
5 Correct 65 ms 9288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 20 ms 1620 KB Output is correct
12 Correct 24 ms 1724 KB Output is correct
13 Correct 18 ms 1560 KB Output is correct
14 Correct 16 ms 1620 KB Output is correct
15 Correct 23 ms 1492 KB Output is correct
16 Correct 29 ms 2832 KB Output is correct
17 Correct 43 ms 4696 KB Output is correct
18 Correct 56 ms 5844 KB Output is correct
19 Correct 49 ms 5332 KB Output is correct
20 Correct 32 ms 3900 KB Output is correct
21 Correct 22 ms 1480 KB Output is correct
22 Correct 32 ms 3700 KB Output is correct
23 Correct 54 ms 4988 KB Output is correct
24 Correct 52 ms 5056 KB Output is correct
25 Correct 33 ms 3748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 20 ms 1620 KB Output is correct
27 Correct 24 ms 1724 KB Output is correct
28 Correct 18 ms 1560 KB Output is correct
29 Correct 16 ms 1620 KB Output is correct
30 Correct 23 ms 1492 KB Output is correct
31 Correct 69 ms 8892 KB Output is correct
32 Correct 70 ms 9044 KB Output is correct
33 Correct 65 ms 8908 KB Output is correct
34 Correct 67 ms 9164 KB Output is correct
35 Correct 75 ms 8816 KB Output is correct
36 Correct 69 ms 9124 KB Output is correct
37 Correct 77 ms 9048 KB Output is correct
38 Correct 72 ms 8948 KB Output is correct
39 Correct 70 ms 9420 KB Output is correct
40 Correct 65 ms 9288 KB Output is correct
41 Correct 29 ms 2832 KB Output is correct
42 Correct 43 ms 4696 KB Output is correct
43 Correct 56 ms 5844 KB Output is correct
44 Correct 49 ms 5332 KB Output is correct
45 Correct 32 ms 3900 KB Output is correct
46 Correct 22 ms 1480 KB Output is correct
47 Correct 32 ms 3700 KB Output is correct
48 Correct 54 ms 4988 KB Output is correct
49 Correct 52 ms 5056 KB Output is correct
50 Correct 33 ms 3748 KB Output is correct
51 Correct 85 ms 8996 KB Output is correct
52 Correct 87 ms 8920 KB Output is correct
53 Correct 84 ms 9116 KB Output is correct
54 Correct 81 ms 8888 KB Output is correct
55 Correct 87 ms 9020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 20 ms 1620 KB Output is correct
27 Correct 24 ms 1724 KB Output is correct
28 Correct 18 ms 1560 KB Output is correct
29 Correct 16 ms 1620 KB Output is correct
30 Correct 23 ms 1492 KB Output is correct
31 Correct 69 ms 8892 KB Output is correct
32 Correct 70 ms 9044 KB Output is correct
33 Correct 65 ms 8908 KB Output is correct
34 Correct 67 ms 9164 KB Output is correct
35 Correct 75 ms 8816 KB Output is correct
36 Correct 69 ms 9124 KB Output is correct
37 Correct 77 ms 9048 KB Output is correct
38 Correct 72 ms 8948 KB Output is correct
39 Correct 70 ms 9420 KB Output is correct
40 Correct 65 ms 9288 KB Output is correct
41 Correct 29 ms 2832 KB Output is correct
42 Correct 43 ms 4696 KB Output is correct
43 Correct 56 ms 5844 KB Output is correct
44 Correct 49 ms 5332 KB Output is correct
45 Correct 32 ms 3900 KB Output is correct
46 Correct 22 ms 1480 KB Output is correct
47 Correct 32 ms 3700 KB Output is correct
48 Correct 54 ms 4988 KB Output is correct
49 Correct 52 ms 5056 KB Output is correct
50 Correct 33 ms 3748 KB Output is correct
51 Correct 85 ms 8996 KB Output is correct
52 Correct 87 ms 8920 KB Output is correct
53 Correct 84 ms 9116 KB Output is correct
54 Correct 81 ms 8888 KB Output is correct
55 Correct 87 ms 9020 KB Output is correct
56 Execution timed out 1065 ms 69772 KB Time limit exceeded
57 Halted 0 ms 0 KB -