답안 #433185

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

using namespace std;
typedef long long ll;
int bucket = 316;
int n, q;

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(ll p, ll val)
{
    for(tree[p+=n]+=val;p>1;p>>=1) tree[p>>1] = max(tree[p], tree[p^1]);
}

ll ans[100002];

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    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(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(I[s], -X[s]);
            s++;
        }
        while(s > Q[i].s)
        {
            s--;
            update(I[s], X[s]);
        }
        while(e < Q[i].e)
        {
            e++;
            update(I[e], X[e]);
        }
        while(e > Q[i].e)
        {
            update(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 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 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 2 ms 1484 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 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 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 2 ms 1484 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 2 ms 1484 KB Output is correct
18 Correct 3 ms 1484 KB Output is correct
19 Correct 6 ms 1612 KB Output is correct
20 Correct 12 ms 1612 KB Output is correct
21 Correct 18 ms 1740 KB Output is correct
22 Correct 17 ms 1740 KB Output is correct
23 Correct 16 ms 1764 KB Output is correct
24 Correct 16 ms 1880 KB Output is correct
25 Correct 17 ms 1764 KB Output is correct
26 Correct 18 ms 1764 KB Output is correct
27 Correct 21 ms 1784 KB Output is correct
28 Correct 18 ms 1764 KB Output is correct
29 Correct 18 ms 1740 KB Output is correct
30 Correct 20 ms 1868 KB Output is correct
31 Correct 18 ms 1740 KB Output is correct
32 Correct 18 ms 1740 KB Output is correct
33 Correct 36 ms 1752 KB Output is correct
34 Correct 18 ms 1740 KB Output is correct
35 Correct 18 ms 1760 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 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 2 ms 1612 KB Output is correct
7 Correct 3 ms 1740 KB Output is correct
8 Correct 6 ms 1996 KB Output is correct
9 Correct 12 ms 2508 KB Output is correct
10 Correct 14 ms 2780 KB Output is correct
11 Correct 70 ms 5316 KB Output is correct
12 Correct 36 ms 5192 KB Output is correct
13 Correct 53 ms 5736 KB Output is correct
14 Correct 75 ms 6220 KB Output is correct
15 Correct 99 ms 7144 KB Output is correct
16 Correct 76 ms 6292 KB Output is correct
17 Correct 42 ms 5320 KB Output is correct
18 Correct 74 ms 6236 KB Output is correct
19 Correct 67 ms 6764 KB Output is correct
20 Correct 36 ms 5736 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 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 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 2 ms 1484 KB Output is correct
16 Correct 2 ms 1484 KB Output is correct
17 Correct 2 ms 1484 KB Output is correct
18 Correct 3 ms 1484 KB Output is correct
19 Correct 6 ms 1612 KB Output is correct
20 Correct 12 ms 1612 KB Output is correct
21 Correct 18 ms 1740 KB Output is correct
22 Correct 17 ms 1740 KB Output is correct
23 Correct 16 ms 1764 KB Output is correct
24 Correct 16 ms 1880 KB Output is correct
25 Correct 17 ms 1764 KB Output is correct
26 Correct 18 ms 1764 KB Output is correct
27 Correct 21 ms 1784 KB Output is correct
28 Correct 18 ms 1764 KB Output is correct
29 Correct 18 ms 1740 KB Output is correct
30 Correct 20 ms 1868 KB Output is correct
31 Correct 18 ms 1740 KB Output is correct
32 Correct 18 ms 1740 KB Output is correct
33 Correct 36 ms 1752 KB Output is correct
34 Correct 18 ms 1740 KB Output is correct
35 Correct 18 ms 1760 KB Output is correct
36 Correct 1 ms 1484 KB Output is correct
37 Correct 1 ms 1484 KB Output is correct
38 Correct 1 ms 1484 KB Output is correct
39 Correct 1 ms 1484 KB Output is correct
40 Correct 2 ms 1612 KB Output is correct
41 Correct 2 ms 1612 KB Output is correct
42 Correct 3 ms 1740 KB Output is correct
43 Correct 6 ms 1996 KB Output is correct
44 Correct 12 ms 2508 KB Output is correct
45 Correct 14 ms 2780 KB Output is correct
46 Correct 70 ms 5316 KB Output is correct
47 Correct 36 ms 5192 KB Output is correct
48 Correct 53 ms 5736 KB Output is correct
49 Correct 75 ms 6220 KB Output is correct
50 Correct 99 ms 7144 KB Output is correct
51 Correct 76 ms 6292 KB Output is correct
52 Correct 42 ms 5320 KB Output is correct
53 Correct 74 ms 6236 KB Output is correct
54 Correct 67 ms 6764 KB Output is correct
55 Correct 36 ms 5736 KB Output is correct
56 Correct 40 ms 1980 KB Output is correct
57 Correct 110 ms 2568 KB Output is correct
58 Correct 190 ms 3224 KB Output is correct
59 Correct 328 ms 3636 KB Output is correct
60 Correct 482 ms 4316 KB Output is correct
61 Correct 609 ms 4976 KB Output is correct
62 Correct 719 ms 5504 KB Output is correct
63 Correct 803 ms 7252 KB Output is correct
64 Correct 932 ms 7600 KB Output is correct
65 Correct 942 ms 7432 KB Output is correct
66 Correct 1084 ms 7724 KB Output is correct
67 Correct 1389 ms 8964 KB Output is correct
68 Correct 1665 ms 9220 KB Output is correct
69 Correct 1687 ms 9336 KB Output is correct
70 Correct 1689 ms 9328 KB Output is correct
71 Correct 1692 ms 9320 KB Output is correct
72 Correct 1722 ms 9340 KB Output is correct
73 Correct 1713 ms 9316 KB Output is correct
74 Correct 1741 ms 9320 KB Output is correct
75 Correct 1715 ms 9320 KB Output is correct
76 Correct 1659 ms 9320 KB Output is correct
77 Correct 1755 ms 9448 KB Output is correct
78 Correct 1722 ms 9320 KB Output is correct
79 Correct 1684 ms 9444 KB Output is correct
80 Correct 937 ms 8296 KB Output is correct