답안 #302119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302119 2020-09-18T13:11:19 Z edenooo 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 107936 KB
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890
#define ll long long

const int SQ = 316;
struct Node {
	int l, r, i;
	bool operator<(Node &n)
	{
		if (l/SQ != n.l/SQ) return l/SQ < n.l/SQ;
		return r < n.r;
	}
};

int N, Q;
int A[100101], B[100101], cnt[100101];
ll res[100101];
vector<Node> q;
priority_queue<ll> pq, del;
vector<int> com;

int main()
{
	scanf("%d %d", &N, &Q);
	for(int i=1; i<=N; i++)
	{
		scanf("%d", &A[i]);
		com.push_back(A[i]);
	}
	// 좌표 압축
	sort(com.begin(), com.end());
	com.erase(unique(com.begin(), com.end()), com.end());
	for(int i=1; i<=N; i++)
		B[i] = lower_bound(com.begin(), com.end(), A[i]) - com.begin();
	for(int i=0; i<com.size(); i++)
		pq.push(0);

	// 오프라인 쿼리
	for(int i=1; i<=Q; i++)
	{
		int l, r;
		scanf("%d %d", &l, &r);
		q.push_back({l, r, i});
	}
	sort(q.begin(), q.end());

	// MO's
	int l = 1, r = 0; // [l, r]
	for(int i=0; i<q.size(); i++)
	{
		int nl = q[i].l, nr = q[i].r, idx = q[i].i;
		while(r < nr)
		{
			r++;
			del.push((ll)A[r]*cnt[B[r]]);
			cnt[B[r]]++;
			pq.push((ll)A[r]*cnt[B[r]]);
		}
		while(l < nl)
		{
			del.push((ll)A[l]*cnt[B[l]]);
			cnt[B[l]]--;
			pq.push((ll)A[l]*cnt[B[l]]);
			l++;
		}
		while(nl < l)
		{
			l--;
			del.push((ll)A[l]*cnt[B[l]]);
			cnt[B[l]]++;
			pq.push((ll)A[l]*cnt[B[l]]);
		}
		while(nr < r)
		{
			del.push((ll)A[r]*cnt[B[r]]);
			cnt[B[r]]--;
			pq.push((ll)A[r]*cnt[B[r]]);
			r--;
		}

		while(!pq.empty() && !del.empty() && pq.top() == del.top())
			pq.pop(), del.pop();
		res[idx] = pq.top();
	}

	for(int i=1; i<=Q; i++)
		printf("%lld\n", res[i]);
	return 0;
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=0; i<com.size(); i++)
      |               ~^~~~~~~~~~~
historic.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i=0; i<q.size(); i++)
      |               ~^~~~~~~~~
historic.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  scanf("%d %d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%d", &A[i]);
      |   ~~~~~^~~~~~~~~~~~~
historic.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 7 ms 856 KB Output is correct
18 Correct 17 ms 1328 KB Output is correct
19 Correct 37 ms 1524 KB Output is correct
20 Correct 91 ms 2240 KB Output is correct
21 Correct 157 ms 2416 KB Output is correct
22 Correct 146 ms 2420 KB Output is correct
23 Correct 157 ms 2024 KB Output is correct
24 Correct 155 ms 2292 KB Output is correct
25 Correct 107 ms 6996 KB Output is correct
26 Correct 123 ms 6996 KB Output is correct
27 Correct 127 ms 4692 KB Output is correct
28 Correct 113 ms 6980 KB Output is correct
29 Correct 136 ms 6996 KB Output is correct
30 Correct 149 ms 4308 KB Output is correct
31 Correct 159 ms 2420 KB Output is correct
32 Correct 141 ms 1900 KB Output is correct
33 Correct 129 ms 4820 KB Output is correct
34 Correct 127 ms 6988 KB Output is correct
35 Correct 89 ms 6988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 10 ms 1244 KB Output is correct
9 Correct 13 ms 2040 KB Output is correct
10 Correct 27 ms 1404 KB Output is correct
11 Correct 113 ms 6888 KB Output is correct
12 Correct 69 ms 4412 KB Output is correct
13 Correct 81 ms 6892 KB Output is correct
14 Correct 101 ms 7144 KB Output is correct
15 Correct 129 ms 9824 KB Output is correct
16 Correct 72 ms 9192 KB Output is correct
17 Correct 42 ms 5308 KB Output is correct
18 Correct 69 ms 9572 KB Output is correct
19 Correct 74 ms 10724 KB Output is correct
20 Correct 57 ms 7400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 7 ms 856 KB Output is correct
18 Correct 17 ms 1328 KB Output is correct
19 Correct 37 ms 1524 KB Output is correct
20 Correct 91 ms 2240 KB Output is correct
21 Correct 157 ms 2416 KB Output is correct
22 Correct 146 ms 2420 KB Output is correct
23 Correct 157 ms 2024 KB Output is correct
24 Correct 155 ms 2292 KB Output is correct
25 Correct 107 ms 6996 KB Output is correct
26 Correct 123 ms 6996 KB Output is correct
27 Correct 127 ms 4692 KB Output is correct
28 Correct 113 ms 6980 KB Output is correct
29 Correct 136 ms 6996 KB Output is correct
30 Correct 149 ms 4308 KB Output is correct
31 Correct 159 ms 2420 KB Output is correct
32 Correct 141 ms 1900 KB Output is correct
33 Correct 129 ms 4820 KB Output is correct
34 Correct 127 ms 6988 KB Output is correct
35 Correct 89 ms 6988 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 4 ms 768 KB Output is correct
43 Correct 10 ms 1244 KB Output is correct
44 Correct 13 ms 2040 KB Output is correct
45 Correct 27 ms 1404 KB Output is correct
46 Correct 113 ms 6888 KB Output is correct
47 Correct 69 ms 4412 KB Output is correct
48 Correct 81 ms 6892 KB Output is correct
49 Correct 101 ms 7144 KB Output is correct
50 Correct 129 ms 9824 KB Output is correct
51 Correct 72 ms 9192 KB Output is correct
52 Correct 42 ms 5308 KB Output is correct
53 Correct 69 ms 9572 KB Output is correct
54 Correct 74 ms 10724 KB Output is correct
55 Correct 57 ms 7400 KB Output is correct
56 Correct 390 ms 2500 KB Output is correct
57 Correct 1049 ms 8012 KB Output is correct
58 Correct 1644 ms 51628 KB Output is correct
59 Correct 2946 ms 102008 KB Output is correct
60 Correct 3510 ms 107936 KB Output is correct
61 Execution timed out 4033 ms 53652 KB Time limit exceeded
62 Halted 0 ms 0 KB -