답안 #557084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557084 2022-05-04T17:27:08 Z lunchbox 역사적 조사 (JOI14_historical) C++17
100 / 100
737 ms 8636 KB
/*
https://oj.uz/problem/view/JOI14_historical
역사적 조사 (Historical)
*/
#include <bits/stdc++.h>
using namespace std;

using LL = long long;
const int N = 100000, B = 350, Q = 100000;

vector<array<int, 3>> qq[(N - 1) / B + 1];

int kk[N], aa_[N];
stack<pair<LL, int>> stk;

void add(int a) {
	kk[a]++;
	stk.push({max(stk.top().first, (LL) kk[a] * aa_[a]), a});
}
void pop() {
	kk[stk.top().second]--;
	stk.pop();
}
LL best() {
	return stk.top().first;
}

void run() {
	static LL ans[Q];
	static int aa[N];
	vector<int> vv;
	int n, q;

	scanf("%d%d", &n, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		vv.push_back(aa[i]);
	}
	sort(vv.begin(), vv.end());
	vv.erase(unique(vv.begin(), vv.end()), vv.end());
	for (int i = 0; i < n; i++) {
		int v = aa[i];

		aa[i] = lower_bound(vv.begin(), vv.end(), aa[i]) - vv.begin();
		aa_[aa[i]] = v;
	}
	for (int i = 0; i < q; i++) {
		int l, r;

		scanf("%d%d", &l, &r), l--, r--;
		qq[l / B].push_back({r, l, i});
	}
	stk.push({0, -1});
	for (int b = 0; b <= (n - 1) / B; b++) {
		int r_ = min(n, (b + 1) * B), p = r_ - 1;

		sort(qq[b].begin(), qq[b].end());
		for (auto [r, l, i] : qq[b]) {
			if (r < r_) {
				for (int j = l; j <= r; j++)
					add(aa[j]);
				ans[i] = best();
				for (int j = l; j <= r; j++)
					pop();
			} else {
				while (p < r)
					add(aa[++p]);
				for (int j = l; j < r_; j++)
					add(aa[j]);
				ans[i] = best();
				for (int j = l; j < r_; j++)
					pop();
			}
		}
		while (stk.size() > 1)
			pop();
	}
	for (int i = 0; i < q; i++)
		printf("%lld\n", ans[i]);
}

int main() {
	run();
	return 0;
}

Compilation message

historic.cpp: In function 'void run()':
historic.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
historic.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   scanf("%d", &aa[i]);
      |   ~~~~~^~~~~~~~~~~~~~
historic.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d%d", &l, &r), l--, r--;
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 6 ms 332 KB Output is correct
20 Correct 13 ms 468 KB Output is correct
21 Correct 22 ms 660 KB Output is correct
22 Correct 21 ms 640 KB Output is correct
23 Correct 21 ms 652 KB Output is correct
24 Correct 19 ms 592 KB Output is correct
25 Correct 22 ms 668 KB Output is correct
26 Correct 22 ms 684 KB Output is correct
27 Correct 20 ms 716 KB Output is correct
28 Correct 22 ms 696 KB Output is correct
29 Correct 23 ms 688 KB Output is correct
30 Correct 22 ms 692 KB Output is correct
31 Correct 20 ms 716 KB Output is correct
32 Correct 23 ms 716 KB Output is correct
33 Correct 20 ms 700 KB Output is correct
34 Correct 19 ms 700 KB Output is correct
35 Correct 23 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 8 ms 852 KB Output is correct
10 Correct 10 ms 1108 KB Output is correct
11 Correct 150 ms 5828 KB Output is correct
12 Correct 29 ms 2096 KB Output is correct
13 Correct 89 ms 3012 KB Output is correct
14 Correct 145 ms 4824 KB Output is correct
15 Correct 67 ms 7336 KB Output is correct
16 Correct 332 ms 5920 KB Output is correct
17 Correct 219 ms 3776 KB Output is correct
18 Correct 356 ms 5760 KB Output is correct
19 Correct 362 ms 6928 KB Output is correct
20 Correct 163 ms 4824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 6 ms 332 KB Output is correct
20 Correct 13 ms 468 KB Output is correct
21 Correct 22 ms 660 KB Output is correct
22 Correct 21 ms 640 KB Output is correct
23 Correct 21 ms 652 KB Output is correct
24 Correct 19 ms 592 KB Output is correct
25 Correct 22 ms 668 KB Output is correct
26 Correct 22 ms 684 KB Output is correct
27 Correct 20 ms 716 KB Output is correct
28 Correct 22 ms 696 KB Output is correct
29 Correct 23 ms 688 KB Output is correct
30 Correct 22 ms 692 KB Output is correct
31 Correct 20 ms 716 KB Output is correct
32 Correct 23 ms 716 KB Output is correct
33 Correct 20 ms 700 KB Output is correct
34 Correct 19 ms 700 KB Output is correct
35 Correct 23 ms 724 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 5 ms 596 KB Output is correct
44 Correct 8 ms 852 KB Output is correct
45 Correct 10 ms 1108 KB Output is correct
46 Correct 150 ms 5828 KB Output is correct
47 Correct 29 ms 2096 KB Output is correct
48 Correct 89 ms 3012 KB Output is correct
49 Correct 145 ms 4824 KB Output is correct
50 Correct 67 ms 7336 KB Output is correct
51 Correct 332 ms 5920 KB Output is correct
52 Correct 219 ms 3776 KB Output is correct
53 Correct 356 ms 5760 KB Output is correct
54 Correct 362 ms 6928 KB Output is correct
55 Correct 163 ms 4824 KB Output is correct
56 Correct 39 ms 984 KB Output is correct
57 Correct 83 ms 1752 KB Output is correct
58 Correct 133 ms 2536 KB Output is correct
59 Correct 186 ms 3460 KB Output is correct
60 Correct 253 ms 4224 KB Output is correct
61 Correct 354 ms 5228 KB Output is correct
62 Correct 377 ms 5944 KB Output is correct
63 Correct 469 ms 6980 KB Output is correct
64 Correct 598 ms 7748 KB Output is correct
65 Correct 607 ms 7804 KB Output is correct
66 Correct 686 ms 7972 KB Output is correct
67 Correct 612 ms 8028 KB Output is correct
68 Correct 630 ms 8096 KB Output is correct
69 Correct 637 ms 8376 KB Output is correct
70 Correct 654 ms 8460 KB Output is correct
71 Correct 659 ms 8424 KB Output is correct
72 Correct 643 ms 8400 KB Output is correct
73 Correct 737 ms 8328 KB Output is correct
74 Correct 644 ms 8404 KB Output is correct
75 Correct 647 ms 8232 KB Output is correct
76 Correct 641 ms 8244 KB Output is correct
77 Correct 636 ms 8248 KB Output is correct
78 Correct 631 ms 8420 KB Output is correct
79 Correct 651 ms 8348 KB Output is correct
80 Correct 602 ms 8636 KB Output is correct