답안 #433183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433183 2021-06-19T06:10:17 Z benedict0724 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 9668 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int bucket = 316;

struct query
{
    int s, e, i;
    query() : query(0, 0, 0) {}
    query(int _s, int _e, int _i) : s(_s), e(_e), i(_i) {}

    bool operator < (const query &O)
    {
        if(s/bucket == O.s/bucket) return e < O.e;
        return s/bucket < O.s/bucket;
    }
};

ll X[100002], Y[100002], I[100002];
query Q[100002];

ll tree[400002];

void update(int i, int l, int r, int id, ll v)
{
    if(l == r) { tree[i] += v; return; }
    int m = (l + r)/2;
    if(id <= m) update(i*2, l, m, id, v);
    else update(i*2+1, m+1, r, id, v);

    tree[i] = max(tree[i*2], tree[i*2+1]);
}

ll ans[100002];

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    int n, q; cin >> n >> q;
    for(int i=1;i<=n;i++) cin >> X[i];

    for(int i=1;i<=q;i++)
    {
        int l, r; cin >> l >> r;
        Q[i] = query(l, r, i);
    }
    sort(Q + 1, Q + q + 1);

    for(int i=1;i<=n;i++) Y[i] = X[i];
    sort(Y + 1, Y + n + 1);
    for(int i=1;i<=n;i++) I[i] = lower_bound(Y + 1, Y + n + 1, X[i]) - Y;

    for(int i=Q[1].s;i<=Q[1].e;i++)
        update(1, 1, n, I[i], X[i]);

    ans[Q[1].i] = tree[1];
    int s = Q[1].s, e = Q[1].e;
    for(int i=2;i<=q;i++)
    {
        while(s < Q[i].s)
        {
            update(1, 1, n, I[s], -X[s]);
            s++;
        }
        while(s > Q[i].s)
        {
            s--;
            update(1, 1, n, I[s], X[s]);
        }
        while(e < Q[i].e)
        {
            e++;
            update(1, 1, n, I[e], X[e]);
        }
        while(e > Q[i].e)
        {
            update(1, 1, n, I[e], -X[e]);
            e--;
        }

        ans[Q[i].i] = tree[1];
    }

    for(int i=1;i<=q;i++) cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 1 ms 1508 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1512 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 2 ms 1484 KB Output is correct
11 Correct 1 ms 1508 KB Output is correct
12 Correct 2 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 1 ms 1508 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1512 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 2 ms 1484 KB Output is correct
11 Correct 1 ms 1508 KB Output is correct
12 Correct 2 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1500 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 4 ms 1484 KB Output is correct
18 Correct 9 ms 1580 KB Output is correct
19 Correct 19 ms 1632 KB Output is correct
20 Correct 43 ms 1728 KB Output is correct
21 Correct 71 ms 1868 KB Output is correct
22 Correct 72 ms 1868 KB Output is correct
23 Correct 65 ms 1772 KB Output is correct
24 Correct 67 ms 1856 KB Output is correct
25 Correct 74 ms 1868 KB Output is correct
26 Correct 83 ms 1884 KB Output is correct
27 Correct 74 ms 1884 KB Output is correct
28 Correct 76 ms 1900 KB Output is correct
29 Correct 76 ms 1904 KB Output is correct
30 Correct 77 ms 1892 KB Output is correct
31 Correct 75 ms 1968 KB Output is correct
32 Correct 57 ms 1804 KB Output is correct
33 Correct 78 ms 1888 KB Output is correct
34 Correct 78 ms 1892 KB Output is correct
35 Correct 79 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 3 ms 1612 KB Output is correct
6 Correct 3 ms 1612 KB Output is correct
7 Correct 5 ms 1740 KB Output is correct
8 Correct 10 ms 2176 KB Output is correct
9 Correct 20 ms 2808 KB Output is correct
10 Correct 20 ms 3020 KB Output is correct
11 Correct 95 ms 6908 KB Output is correct
12 Correct 75 ms 6116 KB Output is correct
13 Correct 98 ms 7288 KB Output is correct
14 Correct 125 ms 8228 KB Output is correct
15 Correct 139 ms 9668 KB Output is correct
16 Correct 100 ms 8308 KB Output is correct
17 Correct 64 ms 5984 KB Output is correct
18 Correct 98 ms 7876 KB Output is correct
19 Correct 97 ms 9100 KB Output is correct
20 Correct 51 ms 7236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 1 ms 1508 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1512 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 2 ms 1484 KB Output is correct
11 Correct 1 ms 1508 KB Output is correct
12 Correct 2 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1500 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 4 ms 1484 KB Output is correct
18 Correct 9 ms 1580 KB Output is correct
19 Correct 19 ms 1632 KB Output is correct
20 Correct 43 ms 1728 KB Output is correct
21 Correct 71 ms 1868 KB Output is correct
22 Correct 72 ms 1868 KB Output is correct
23 Correct 65 ms 1772 KB Output is correct
24 Correct 67 ms 1856 KB Output is correct
25 Correct 74 ms 1868 KB Output is correct
26 Correct 83 ms 1884 KB Output is correct
27 Correct 74 ms 1884 KB Output is correct
28 Correct 76 ms 1900 KB Output is correct
29 Correct 76 ms 1904 KB Output is correct
30 Correct 77 ms 1892 KB Output is correct
31 Correct 75 ms 1968 KB Output is correct
32 Correct 57 ms 1804 KB Output is correct
33 Correct 78 ms 1888 KB Output is correct
34 Correct 78 ms 1892 KB Output is correct
35 Correct 79 ms 1900 KB Output is correct
36 Correct 2 ms 1484 KB Output is correct
37 Correct 2 ms 1484 KB Output is correct
38 Correct 2 ms 1484 KB Output is correct
39 Correct 2 ms 1484 KB Output is correct
40 Correct 3 ms 1612 KB Output is correct
41 Correct 3 ms 1612 KB Output is correct
42 Correct 5 ms 1740 KB Output is correct
43 Correct 10 ms 2176 KB Output is correct
44 Correct 20 ms 2808 KB Output is correct
45 Correct 20 ms 3020 KB Output is correct
46 Correct 95 ms 6908 KB Output is correct
47 Correct 75 ms 6116 KB Output is correct
48 Correct 98 ms 7288 KB Output is correct
49 Correct 125 ms 8228 KB Output is correct
50 Correct 139 ms 9668 KB Output is correct
51 Correct 100 ms 8308 KB Output is correct
52 Correct 64 ms 5984 KB Output is correct
53 Correct 98 ms 7876 KB Output is correct
54 Correct 97 ms 9100 KB Output is correct
55 Correct 51 ms 7236 KB Output is correct
56 Correct 176 ms 2160 KB Output is correct
57 Correct 561 ms 3140 KB Output is correct
58 Correct 1067 ms 3748 KB Output is correct
59 Correct 1770 ms 4792 KB Output is correct
60 Correct 2683 ms 5428 KB Output is correct
61 Correct 3511 ms 6248 KB Output is correct
62 Execution timed out 4090 ms 6352 KB Time limit exceeded
63 Halted 0 ms 0 KB -