답안 #686745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
686745 2023-01-25T21:48:28 Z qweasdzxc 역사적 조사 (JOI14_historical) C++14
100 / 100
1327 ms 9736 KB
#include <bits/stdc++.h>
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vp vector<pi>
#define vpl vector<pl>
#define ll long long
#define MAX 2147000000
#define MOD 1000000007
using namespace std;

struct st{
    int l, r, idx;
};

int n, q;
const int sz = 1e5 + 10;
vector<st> query(sz);
vi A;

vl maxSeg(sz * 4);
vi vec;

void update(ll p, ll val)
{
    for(maxSeg[p+=n]+=val;p>1;p>>=1) maxSeg[p>>1] = max(maxSeg[p], maxSeg[p^1]);
}

void Plus(int k){
    update(k, A[k]);
}

void Minus(int k){
    update(k, -A[k]);
}


int main() {
	fastio;	
    cin >> n >> q;
    vec.resize(n);
    for(int i{0}; i < n; ++i){
        cin >> vec[i];
    }
    A = vec;
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    for(int i{0}; i < n; ++i){
        vec[i] = lower_bound(A.begin(), A.end(), vec[i]) - A.begin();
    }
    for(int i{0}; i < q; ++i){
        cin >> query[i].l >> query[i].r;
        query[i].l--; query[i].r--;
        query[i].idx = i;
    }
    int sq = sqrt(n);
    sort(query.begin(), query.begin() + q, [&](st& a, st& b){
        if(a.l / sq == b.l / sq) return a.r < b.r;
        else return a.l / sq < b.l / sq;
    });
    int l = query[0].l;
    int r = query[0].r;
    vl ans(q);
    for(int i{l}; i <= r; ++i){
        Plus(vec[i]);
    }
    ans[query[0].idx] = maxSeg[1];
    for(int i{1}; i < q; ++i){
        while(l > query[i].l) Plus(vec[--l]);
        while(r < query[i].r) Plus(vec[++r]);
        while(l < query[i].l) Minus(vec[l++]);        
        while(r > query[i].r) Minus(vec[r--]);
        ans[query[i].idx] = maxSeg[1];
    }
    for(auto& i : ans) cout << i << "\n";
}
	
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 3 ms 4564 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 2 ms 4564 KB Output is correct
5 Correct 3 ms 4564 KB Output is correct
6 Correct 3 ms 4564 KB Output is correct
7 Correct 2 ms 4564 KB Output is correct
8 Correct 2 ms 4564 KB Output is correct
9 Correct 3 ms 4564 KB Output is correct
10 Correct 2 ms 4564 KB Output is correct
11 Correct 2 ms 4564 KB Output is correct
12 Correct 3 ms 4564 KB Output is correct
13 Correct 3 ms 4644 KB Output is correct
14 Correct 3 ms 4564 KB Output is correct
15 Correct 3 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 3 ms 4564 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 2 ms 4564 KB Output is correct
5 Correct 3 ms 4564 KB Output is correct
6 Correct 3 ms 4564 KB Output is correct
7 Correct 2 ms 4564 KB Output is correct
8 Correct 2 ms 4564 KB Output is correct
9 Correct 3 ms 4564 KB Output is correct
10 Correct 2 ms 4564 KB Output is correct
11 Correct 2 ms 4564 KB Output is correct
12 Correct 3 ms 4564 KB Output is correct
13 Correct 3 ms 4644 KB Output is correct
14 Correct 3 ms 4564 KB Output is correct
15 Correct 3 ms 4564 KB Output is correct
16 Correct 2 ms 4648 KB Output is correct
17 Correct 3 ms 4564 KB Output is correct
18 Correct 4 ms 4564 KB Output is correct
19 Correct 4 ms 4692 KB Output is correct
20 Correct 8 ms 4692 KB Output is correct
21 Correct 12 ms 4792 KB Output is correct
22 Correct 11 ms 4784 KB Output is correct
23 Correct 11 ms 4912 KB Output is correct
24 Correct 13 ms 4780 KB Output is correct
25 Correct 12 ms 4808 KB Output is correct
26 Correct 11 ms 4820 KB Output is correct
27 Correct 14 ms 4756 KB Output is correct
28 Correct 12 ms 4812 KB Output is correct
29 Correct 13 ms 4820 KB Output is correct
30 Correct 13 ms 4820 KB Output is correct
31 Correct 12 ms 4756 KB Output is correct
32 Correct 11 ms 4820 KB Output is correct
33 Correct 12 ms 4760 KB Output is correct
34 Correct 12 ms 4756 KB Output is correct
35 Correct 12 ms 4820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4564 KB Output is correct
2 Correct 2 ms 4564 KB Output is correct
3 Correct 3 ms 4620 KB Output is correct
4 Correct 2 ms 4648 KB Output is correct
5 Correct 3 ms 4692 KB Output is correct
6 Correct 3 ms 4692 KB Output is correct
7 Correct 5 ms 4692 KB Output is correct
8 Correct 5 ms 4820 KB Output is correct
9 Correct 9 ms 5096 KB Output is correct
10 Correct 10 ms 5368 KB Output is correct
11 Correct 55 ms 8240 KB Output is correct
12 Correct 27 ms 6184 KB Output is correct
13 Correct 37 ms 6804 KB Output is correct
14 Correct 66 ms 7820 KB Output is correct
15 Correct 85 ms 9268 KB Output is correct
16 Correct 61 ms 7824 KB Output is correct
17 Correct 32 ms 6424 KB Output is correct
18 Correct 47 ms 8344 KB Output is correct
19 Correct 51 ms 8732 KB Output is correct
20 Correct 29 ms 6796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 3 ms 4564 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 2 ms 4564 KB Output is correct
5 Correct 3 ms 4564 KB Output is correct
6 Correct 3 ms 4564 KB Output is correct
7 Correct 2 ms 4564 KB Output is correct
8 Correct 2 ms 4564 KB Output is correct
9 Correct 3 ms 4564 KB Output is correct
10 Correct 2 ms 4564 KB Output is correct
11 Correct 2 ms 4564 KB Output is correct
12 Correct 3 ms 4564 KB Output is correct
13 Correct 3 ms 4644 KB Output is correct
14 Correct 3 ms 4564 KB Output is correct
15 Correct 3 ms 4564 KB Output is correct
16 Correct 2 ms 4648 KB Output is correct
17 Correct 3 ms 4564 KB Output is correct
18 Correct 4 ms 4564 KB Output is correct
19 Correct 4 ms 4692 KB Output is correct
20 Correct 8 ms 4692 KB Output is correct
21 Correct 12 ms 4792 KB Output is correct
22 Correct 11 ms 4784 KB Output is correct
23 Correct 11 ms 4912 KB Output is correct
24 Correct 13 ms 4780 KB Output is correct
25 Correct 12 ms 4808 KB Output is correct
26 Correct 11 ms 4820 KB Output is correct
27 Correct 14 ms 4756 KB Output is correct
28 Correct 12 ms 4812 KB Output is correct
29 Correct 13 ms 4820 KB Output is correct
30 Correct 13 ms 4820 KB Output is correct
31 Correct 12 ms 4756 KB Output is correct
32 Correct 11 ms 4820 KB Output is correct
33 Correct 12 ms 4760 KB Output is correct
34 Correct 12 ms 4756 KB Output is correct
35 Correct 12 ms 4820 KB Output is correct
36 Correct 3 ms 4564 KB Output is correct
37 Correct 2 ms 4564 KB Output is correct
38 Correct 3 ms 4620 KB Output is correct
39 Correct 2 ms 4648 KB Output is correct
40 Correct 3 ms 4692 KB Output is correct
41 Correct 3 ms 4692 KB Output is correct
42 Correct 5 ms 4692 KB Output is correct
43 Correct 5 ms 4820 KB Output is correct
44 Correct 9 ms 5096 KB Output is correct
45 Correct 10 ms 5368 KB Output is correct
46 Correct 55 ms 8240 KB Output is correct
47 Correct 27 ms 6184 KB Output is correct
48 Correct 37 ms 6804 KB Output is correct
49 Correct 66 ms 7820 KB Output is correct
50 Correct 85 ms 9268 KB Output is correct
51 Correct 61 ms 7824 KB Output is correct
52 Correct 32 ms 6424 KB Output is correct
53 Correct 47 ms 8344 KB Output is correct
54 Correct 51 ms 8732 KB Output is correct
55 Correct 29 ms 6796 KB Output is correct
56 Correct 29 ms 4952 KB Output is correct
57 Correct 76 ms 5432 KB Output is correct
58 Correct 156 ms 5796 KB Output is correct
59 Correct 226 ms 6276 KB Output is correct
60 Correct 389 ms 6744 KB Output is correct
61 Correct 429 ms 7416 KB Output is correct
62 Correct 486 ms 7852 KB Output is correct
63 Correct 601 ms 8608 KB Output is correct
64 Correct 708 ms 9164 KB Output is correct
65 Correct 811 ms 8964 KB Output is correct
66 Correct 810 ms 9064 KB Output is correct
67 Correct 820 ms 9144 KB Output is correct
68 Correct 922 ms 9248 KB Output is correct
69 Correct 1054 ms 9344 KB Output is correct
70 Correct 1327 ms 9344 KB Output is correct
71 Correct 1240 ms 9360 KB Output is correct
72 Correct 1176 ms 9364 KB Output is correct
73 Correct 1180 ms 9332 KB Output is correct
74 Correct 1136 ms 9336 KB Output is correct
75 Correct 1172 ms 9340 KB Output is correct
76 Correct 1099 ms 9344 KB Output is correct
77 Correct 1043 ms 9348 KB Output is correct
78 Correct 1073 ms 9364 KB Output is correct
79 Correct 1006 ms 9344 KB Output is correct
80 Correct 815 ms 9736 KB Output is correct