Submission #789725

# Submission time Handle Problem Language Result Execution time Memory
789725 2023-07-21T20:51:39 Z IBory 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 25192 KB
#include <bits/stdc++.h>
#define pii pair<ll, ll>
typedef long long ll;
using namespace std;

const int MAX = 123456, SQ = 8;
ll X[MAX], ans[MAX], cnt[MAX], S[MAX];
priority_queue<ll> PQ[MAX >> 8], E[MAX >> 8];

struct Query {
	int s, e, id;
	Query(int a = 0, int b = 0, int c = 0) {
		s = a, e = b, id = c;
	}
	const bool operator<(Query& a) {
		if ((s >> SQ) != (a.s >> SQ)) return (s >> SQ) < (a.s >> SQ);
		return e > a.e;
	}
} QS[MAX];

void Add(int idx) {
	int n = S[idx];
	priority_queue<ll>& C = PQ[n >> SQ];
	priority_queue<ll>& EPQ = E[n >> SQ];
	if (cnt[n]) EPQ.push(X[n] * cnt[n]);
	C.push(X[n] * (++cnt[n]));
}

void Sub(int idx) {
	int n = S[idx];
	priority_queue<ll>& C = PQ[n >> SQ];
	priority_queue<ll>& EPQ = E[n >> SQ];
	EPQ.push(X[n] * cnt[n]);
	if (--cnt[n]) C.push(X[n] * (cnt[n]));
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, Q;
	cin >> N >> Q;
	map<int, int> occur;
	for (int i = 1; i <= N; ++i) {
		cin >> X[i];
		if (occur.find(X[i]) == occur.end()) S[i] = occur[X[i]] = i;
		else S[i] = occur[X[i]];
	}
	for (int i = 0; i < Q; ++i) {
		int s, e;
		cin >> s >> e;
		QS[i] = Query(s, e, i);
	}
	sort(QS, QS + Q);

	int L = 1, R = 0;
	for (int d = 0; d < Q; ++d) {
		auto [s, e, id] = QS[d];
		while (R < e) Add(++R);
		while (s < L) Add(--L);
		while (e < R) Sub(R--);
		while (L < s) Sub(L++);
		for (int i = 0; i < (MAX >> SQ); ++i) {
			while (!E[i].empty() && PQ[i].top() == E[i].top()) PQ[i].pop(), E[i].pop();
			if (PQ[i].empty()) continue;
			ans[id] = max(ans[id], PQ[i].top());
		}
	}

	for (int i = 0; i < Q; ++i) cout << ans[i] << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1756 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 1 ms 1748 KB Output is correct
7 Correct 1 ms 1748 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 1748 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 1 ms 1748 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 1 ms 1852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1756 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 1 ms 1748 KB Output is correct
7 Correct 1 ms 1748 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 1748 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 1 ms 1748 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 1 ms 1852 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 6 ms 2136 KB Output is correct
18 Correct 12 ms 2360 KB Output is correct
19 Correct 26 ms 2492 KB Output is correct
20 Correct 63 ms 2668 KB Output is correct
21 Correct 108 ms 3048 KB Output is correct
22 Correct 101 ms 3016 KB Output is correct
23 Correct 105 ms 2556 KB Output is correct
24 Correct 107 ms 3024 KB Output is correct
25 Correct 78 ms 4576 KB Output is correct
26 Correct 81 ms 4232 KB Output is correct
27 Correct 85 ms 3920 KB Output is correct
28 Correct 87 ms 3880 KB Output is correct
29 Correct 96 ms 3676 KB Output is correct
30 Correct 89 ms 3628 KB Output is correct
31 Correct 108 ms 2760 KB Output is correct
32 Correct 94 ms 2540 KB Output is correct
33 Correct 90 ms 3792 KB Output is correct
34 Correct 78 ms 4632 KB Output is correct
35 Correct 75 ms 4596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1748 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 3 ms 1876 KB Output is correct
6 Correct 4 ms 2004 KB Output is correct
7 Correct 6 ms 2328 KB Output is correct
8 Correct 6 ms 2644 KB Output is correct
9 Correct 14 ms 3264 KB Output is correct
10 Correct 28 ms 2836 KB Output is correct
11 Correct 185 ms 7176 KB Output is correct
12 Correct 45 ms 5736 KB Output is correct
13 Correct 101 ms 7800 KB Output is correct
14 Correct 123 ms 8820 KB Output is correct
15 Correct 136 ms 10108 KB Output is correct
16 Correct 114 ms 12740 KB Output is correct
17 Correct 47 ms 8148 KB Output is correct
18 Correct 94 ms 12352 KB Output is correct
19 Correct 108 ms 13164 KB Output is correct
20 Correct 53 ms 10668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1756 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 1 ms 1748 KB Output is correct
7 Correct 1 ms 1748 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 1748 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 1 ms 1748 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 1 ms 1852 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 6 ms 2136 KB Output is correct
18 Correct 12 ms 2360 KB Output is correct
19 Correct 26 ms 2492 KB Output is correct
20 Correct 63 ms 2668 KB Output is correct
21 Correct 108 ms 3048 KB Output is correct
22 Correct 101 ms 3016 KB Output is correct
23 Correct 105 ms 2556 KB Output is correct
24 Correct 107 ms 3024 KB Output is correct
25 Correct 78 ms 4576 KB Output is correct
26 Correct 81 ms 4232 KB Output is correct
27 Correct 85 ms 3920 KB Output is correct
28 Correct 87 ms 3880 KB Output is correct
29 Correct 96 ms 3676 KB Output is correct
30 Correct 89 ms 3628 KB Output is correct
31 Correct 108 ms 2760 KB Output is correct
32 Correct 94 ms 2540 KB Output is correct
33 Correct 90 ms 3792 KB Output is correct
34 Correct 78 ms 4632 KB Output is correct
35 Correct 75 ms 4596 KB Output is correct
36 Correct 1 ms 1748 KB Output is correct
37 Correct 1 ms 1748 KB Output is correct
38 Correct 1 ms 1748 KB Output is correct
39 Correct 2 ms 1876 KB Output is correct
40 Correct 3 ms 1876 KB Output is correct
41 Correct 4 ms 2004 KB Output is correct
42 Correct 6 ms 2328 KB Output is correct
43 Correct 6 ms 2644 KB Output is correct
44 Correct 14 ms 3264 KB Output is correct
45 Correct 28 ms 2836 KB Output is correct
46 Correct 185 ms 7176 KB Output is correct
47 Correct 45 ms 5736 KB Output is correct
48 Correct 101 ms 7800 KB Output is correct
49 Correct 123 ms 8820 KB Output is correct
50 Correct 136 ms 10108 KB Output is correct
51 Correct 114 ms 12740 KB Output is correct
52 Correct 47 ms 8148 KB Output is correct
53 Correct 94 ms 12352 KB Output is correct
54 Correct 108 ms 13164 KB Output is correct
55 Correct 53 ms 10668 KB Output is correct
56 Correct 254 ms 2952 KB Output is correct
57 Correct 654 ms 5060 KB Output is correct
58 Correct 943 ms 10900 KB Output is correct
59 Correct 1313 ms 20356 KB Output is correct
60 Correct 1833 ms 25192 KB Output is correct
61 Correct 3346 ms 14428 KB Output is correct
62 Execution timed out 4065 ms 11300 KB Time limit exceeded
63 Halted 0 ms 0 KB -