# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261039 | 2020-08-11T10:25:15 Z | onjo0127 | 역사적 조사 (JOI14_historical) | C++11 | 316 ms | 8048 KB |
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int bck = 320; struct query { int s, e, id; }; int N, X[100009], I[100009]; long long ans[100009], sum[100009], mx; vector<query> L[333]; void add(int x) { sum[I[x]] += X[x]; mx = max(mx, sum[I[x]]); } void del(int x) { sum[I[x]] -= X[x]; } int main() { vector<int> P; int 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); L[s / bck].push_back({s, e, i}); } for(int i=0; i<=N/bck; i++) sort(L[i].begin(), L[i].end(), [&](query PP, query QQ) { return PP.e < QQ.e; }); for(int i=0; i<=N/bck; i++) { mx = 0; int ql = i*bck, qr = min((i+1)*bck - 1, N), rm = qr; for(auto& it: L[i]) { int s = it.s, e = it.e; if(s/bck == e/bck) { mx = 0; for(int i=s; i<=e; i++) add(i); ans[it.id] = mx; for(int i=s; i<=e; i++) del(i); mx = 0; } else { while(rm < e) add(++rm); long long tmp = mx; for(int i=s; i<=qr; i++) add(i); ans[it.id] = mx; for(int i=s; i<=qr; i++) del(i); mx = tmp; } } for(int i=rm; i>qr; i--) del(i); } for(int i=1; i<=Q; i++) printf("%lld\n", ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 388 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 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 | 0 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 388 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 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 | 0 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 | 1 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 7 ms | 512 KB | Output is correct |
21 | Correct | 9 ms | 640 KB | Output is correct |
22 | Correct | 9 ms | 640 KB | Output is correct |
23 | Correct | 9 ms | 640 KB | Output is correct |
24 | Correct | 9 ms | 640 KB | Output is correct |
25 | Correct | 9 ms | 640 KB | Output is correct |
26 | Correct | 10 ms | 640 KB | Output is correct |
27 | Correct | 10 ms | 640 KB | Output is correct |
28 | Correct | 10 ms | 768 KB | Output is correct |
29 | Correct | 10 ms | 640 KB | Output is correct |
30 | Correct | 10 ms | 640 KB | Output is correct |
31 | Correct | 10 ms | 640 KB | Output is correct |
32 | Correct | 10 ms | 768 KB | Output is correct |
33 | Correct | 11 ms | 768 KB | Output is correct |
34 | Correct | 10 ms | 768 KB | Output is correct |
35 | Correct | 10 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 3 ms | 512 KB | Output is correct |
8 | Correct | 7 ms | 640 KB | Output is correct |
9 | Correct | 11 ms | 1112 KB | Output is correct |
10 | Correct | 10 ms | 1404 KB | Output is correct |
11 | Correct | 88 ms | 6000 KB | Output is correct |
12 | Correct | 34 ms | 2416 KB | Output is correct |
13 | Correct | 62 ms | 3440 KB | Output is correct |
14 | Correct | 102 ms | 5360 KB | Output is correct |
15 | Correct | 91 ms | 7920 KB | Output is correct |
16 | Correct | 195 ms | 5744 KB | Output is correct |
17 | Correct | 108 ms | 3184 KB | Output is correct |
18 | Correct | 175 ms | 5740 KB | Output is correct |
19 | Correct | 189 ms | 7148 KB | Output is correct |
20 | Correct | 106 ms | 4080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 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 | 388 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 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 | 0 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 | 1 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 7 ms | 512 KB | Output is correct |
21 | Correct | 9 ms | 640 KB | Output is correct |
22 | Correct | 9 ms | 640 KB | Output is correct |
23 | Correct | 9 ms | 640 KB | Output is correct |
24 | Correct | 9 ms | 640 KB | Output is correct |
25 | Correct | 9 ms | 640 KB | Output is correct |
26 | Correct | 10 ms | 640 KB | Output is correct |
27 | Correct | 10 ms | 640 KB | Output is correct |
28 | Correct | 10 ms | 768 KB | Output is correct |
29 | Correct | 10 ms | 640 KB | Output is correct |
30 | Correct | 10 ms | 640 KB | Output is correct |
31 | Correct | 10 ms | 640 KB | Output is correct |
32 | Correct | 10 ms | 768 KB | Output is correct |
33 | Correct | 11 ms | 768 KB | Output is correct |
34 | Correct | 10 ms | 768 KB | Output is correct |
35 | Correct | 10 ms | 768 KB | Output is correct |
36 | Correct | 0 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 | 3 ms | 512 KB | Output is correct |
43 | Correct | 7 ms | 640 KB | Output is correct |
44 | Correct | 11 ms | 1112 KB | Output is correct |
45 | Correct | 10 ms | 1404 KB | Output is correct |
46 | Correct | 88 ms | 6000 KB | Output is correct |
47 | Correct | 34 ms | 2416 KB | Output is correct |
48 | Correct | 62 ms | 3440 KB | Output is correct |
49 | Correct | 102 ms | 5360 KB | Output is correct |
50 | Correct | 91 ms | 7920 KB | Output is correct |
51 | Correct | 195 ms | 5744 KB | Output is correct |
52 | Correct | 108 ms | 3184 KB | Output is correct |
53 | Correct | 175 ms | 5740 KB | Output is correct |
54 | Correct | 189 ms | 7148 KB | Output is correct |
55 | Correct | 106 ms | 4080 KB | Output is correct |
56 | Correct | 19 ms | 1024 KB | Output is correct |
57 | Correct | 43 ms | 1648 KB | Output is correct |
58 | Correct | 63 ms | 2296 KB | Output is correct |
59 | Correct | 104 ms | 3060 KB | Output is correct |
60 | Correct | 123 ms | 3956 KB | Output is correct |
61 | Correct | 141 ms | 4596 KB | Output is correct |
62 | Correct | 190 ms | 5228 KB | Output is correct |
63 | Correct | 208 ms | 6256 KB | Output is correct |
64 | Correct | 241 ms | 6912 KB | Output is correct |
65 | Correct | 272 ms | 6852 KB | Output is correct |
66 | Correct | 276 ms | 7020 KB | Output is correct |
67 | Correct | 284 ms | 7024 KB | Output is correct |
68 | Correct | 301 ms | 7408 KB | Output is correct |
69 | Correct | 305 ms | 7660 KB | Output is correct |
70 | Correct | 316 ms | 8048 KB | Output is correct |
71 | Correct | 308 ms | 7788 KB | Output is correct |
72 | Correct | 308 ms | 7788 KB | Output is correct |
73 | Correct | 309 ms | 7664 KB | Output is correct |
74 | Correct | 308 ms | 7644 KB | Output is correct |
75 | Correct | 306 ms | 7792 KB | Output is correct |
76 | Correct | 302 ms | 7680 KB | Output is correct |
77 | Correct | 310 ms | 7792 KB | Output is correct |
78 | Correct | 299 ms | 7524 KB | Output is correct |
79 | Correct | 308 ms | 7676 KB | Output is correct |
80 | Correct | 282 ms | 7664 KB | Output is correct |