# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259572 | 2020-08-08T02:52:25 Z | 송준혁(#5058) | 역사적 조사 (JOI14_historical) | C++17 | 4000 ms | 11512 KB |
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define Mup(a,x) a=max(a, x) #define mup(a,x) a=min(a, x) #define all(v) v.begin(),v.end() #define lb lower_bound #define INF (1ll<<60) using namespace std; typedef long long LL; typedef pair<int,int> pii; int N, Q, B=400; LL A[101010], C[101010], ans[101010]; map<LL,LL> M; multiset<LL> S; struct query{ int s, e, id; } P[101010]; int main(){ scanf("%d %d", &N, &Q); for (int i=1; i<=N; i++) scanf("%lld", &A[i]); for (int i=1; i<=Q; i++) scanf("%d %d", &P[i].s, &P[i].e), P[i].id=i; sort(P+1, P+Q+1, [&](query a, query b){ if (a.s/B == b.s/B) return a.e < b.e; return a.s < b.s; }); int l=1, r=1; M[A[1]] = A[1]; S.insert(A[1]); for (int i=1; i<=Q; i++){ for (int j=r+1; j<=P[i].e; j++) { if (M[A[j]] != 0) S.erase(S.find(M[A[j]])); M[A[j]] += A[j]; S.insert(M[A[j]]); } for (int j=P[i].s; j<l; j++) { if (M[A[j]] != 0) S.erase(S.find(M[A[j]])); M[A[j]] += A[j]; S.insert(M[A[j]]); } for (int j=P[i].e+1; j<=r; j++) { S.erase(S.find(M[A[j]])); M[A[j]] -= A[j]; if (M[A[j]]) S.insert(M[A[j]]); else M.erase(A[j]); } for (int j=l; j<P[i].s; j++) { S.erase(S.find(M[A[j]])); M[A[j]] -= A[j]; if (M[A[j]]) S.insert(M[A[j]]); else M.erase(A[j]); } ans[P[i].id] = *--S.end(); l=P[i].s, r=P[i].e; } 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 | 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 |
# | 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 | 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 | 3 ms | 384 KB | Output is correct |
17 | Correct | 12 ms | 384 KB | Output is correct |
18 | Correct | 32 ms | 416 KB | Output is correct |
19 | Correct | 73 ms | 384 KB | Output is correct |
20 | Correct | 167 ms | 488 KB | Output is correct |
21 | Correct | 230 ms | 512 KB | Output is correct |
22 | Correct | 286 ms | 512 KB | Output is correct |
23 | Correct | 166 ms | 632 KB | Output is correct |
24 | Correct | 179 ms | 632 KB | Output is correct |
25 | Correct | 360 ms | 844 KB | Output is correct |
26 | Correct | 370 ms | 764 KB | Output is correct |
27 | Correct | 356 ms | 760 KB | Output is correct |
28 | Correct | 354 ms | 760 KB | Output is correct |
29 | Correct | 347 ms | 700 KB | Output is correct |
30 | Correct | 370 ms | 760 KB | Output is correct |
31 | Correct | 180 ms | 632 KB | Output is correct |
32 | Correct | 70 ms | 612 KB | Output is correct |
33 | Correct | 358 ms | 712 KB | Output is correct |
34 | Correct | 352 ms | 808 KB | Output is correct |
35 | Correct | 370 ms | 852 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 | 0 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 | 3 ms | 384 KB | Output is correct |
7 | Correct | 9 ms | 384 KB | Output is correct |
8 | Correct | 20 ms | 640 KB | Output is correct |
9 | Correct | 31 ms | 768 KB | Output is correct |
10 | Correct | 15 ms | 768 KB | Output is correct |
11 | Correct | 103 ms | 3320 KB | Output is correct |
12 | Correct | 95 ms | 1920 KB | Output is correct |
13 | Correct | 118 ms | 2936 KB | Output is correct |
14 | Correct | 136 ms | 4248 KB | Output is correct |
15 | Correct | 106 ms | 6264 KB | Output is correct |
16 | Correct | 205 ms | 9628 KB | Output is correct |
17 | Correct | 68 ms | 2552 KB | Output is correct |
18 | Correct | 109 ms | 4856 KB | Output is correct |
19 | Correct | 126 ms | 7676 KB | Output is correct |
20 | Correct | 92 ms | 11512 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 | 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 | 3 ms | 384 KB | Output is correct |
17 | Correct | 12 ms | 384 KB | Output is correct |
18 | Correct | 32 ms | 416 KB | Output is correct |
19 | Correct | 73 ms | 384 KB | Output is correct |
20 | Correct | 167 ms | 488 KB | Output is correct |
21 | Correct | 230 ms | 512 KB | Output is correct |
22 | Correct | 286 ms | 512 KB | Output is correct |
23 | Correct | 166 ms | 632 KB | Output is correct |
24 | Correct | 179 ms | 632 KB | Output is correct |
25 | Correct | 360 ms | 844 KB | Output is correct |
26 | Correct | 370 ms | 764 KB | Output is correct |
27 | Correct | 356 ms | 760 KB | Output is correct |
28 | Correct | 354 ms | 760 KB | Output is correct |
29 | Correct | 347 ms | 700 KB | Output is correct |
30 | Correct | 370 ms | 760 KB | Output is correct |
31 | Correct | 180 ms | 632 KB | Output is correct |
32 | Correct | 70 ms | 612 KB | Output is correct |
33 | Correct | 358 ms | 712 KB | Output is correct |
34 | Correct | 352 ms | 808 KB | Output is correct |
35 | Correct | 370 ms | 852 KB | Output is correct |
36 | Correct | 1 ms | 384 KB | Output is correct |
37 | Correct | 1 ms | 384 KB | Output is correct |
38 | Correct | 0 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 | 3 ms | 384 KB | Output is correct |
42 | Correct | 9 ms | 384 KB | Output is correct |
43 | Correct | 20 ms | 640 KB | Output is correct |
44 | Correct | 31 ms | 768 KB | Output is correct |
45 | Correct | 15 ms | 768 KB | Output is correct |
46 | Correct | 103 ms | 3320 KB | Output is correct |
47 | Correct | 95 ms | 1920 KB | Output is correct |
48 | Correct | 118 ms | 2936 KB | Output is correct |
49 | Correct | 136 ms | 4248 KB | Output is correct |
50 | Correct | 106 ms | 6264 KB | Output is correct |
51 | Correct | 205 ms | 9628 KB | Output is correct |
52 | Correct | 68 ms | 2552 KB | Output is correct |
53 | Correct | 109 ms | 4856 KB | Output is correct |
54 | Correct | 126 ms | 7676 KB | Output is correct |
55 | Correct | 92 ms | 11512 KB | Output is correct |
56 | Correct | 433 ms | 888 KB | Output is correct |
57 | Correct | 1775 ms | 1528 KB | Output is correct |
58 | Execution timed out | 4033 ms | 2424 KB | Time limit exceeded |
59 | Halted | 0 ms | 0 KB | - |