Submission #789718

# Submission time Handle Problem Language Result Execution time Memory
789718 2023-07-21T20:35:12 Z IBory 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 14024 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];
multiset<ll> cand[MAX >> SQ];

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];
	if (cnt[n]) cand[n >> SQ].erase(cand[n >> SQ].find(X[n] * cnt[n]));
	cand[n >> SQ].insert(X[n] * (++cnt[n]));
}

void Sub(int idx) {
	int n = S[idx];
	cand[n >> SQ].erase(cand[n >> SQ].find(X[n] * cnt[n]));
	if (--cnt[n]) cand[n >> SQ].insert(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 i = 0; i < Q; ++i) {
		auto [s, e, id] = QS[i];
		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) {
			if (cand[i].empty()) continue;
			ans[id] = max(ans[id], *cand[i].rbegin());
		}
	}

	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 1796 KB Output is correct
4 Correct 1 ms 1804 KB Output is correct
5 Correct 2 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 1748 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 2 ms 1796 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 1796 KB Output is correct
4 Correct 1 ms 1804 KB Output is correct
5 Correct 2 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 1748 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 2 ms 1796 KB Output is correct
16 Correct 2 ms 1804 KB Output is correct
17 Correct 4 ms 1748 KB Output is correct
18 Correct 8 ms 1872 KB Output is correct
19 Correct 16 ms 1924 KB Output is correct
20 Correct 35 ms 1980 KB Output is correct
21 Correct 55 ms 2004 KB Output is correct
22 Correct 60 ms 2052 KB Output is correct
23 Correct 46 ms 2016 KB Output is correct
24 Correct 50 ms 2004 KB Output is correct
25 Correct 54 ms 2188 KB Output is correct
26 Correct 55 ms 2196 KB Output is correct
27 Correct 56 ms 2168 KB Output is correct
28 Correct 57 ms 2172 KB Output is correct
29 Correct 59 ms 2136 KB Output is correct
30 Correct 57 ms 2200 KB Output is correct
31 Correct 51 ms 2044 KB Output is correct
32 Correct 26 ms 2028 KB Output is correct
33 Correct 58 ms 2132 KB Output is correct
34 Correct 54 ms 2228 KB Output is correct
35 Correct 52 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1800 KB Output is correct
4 Correct 2 ms 1748 KB Output is correct
5 Correct 3 ms 1876 KB Output is correct
6 Correct 3 ms 1876 KB Output is correct
7 Correct 5 ms 2004 KB Output is correct
8 Correct 7 ms 2388 KB Output is correct
9 Correct 15 ms 3156 KB Output is correct
10 Correct 11 ms 2900 KB Output is correct
11 Correct 99 ms 5552 KB Output is correct
12 Correct 36 ms 4412 KB Output is correct
13 Correct 80 ms 5708 KB Output is correct
14 Correct 110 ms 7820 KB Output is correct
15 Correct 130 ms 9472 KB Output is correct
16 Correct 119 ms 12932 KB Output is correct
17 Correct 49 ms 4344 KB Output is correct
18 Correct 91 ms 5476 KB Output is correct
19 Correct 105 ms 12108 KB Output is correct
20 Correct 79 ms 14024 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 1796 KB Output is correct
4 Correct 1 ms 1804 KB Output is correct
5 Correct 2 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 1748 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 2 ms 1796 KB Output is correct
16 Correct 2 ms 1804 KB Output is correct
17 Correct 4 ms 1748 KB Output is correct
18 Correct 8 ms 1872 KB Output is correct
19 Correct 16 ms 1924 KB Output is correct
20 Correct 35 ms 1980 KB Output is correct
21 Correct 55 ms 2004 KB Output is correct
22 Correct 60 ms 2052 KB Output is correct
23 Correct 46 ms 2016 KB Output is correct
24 Correct 50 ms 2004 KB Output is correct
25 Correct 54 ms 2188 KB Output is correct
26 Correct 55 ms 2196 KB Output is correct
27 Correct 56 ms 2168 KB Output is correct
28 Correct 57 ms 2172 KB Output is correct
29 Correct 59 ms 2136 KB Output is correct
30 Correct 57 ms 2200 KB Output is correct
31 Correct 51 ms 2044 KB Output is correct
32 Correct 26 ms 2028 KB Output is correct
33 Correct 58 ms 2132 KB Output is correct
34 Correct 54 ms 2228 KB Output is correct
35 Correct 52 ms 2260 KB Output is correct
36 Correct 2 ms 1748 KB Output is correct
37 Correct 1 ms 1748 KB Output is correct
38 Correct 1 ms 1800 KB Output is correct
39 Correct 2 ms 1748 KB Output is correct
40 Correct 3 ms 1876 KB Output is correct
41 Correct 3 ms 1876 KB Output is correct
42 Correct 5 ms 2004 KB Output is correct
43 Correct 7 ms 2388 KB Output is correct
44 Correct 15 ms 3156 KB Output is correct
45 Correct 11 ms 2900 KB Output is correct
46 Correct 99 ms 5552 KB Output is correct
47 Correct 36 ms 4412 KB Output is correct
48 Correct 80 ms 5708 KB Output is correct
49 Correct 110 ms 7820 KB Output is correct
50 Correct 130 ms 9472 KB Output is correct
51 Correct 119 ms 12932 KB Output is correct
52 Correct 49 ms 4344 KB Output is correct
53 Correct 91 ms 5476 KB Output is correct
54 Correct 105 ms 12108 KB Output is correct
55 Correct 79 ms 14024 KB Output is correct
56 Correct 117 ms 2240 KB Output is correct
57 Correct 375 ms 2968 KB Output is correct
58 Correct 738 ms 3976 KB Output is correct
59 Correct 1249 ms 5260 KB Output is correct
60 Correct 1873 ms 6132 KB Output is correct
61 Correct 2470 ms 5772 KB Output is correct
62 Correct 2624 ms 5580 KB Output is correct
63 Correct 2499 ms 5668 KB Output is correct
64 Correct 2235 ms 5952 KB Output is correct
65 Correct 1572 ms 6060 KB Output is correct
66 Correct 3016 ms 6092 KB Output is correct
67 Execution timed out 4078 ms 5308 KB Time limit exceeded
68 Halted 0 ms 0 KB -