Submission #260942

# Submission time Handle Problem Language Result Execution time Memory
260942 2020-08-11T08:20:32 Z onjo0127 역사적 조사 (JOI14_historical) C++11
40 / 100
4000 ms 11240 KB
#include <bits/stdc++.h>
using namespace std;
const int bck = 320;

struct query {
	int s, e, id;
};

int X[100009], I[100009];
long long ans[100009], sum[100009];
multiset<long long> st;

void add(int x) {
	st.erase(st.find(sum[I[x]]));
	sum[I[x]] += X[x];
	st.insert(sum[I[x]]);
}

void del(int x) {
	st.erase(st.find(sum[I[x]]));
	sum[I[x]] -= X[x];
	st.insert(sum[I[x]]);
}

int main() {
	vector<query> S; vector<int> P;
	int N, Q; scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++) {
		scanf("%d", &X[i]);
		P.push_back(X[i]);
	}
	sort(P.begin(), P.end());
	P.resize(unique(P.begin(), P.end()) - P.begin());
	for(int i=1; i<=N; i++) I[i] = lower_bound(P.begin(), P.end(), X[i]) - P.begin() + 1;
	for(int i=1; i<=Q; i++) {
		int s, e; scanf("%d%d", &s, &e);
		S.push_back({s, e, i});
	}
	sort(S.begin(), S.end(), [&](query PP, query QQ) {
		int pb = PP.s / bck, qb = QQ.s / bck;
		if(pb == qb) return PP.e < QQ.e;
		return pb < qb;
	});

	for(int i=1; i<=P.size(); i++) st.insert(0);
	int s = 1, e = 0;
	for(auto& it: S) {
		int ns = it.s, ne = it.e;
		while(e < ne) add(++e);
		while(e > ne) del(e--);
		while(s > ns) add(--s);
		while(s < ns) del(s++);
		ans[it.id] = *st.rbegin();
	}
	for(int i=1; i<=Q; i++) printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<=P.size(); i++) st.insert(0);
               ~^~~~~~~~~~
historic.cpp:27:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, Q; 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]
   scanf("%d", &X[i]);
   ~~~~~^~~~~~~~~~~~~
historic.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int s, e; scanf("%d%d", &s, &e);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 288 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory 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 288 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 15 ms 416 KB Output is correct
19 Correct 30 ms 500 KB Output is correct
20 Correct 106 ms 632 KB Output is correct
21 Correct 115 ms 724 KB Output is correct
22 Correct 111 ms 760 KB Output is correct
23 Correct 82 ms 640 KB Output is correct
24 Correct 95 ms 640 KB Output is correct
25 Correct 146 ms 760 KB Output is correct
26 Correct 139 ms 760 KB Output is correct
27 Correct 141 ms 760 KB Output is correct
28 Correct 143 ms 760 KB Output is correct
29 Correct 134 ms 760 KB Output is correct
30 Correct 135 ms 760 KB Output is correct
31 Correct 87 ms 760 KB Output is correct
32 Correct 46 ms 760 KB Output is correct
33 Correct 158 ms 760 KB Output is correct
34 Correct 140 ms 760 KB Output is correct
35 Correct 162 ms 768 KB Output is correct
# Verdict Execution time Memory 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 3 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 24 ms 1280 KB Output is correct
10 Correct 16 ms 1404 KB Output is correct
11 Correct 93 ms 5728 KB Output is correct
12 Correct 69 ms 2420 KB Output is correct
13 Correct 109 ms 3696 KB Output is correct
14 Correct 149 ms 6764 KB Output is correct
15 Correct 166 ms 9704 KB Output is correct
16 Correct 160 ms 10092 KB Output is correct
17 Correct 58 ms 3312 KB Output is correct
18 Correct 98 ms 5704 KB Output is correct
19 Correct 140 ms 11240 KB Output is correct
20 Correct 97 ms 8848 KB Output is correct
# Verdict Execution time Memory 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 288 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 15 ms 416 KB Output is correct
19 Correct 30 ms 500 KB Output is correct
20 Correct 106 ms 632 KB Output is correct
21 Correct 115 ms 724 KB Output is correct
22 Correct 111 ms 760 KB Output is correct
23 Correct 82 ms 640 KB Output is correct
24 Correct 95 ms 640 KB Output is correct
25 Correct 146 ms 760 KB Output is correct
26 Correct 139 ms 760 KB Output is correct
27 Correct 141 ms 760 KB Output is correct
28 Correct 143 ms 760 KB Output is correct
29 Correct 134 ms 760 KB Output is correct
30 Correct 135 ms 760 KB Output is correct
31 Correct 87 ms 760 KB Output is correct
32 Correct 46 ms 760 KB Output is correct
33 Correct 158 ms 760 KB Output is correct
34 Correct 140 ms 760 KB Output is correct
35 Correct 162 ms 768 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 3 ms 512 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 6 ms 512 KB Output is correct
43 Correct 14 ms 768 KB Output is correct
44 Correct 24 ms 1280 KB Output is correct
45 Correct 16 ms 1404 KB Output is correct
46 Correct 93 ms 5728 KB Output is correct
47 Correct 69 ms 2420 KB Output is correct
48 Correct 109 ms 3696 KB Output is correct
49 Correct 149 ms 6764 KB Output is correct
50 Correct 166 ms 9704 KB Output is correct
51 Correct 160 ms 10092 KB Output is correct
52 Correct 58 ms 3312 KB Output is correct
53 Correct 98 ms 5704 KB Output is correct
54 Correct 140 ms 11240 KB Output is correct
55 Correct 97 ms 8848 KB Output is correct
56 Correct 216 ms 1064 KB Output is correct
57 Correct 803 ms 1676 KB Output is correct
58 Correct 1807 ms 2408 KB Output is correct
59 Correct 3250 ms 3472 KB Output is correct
60 Execution timed out 4053 ms 3820 KB Time limit exceeded
61 Halted 0 ms 0 KB -