답안 #650336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650336 2022-10-13T13:53:11 Z 600Mihnea Fire (JOI20_ho_t5) C++17
1 / 100
1000 ms 12032 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Op {
	int limit;
	int k;
	int id;
};

int main() {
#ifndef ONPC
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
	
	int n, q;
	cin >> n >> q;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	// l, r, t
	vector<ll> prn(2 * q, 0);
	vector<Op> ops;
	for (int i = 0; i < q; i++) {
		int l, r, t;
		cin >> t >> l >> r;
		l--, r--;
		ops.push_back({l - 1, t, i});
		ops.push_back({r, t, i + q});
	}
	// next bigger
	vector<int> nxt(n, n), ant(n, -1);
	{
		vector<int> stk;
		for (int i = n - 1; i >= 0; i--) {
			while (!stk.empty() && a[stk.back()] <= a[i]) {
				stk.pop_back();
			}
			if (!stk.empty()) {
				nxt[i] = stk.back();
			}
			stk.push_back(i);
		}	
	}
	{
		vector<int> stk;
		for (int i = 0; i < n; i++) {
			while (!stk.empty() && a[stk.back()] < a[i]) {
				stk.pop_back();
			}
			if (!stk.empty()) {
				ant[i] = stk.back();
			}
			stk.push_back(i);
		}	
	}
	for (auto &it : ops) {
		int limit = it.limit;
		if (limit < 0) {
			//cout << "skip\n";
			continue;
		}
		int k = it.k;
		int id = it.id;
		ll sol = 0;
		for (int i = 0; i <= limit; i++) {
			for (int rgh = 0; rgh <= limit; rgh++) {
				int lft = max(0, rgh - k);
				// is i the maximum in the interval [lft, rgh]?
				if (ant[i] < lft && lft <= i && i <= rgh && rgh < nxt[i]) {
					sol += a[i];
				}
			}
			// whenever this comes I make an assumption and later a correction
		}
		prn[id] = sol;
	}
	for (int i = 0; i < q; i++) {
		cout << prn[i + q] - prn[i] << "\n";
	}
	cout << "\n";

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 10 ms 340 KB Output is correct
8 Correct 10 ms 340 KB Output is correct
9 Correct 8 ms 468 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 7 ms 212 KB Output is correct
12 Correct 7 ms 320 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 6 ms 340 KB Output is correct
15 Correct 6 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 6 ms 320 KB Output is correct
22 Correct 7 ms 340 KB Output is correct
23 Correct 9 ms 320 KB Output is correct
24 Correct 8 ms 340 KB Output is correct
25 Correct 7 ms 340 KB Output is correct
26 Correct 8 ms 340 KB Output is correct
27 Correct 8 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 8 ms 340 KB Output is correct
30 Correct 8 ms 336 KB Output is correct
31 Correct 9 ms 336 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1083 ms 11344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1090 ms 11592 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 12032 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 10 ms 340 KB Output is correct
8 Correct 10 ms 340 KB Output is correct
9 Correct 8 ms 468 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 7 ms 212 KB Output is correct
12 Correct 7 ms 320 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 6 ms 340 KB Output is correct
15 Correct 6 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 6 ms 320 KB Output is correct
22 Correct 7 ms 340 KB Output is correct
23 Correct 9 ms 320 KB Output is correct
24 Correct 8 ms 340 KB Output is correct
25 Correct 7 ms 340 KB Output is correct
26 Correct 8 ms 340 KB Output is correct
27 Correct 8 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 8 ms 340 KB Output is correct
30 Correct 8 ms 336 KB Output is correct
31 Correct 9 ms 336 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Execution timed out 1083 ms 11344 KB Time limit exceeded
34 Halted 0 ms 0 KB -