# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
20584 | 2017-02-12T13:25:37 Z | kdh9949 | 역사적 조사 (JOI14_historical) | C++14 | 2966 ms | 6804 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz = 131072, b = 320; int n, q, a[100010], xx[100010]; ll ans[100010]; struct Query{ int s, e, idx; bool operator<(const Query &oth) const { return (s / b == oth.s / b) ? e < oth.e : s < oth.s; } } qa[100010]; struct Seg{ ll dat[2 * sz]; void init(){ for(int i = 1; i < 2 * sz; i++) dat[i] = 0; } void upd(int x, int v){ x += sz - 1; dat[x] += v * xx[x - sz + 1]; for(x /= 2; x; x /= 2) dat[x] = max(dat[2 * x], dat[2 * x + 1]); } ll get(){ return dat[1]; } } S; int main(){ scanf("%d%d", &n, &q); for(int i = 1; i <= n; i++){ scanf("%d", a + i); xx[i] = a[i]; } sort(xx + 1, xx + n + 1); for(int i = 1; i <= n; i++) a[i] = (int)(lower_bound(xx + 1, xx + n + 1, a[i]) - xx); for(int i = 1; i <= q; i++){ scanf("%d%d", &qa[i].s, &qa[i].e); qa[i].idx = i; } sort(qa + 1, qa + q + 1); qa[0].s = 1; qa[0].e = 0; S.init(); for(int i = 1; i <= q; i++){ int ls = qa[i - 1].s, le = qa[i - 1].e; int cs = qa[i].s, ce = qa[i].e; for(; ls < cs; ) S.upd(a[ls++], -1); for(; ls > cs; ) S.upd(a[--ls], 1); for(; le < ce; ) S.upd(a[++le], 1); for(; le > ce; ) S.upd(a[le--], -1); ans[qa[i].idx] = S.get(); } for(int i = 1; i <= q; i++) printf("%lld\n", ans[i]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6804 KB | Output is correct |
2 | Correct | 0 ms | 6804 KB | Output is correct |
3 | Correct | 0 ms | 6804 KB | Output is correct |
4 | Correct | 0 ms | 6804 KB | Output is correct |
5 | Correct | 0 ms | 6804 KB | Output is correct |
6 | Correct | 0 ms | 6804 KB | Output is correct |
7 | Correct | 0 ms | 6804 KB | Output is correct |
8 | Correct | 0 ms | 6804 KB | Output is correct |
9 | Correct | 0 ms | 6804 KB | Output is correct |
10 | Correct | 0 ms | 6804 KB | Output is correct |
11 | Correct | 0 ms | 6804 KB | Output is correct |
12 | Correct | 0 ms | 6804 KB | Output is correct |
13 | Correct | 0 ms | 6804 KB | Output is correct |
14 | Correct | 0 ms | 6804 KB | Output is correct |
15 | Correct | 0 ms | 6804 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6804 KB | Output is correct |
2 | Correct | 3 ms | 6804 KB | Output is correct |
3 | Correct | 3 ms | 6804 KB | Output is correct |
4 | Correct | 9 ms | 6804 KB | Output is correct |
5 | Correct | 19 ms | 6804 KB | Output is correct |
6 | Correct | 33 ms | 6804 KB | Output is correct |
7 | Correct | 33 ms | 6804 KB | Output is correct |
8 | Correct | 29 ms | 6804 KB | Output is correct |
9 | Correct | 33 ms | 6804 KB | Output is correct |
10 | Correct | 29 ms | 6804 KB | Output is correct |
11 | Correct | 33 ms | 6804 KB | Output is correct |
12 | Correct | 33 ms | 6804 KB | Output is correct |
13 | Correct | 33 ms | 6804 KB | Output is correct |
14 | Correct | 33 ms | 6804 KB | Output is correct |
15 | Correct | 29 ms | 6804 KB | Output is correct |
16 | Correct | 33 ms | 6804 KB | Output is correct |
17 | Correct | 33 ms | 6804 KB | Output is correct |
18 | Correct | 29 ms | 6804 KB | Output is correct |
19 | Correct | 33 ms | 6804 KB | Output is correct |
20 | Correct | 33 ms | 6804 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6804 KB | Output is correct |
2 | Correct | 0 ms | 6804 KB | Output is correct |
3 | Correct | 0 ms | 6804 KB | Output is correct |
4 | Correct | 0 ms | 6804 KB | Output is correct |
5 | Correct | 0 ms | 6804 KB | Output is correct |
6 | Correct | 0 ms | 6804 KB | Output is correct |
7 | Correct | 0 ms | 6804 KB | Output is correct |
8 | Correct | 3 ms | 6804 KB | Output is correct |
9 | Correct | 13 ms | 6804 KB | Output is correct |
10 | Correct | 13 ms | 6804 KB | Output is correct |
11 | Correct | 73 ms | 6804 KB | Output is correct |
12 | Correct | 46 ms | 6804 KB | Output is correct |
13 | Correct | 66 ms | 6804 KB | Output is correct |
14 | Correct | 83 ms | 6804 KB | Output is correct |
15 | Correct | 93 ms | 6804 KB | Output is correct |
16 | Correct | 76 ms | 6804 KB | Output is correct |
17 | Correct | 33 ms | 6804 KB | Output is correct |
18 | Correct | 69 ms | 6804 KB | Output is correct |
19 | Correct | 63 ms | 6804 KB | Output is correct |
20 | Correct | 36 ms | 6804 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 73 ms | 6804 KB | Output is correct |
2 | Correct | 196 ms | 6804 KB | Output is correct |
3 | Correct | 369 ms | 6804 KB | Output is correct |
4 | Correct | 583 ms | 6804 KB | Output is correct |
5 | Correct | 856 ms | 6804 KB | Output is correct |
6 | Correct | 1176 ms | 6804 KB | Output is correct |
7 | Correct | 1296 ms | 6804 KB | Output is correct |
8 | Correct | 1459 ms | 6804 KB | Output is correct |
9 | Correct | 1736 ms | 6804 KB | Output is correct |
10 | Correct | 2519 ms | 6804 KB | Output is correct |
11 | Correct | 1969 ms | 6804 KB | Output is correct |
12 | Correct | 2259 ms | 6804 KB | Output is correct |
13 | Correct | 2789 ms | 6804 KB | Output is correct |
14 | Correct | 2849 ms | 6804 KB | Output is correct |
15 | Correct | 2966 ms | 6804 KB | Output is correct |
16 | Correct | 2876 ms | 6804 KB | Output is correct |
17 | Correct | 2773 ms | 6804 KB | Output is correct |
18 | Correct | 2819 ms | 6804 KB | Output is correct |
19 | Correct | 2759 ms | 6804 KB | Output is correct |
20 | Correct | 2836 ms | 6804 KB | Output is correct |
21 | Correct | 2866 ms | 6804 KB | Output is correct |
22 | Correct | 2873 ms | 6804 KB | Output is correct |
23 | Correct | 2869 ms | 6804 KB | Output is correct |
24 | Correct | 2819 ms | 6804 KB | Output is correct |
25 | Correct | 2473 ms | 6804 KB | Output is correct |