답안 #302156

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

const int SQ = 316, SZ = 131072;
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];
ll res[100101], seg[270000];
vector<Node> q;
priority_queue<ll> pq, del;
vector<int> com;

void Update(int n, int val) // 0-based
{
	n += SZ; seg[n] += val;
	for(n>>=1; n; n>>=1) seg[n] = max(seg[n<<1], seg[n<<1|1]);
}

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=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++;
			Update(B[r], A[r]);
		}
		while(l < nl)
		{
			Update(B[l], -A[l]);
			l++;
		}
		while(nl < l)
		{
			l--;
			Update(B[l], A[l]);
		}
		while(nr < r)
		{
			Update(B[r], -A[r]);
			r--;
		}

		res[idx] = seg[1];
	}

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

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i=0; i<q.size(); i++)
      |               ~^~~~~~~~~
historic.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |  scanf("%d %d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |   scanf("%d", &A[i]);
      |   ~~~~~^~~~~~~~~~~~~
historic.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 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 384 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 1 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 10 ms 512 KB Output is correct
20 Correct 23 ms 512 KB Output is correct
21 Correct 34 ms 640 KB Output is correct
22 Correct 34 ms 768 KB Output is correct
23 Correct 40 ms 640 KB Output is correct
24 Correct 37 ms 640 KB Output is correct
25 Correct 35 ms 640 KB Output is correct
26 Correct 36 ms 792 KB Output is correct
27 Correct 35 ms 888 KB Output is correct
28 Correct 35 ms 760 KB Output is correct
29 Correct 38 ms 768 KB Output is correct
30 Correct 36 ms 760 KB Output is correct
31 Correct 37 ms 640 KB Output is correct
32 Correct 48 ms 640 KB Output is correct
33 Correct 38 ms 640 KB Output is correct
34 Correct 38 ms 768 KB Output is correct
35 Correct 35 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 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 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 13 ms 896 KB Output is correct
10 Correct 17 ms 1148 KB Output is correct
11 Correct 83 ms 4192 KB Output is correct
12 Correct 48 ms 1712 KB Output is correct
13 Correct 57 ms 2672 KB Output is correct
14 Correct 83 ms 4076 KB Output is correct
15 Correct 117 ms 5728 KB Output is correct
16 Correct 76 ms 5100 KB Output is correct
17 Correct 42 ms 2672 KB Output is correct
18 Correct 71 ms 4072 KB Output is correct
19 Correct 83 ms 5864 KB Output is correct
20 Correct 58 ms 4080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 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 1 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 10 ms 512 KB Output is correct
20 Correct 23 ms 512 KB Output is correct
21 Correct 34 ms 640 KB Output is correct
22 Correct 34 ms 768 KB Output is correct
23 Correct 40 ms 640 KB Output is correct
24 Correct 37 ms 640 KB Output is correct
25 Correct 35 ms 640 KB Output is correct
26 Correct 36 ms 792 KB Output is correct
27 Correct 35 ms 888 KB Output is correct
28 Correct 35 ms 760 KB Output is correct
29 Correct 38 ms 768 KB Output is correct
30 Correct 36 ms 760 KB Output is correct
31 Correct 37 ms 640 KB Output is correct
32 Correct 48 ms 640 KB Output is correct
33 Correct 38 ms 640 KB Output is correct
34 Correct 38 ms 768 KB Output is correct
35 Correct 35 ms 760 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 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 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 6 ms 640 KB Output is correct
44 Correct 13 ms 896 KB Output is correct
45 Correct 17 ms 1148 KB Output is correct
46 Correct 83 ms 4192 KB Output is correct
47 Correct 48 ms 1712 KB Output is correct
48 Correct 57 ms 2672 KB Output is correct
49 Correct 83 ms 4076 KB Output is correct
50 Correct 117 ms 5728 KB Output is correct
51 Correct 76 ms 5100 KB Output is correct
52 Correct 42 ms 2672 KB Output is correct
53 Correct 71 ms 4072 KB Output is correct
54 Correct 83 ms 5864 KB Output is correct
55 Correct 58 ms 4080 KB Output is correct
56 Correct 86 ms 1000 KB Output is correct
57 Correct 190 ms 1268 KB Output is correct
58 Correct 349 ms 1780 KB Output is correct
59 Correct 537 ms 2284 KB Output is correct
60 Correct 753 ms 2764 KB Output is correct
61 Correct 985 ms 3172 KB Output is correct
62 Correct 1332 ms 5224 KB Output is correct
63 Correct 1807 ms 6044 KB Output is correct
64 Correct 2497 ms 6716 KB Output is correct
65 Correct 3062 ms 6720 KB Output is correct
66 Correct 2564 ms 6808 KB Output is correct
67 Correct 2190 ms 6864 KB Output is correct
68 Correct 2280 ms 7120 KB Output is correct
69 Correct 2476 ms 7648 KB Output is correct
70 Correct 2699 ms 7984 KB Output is correct
71 Correct 2658 ms 7788 KB Output is correct
72 Correct 2621 ms 7720 KB Output is correct
73 Correct 2535 ms 7668 KB Output is correct
74 Correct 2607 ms 7608 KB Output is correct
75 Correct 2563 ms 7576 KB Output is correct
76 Correct 2537 ms 7540 KB Output is correct
77 Correct 2549 ms 7644 KB Output is correct
78 Correct 2470 ms 7660 KB Output is correct
79 Correct 2468 ms 7600 KB Output is correct
80 Correct 3207 ms 7488 KB Output is correct