# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39536 | 2018-01-16T09:53:03 Z | 14kg | 역사적 조사 (JOI14_historical) | C++11 | 4000 ms | 14940 KB |
#include <stdio.h> #include <algorithm> #include <set> #include <map> #define N 100001 #define NN 262144 #define SQ 300 #define max2(x,y) (x>y?x:y) using namespace std; typedef pair<pair<int, int>, int> ppi; int n, q_len, M_len, nn, in[N]; long long tree[NN], out[N]; ppi Q[N]; set<int> S; map<int, int> M; bool cmp(ppi x, ppi y) { pair<int,int> tx = { x.first.first / SQ,x.first.second / SQ }; pair<int,int> ty = { y.first.first / SQ,y.first.second / SQ }; return x < y; } void Update(int lev) { tree[lev] = max2(tree[lev * 2], tree[lev * 2 + 1]); if (lev > 1) Update(lev / 2); } void Push(int x, long long num) { tree[nn + x - 1] += num; Update((nn + x - 1) / 2); } int main() { scanf("%d %d", &n, &q_len); for (int i = 1; i <= n; i++) scanf("%d", &in[i]), S.insert(in[i]); for (auto i : S) M[i] = ++M_len; for (nn = 1; nn < M_len; nn *= 2); for (int i = 1; i <= q_len; i++) { scanf("%d %d", &Q[i].first.first, &Q[i].first.second); Q[i].second = i; } sort(Q + 1, Q + q_len + 1, cmp); int l = 1, r = 0; for (int i = 1; i <= q_len; i++) { int x = Q[i].first.first, y = Q[i].first.second; while (r < y) Push(M[in[r + 1]], in[r + 1]), r++; while (l > x) Push(M[in[l - 1]], in[l - 1]), l--; while (r > y) Push(M[in[r]], -in[r]), r--; while (l < x) Push(M[in[l]], -in[l]), l++; out[Q[i].second] = tree[1]; } for (int i = 1; i <= q_len; i++) printf("%lld\n", out[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5568 KB | Output is correct |
2 | Correct | 0 ms | 5568 KB | Output is correct |
3 | Correct | 0 ms | 5568 KB | Output is correct |
4 | Correct | 0 ms | 5568 KB | Output is correct |
5 | Correct | 0 ms | 5568 KB | Output is correct |
6 | Correct | 0 ms | 5568 KB | Output is correct |
7 | Correct | 0 ms | 5568 KB | Output is correct |
8 | Correct | 0 ms | 5568 KB | Output is correct |
9 | Correct | 0 ms | 5568 KB | Output is correct |
10 | Correct | 0 ms | 5568 KB | Output is correct |
11 | Correct | 0 ms | 5568 KB | Output is correct |
12 | Correct | 0 ms | 5568 KB | Output is correct |
13 | Correct | 0 ms | 5568 KB | Output is correct |
14 | Correct | 0 ms | 5568 KB | Output is correct |
15 | Correct | 0 ms | 5568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5568 KB | Output is correct |
2 | Correct | 0 ms | 5568 KB | Output is correct |
3 | Correct | 6 ms | 5568 KB | Output is correct |
4 | Correct | 36 ms | 5568 KB | Output is correct |
5 | Correct | 153 ms | 5568 KB | Output is correct |
6 | Correct | 329 ms | 5568 KB | Output is correct |
7 | Correct | 373 ms | 5568 KB | Output is correct |
8 | Correct | 249 ms | 5568 KB | Output is correct |
9 | Correct | 276 ms | 5568 KB | Output is correct |
10 | Correct | 626 ms | 5700 KB | Output is correct |
11 | Correct | 609 ms | 5700 KB | Output is correct |
12 | Correct | 583 ms | 5700 KB | Output is correct |
13 | Correct | 623 ms | 5700 KB | Output is correct |
14 | Correct | 516 ms | 5700 KB | Output is correct |
15 | Correct | 546 ms | 5700 KB | Output is correct |
16 | Correct | 266 ms | 5568 KB | Output is correct |
17 | Correct | 99 ms | 5568 KB | Output is correct |
18 | Correct | 636 ms | 5700 KB | Output is correct |
19 | Correct | 716 ms | 5700 KB | Output is correct |
20 | Correct | 739 ms | 5832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5568 KB | Output is correct |
2 | Correct | 0 ms | 5568 KB | Output is correct |
3 | Correct | 0 ms | 5568 KB | Output is correct |
4 | Correct | 0 ms | 5568 KB | Output is correct |
5 | Correct | 0 ms | 5700 KB | Output is correct |
6 | Correct | 0 ms | 5568 KB | Output is correct |
7 | Correct | 0 ms | 5700 KB | Output is correct |
8 | Correct | 6 ms | 5832 KB | Output is correct |
9 | Correct | 23 ms | 6228 KB | Output is correct |
10 | Correct | 6 ms | 5568 KB | Output is correct |
11 | Correct | 69 ms | 5568 KB | Output is correct |
12 | Correct | 36 ms | 5568 KB | Output is correct |
13 | Correct | 93 ms | 6228 KB | Output is correct |
14 | Correct | 199 ms | 9396 KB | Output is correct |
15 | Correct | 233 ms | 10980 KB | Output is correct |
16 | Correct | 286 ms | 14940 KB | Output is correct |
17 | Correct | 46 ms | 5568 KB | Output is correct |
18 | Correct | 69 ms | 5568 KB | Output is correct |
19 | Correct | 146 ms | 14940 KB | Output is correct |
20 | Correct | 103 ms | 14940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1193 ms | 5568 KB | Output is correct |
2 | Execution timed out | 4000 ms | 5700 KB | Execution timed out |
3 | Halted | 0 ms | 0 KB | - |