# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259599 | 2020-08-08T03:40:56 Z | 송준혁(#5058) | 역사적 조사 (JOI14_historical) | C++17 | 4000 ms | 68076 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<LL,LL> pii; int N, Q, B=400; LL A[101010], C[101010], ans[101010]; map<LL,LL> M; priority_queue<pii> 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.push(pii(A[1], A[1])); for (int i=1; i<=Q; i++){ for (int j=r+1; j<=P[i].e; j++){ M[A[j]] += A[j]; S.push(pii(M[A[j]], A[j])); } for (int j=P[i].s; j<l; j++) { M[A[j]] += A[j]; S.push(pii(M[A[j]], A[j])); } for (int j=P[i].e+1; j<=r; j++) { M[A[j]] -= A[j]; if (M[A[j]]) S.push(pii(M[A[j]], A[j])); } for (int j=l; j<P[i].s; j++) { M[A[j]] -= A[j]; if (M[A[j]]) S.push(pii(M[A[j]], A[j])); } while (M[S.top().se] != S.top().fi) S.pop(); ans[P[i].id] = S.top().fi; 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 | 0 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 | 0 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 | 2 ms | 512 KB | Output is correct |
17 | Correct | 7 ms | 768 KB | Output is correct |
18 | Correct | 20 ms | 1528 KB | Output is correct |
19 | Correct | 47 ms | 2548 KB | Output is correct |
20 | Correct | 116 ms | 2676 KB | Output is correct |
21 | Correct | 187 ms | 2676 KB | Output is correct |
22 | Correct | 209 ms | 2676 KB | Output is correct |
23 | Correct | 173 ms | 2676 KB | Output is correct |
24 | Correct | 179 ms | 2676 KB | Output is correct |
25 | Correct | 194 ms | 4708 KB | Output is correct |
26 | Correct | 201 ms | 4708 KB | Output is correct |
27 | Correct | 205 ms | 4708 KB | Output is correct |
28 | Correct | 192 ms | 4708 KB | Output is correct |
29 | Correct | 201 ms | 4708 KB | Output is correct |
30 | Correct | 210 ms | 4712 KB | Output is correct |
31 | Correct | 176 ms | 2676 KB | Output is correct |
32 | Correct | 116 ms | 2676 KB | Output is correct |
33 | Correct | 201 ms | 4708 KB | Output is correct |
34 | Correct | 201 ms | 4836 KB | Output is correct |
35 | Correct | 175 ms | 8796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 308 KB | Output is correct |
2 | Correct | 0 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 | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 640 KB | Output is correct |
8 | Correct | 9 ms | 1024 KB | Output is correct |
9 | Correct | 22 ms | 1404 KB | Output is correct |
10 | Correct | 20 ms | 896 KB | Output is correct |
11 | Correct | 113 ms | 4456 KB | Output is correct |
12 | Correct | 73 ms | 3264 KB | Output is correct |
13 | Correct | 100 ms | 3984 KB | Output is correct |
14 | Correct | 147 ms | 5992 KB | Output is correct |
15 | Correct | 180 ms | 7672 KB | Output is correct |
16 | Correct | 125 ms | 10468 KB | Output is correct |
17 | Correct | 43 ms | 4076 KB | Output is correct |
18 | Correct | 81 ms | 6632 KB | Output is correct |
19 | Correct | 131 ms | 11344 KB | Output is correct |
20 | Correct | 77 ms | 9448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 2 ms | 512 KB | Output is correct |
17 | Correct | 7 ms | 768 KB | Output is correct |
18 | Correct | 20 ms | 1528 KB | Output is correct |
19 | Correct | 47 ms | 2548 KB | Output is correct |
20 | Correct | 116 ms | 2676 KB | Output is correct |
21 | Correct | 187 ms | 2676 KB | Output is correct |
22 | Correct | 209 ms | 2676 KB | Output is correct |
23 | Correct | 173 ms | 2676 KB | Output is correct |
24 | Correct | 179 ms | 2676 KB | Output is correct |
25 | Correct | 194 ms | 4708 KB | Output is correct |
26 | Correct | 201 ms | 4708 KB | Output is correct |
27 | Correct | 205 ms | 4708 KB | Output is correct |
28 | Correct | 192 ms | 4708 KB | Output is correct |
29 | Correct | 201 ms | 4708 KB | Output is correct |
30 | Correct | 210 ms | 4712 KB | Output is correct |
31 | Correct | 176 ms | 2676 KB | Output is correct |
32 | Correct | 116 ms | 2676 KB | Output is correct |
33 | Correct | 201 ms | 4708 KB | Output is correct |
34 | Correct | 201 ms | 4836 KB | Output is correct |
35 | Correct | 175 ms | 8796 KB | Output is correct |
36 | Correct | 0 ms | 308 KB | Output is correct |
37 | Correct | 0 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 | 3 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 384 KB | Output is correct |
42 | Correct | 4 ms | 640 KB | Output is correct |
43 | Correct | 9 ms | 1024 KB | Output is correct |
44 | Correct | 22 ms | 1404 KB | Output is correct |
45 | Correct | 20 ms | 896 KB | Output is correct |
46 | Correct | 113 ms | 4456 KB | Output is correct |
47 | Correct | 73 ms | 3264 KB | Output is correct |
48 | Correct | 100 ms | 3984 KB | Output is correct |
49 | Correct | 147 ms | 5992 KB | Output is correct |
50 | Correct | 180 ms | 7672 KB | Output is correct |
51 | Correct | 125 ms | 10468 KB | Output is correct |
52 | Correct | 43 ms | 4076 KB | Output is correct |
53 | Correct | 81 ms | 6632 KB | Output is correct |
54 | Correct | 131 ms | 11344 KB | Output is correct |
55 | Correct | 77 ms | 9448 KB | Output is correct |
56 | Correct | 401 ms | 2804 KB | Output is correct |
57 | Correct | 1323 ms | 9180 KB | Output is correct |
58 | Correct | 2587 ms | 34396 KB | Output is correct |
59 | Execution timed out | 4048 ms | 68076 KB | Time limit exceeded |
60 | Halted | 0 ms | 0 KB | - |