답안 #786384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786384 2023-07-18T07:20:37 Z PenguinsAreCute 역사적 조사 (JOI14_historical) C++17
100 / 100
2974 ms 14760 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LL_MAX LONG_LONG_MAX
#define LL_MIN LONG_LONG_MIN
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
struct qry{int l, r, idx;};
#define REP(i, a, b) for(int i = a; i < b; i++)
#define lb(v,x) (lower_bound(v,v+N,x)-v)
#define BSIZE 400
bool comp(qry a, qry b) {
    if(a.l/BSIZE==b.l/BSIZE) return a.r<b.r;
    return a.l<b.l;
}
int vec[121010];
#define MAXN 131072
int s[2*MAXN], e[2*MAXN], val[2*MAXN];
void init(int st, int en) {
    s[1]=st; e[1]=en;
    REP(i,1,131072) if(s[i]!=e[i]) {
        //printf("%lld %lld %lld\n", i, s[i], e[i]);
        int mid = (s[i] + e[i]) >> 1;
        s[i<<1]=s[i];
        e[i<<1]=mid;
        s[i<<1|1]=mid+1,
        e[i<<1|1]=e[i];
    }
}

void update(int x, int u) {
    int i = x + 131072;
    val[i] += u;
    while(i) {
        i /= 2;
        if(i) val[i] = max(val[i<<1],val[i<<1|1]);
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, Q, l=1,r=0; cin >> N >> Q;
    ll ans[Q]; int arr[N+1], v[N+1];
    init(0,131071);
    REP(i,1,N+1) {cin>>arr[i]; vec[i-1]=arr[i];}
    sort(vec,vec+N);
    REP(i,1,N+1) v[i]=lb(vec,arr[i]);
    qry query[Q];
    REP(i,0,Q) {cin>>query[i].l>>query[i].r; query[i].idx=i;}
    sort(query,query+Q,comp);
    REP(i,0,Q) {
        while(l>query[i].l) {l--;update(v[l],vec[v[l]]);}
        while(l<query[i].l) {update(v[l],-vec[v[l]]);l++;}
        while(r>query[i].r) {update(v[r],-vec[v[r]]);r--;}
        while(r<query[i].r) {r++;update(v[r],vec[v[r]]);}
        ans[query[i].idx]=val[1];
    }
    REP(i,0,Q) cout<<ans[i]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 2 ms 4428 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 3 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 3 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 2 ms 4428 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 3 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 3 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4428 KB Output is correct
16 Correct 3 ms 4488 KB Output is correct
17 Correct 4 ms 4436 KB Output is correct
18 Correct 6 ms 4436 KB Output is correct
19 Correct 10 ms 4616 KB Output is correct
20 Correct 20 ms 4736 KB Output is correct
21 Correct 29 ms 4824 KB Output is correct
22 Correct 29 ms 4888 KB Output is correct
23 Correct 36 ms 4888 KB Output is correct
24 Correct 41 ms 4776 KB Output is correct
25 Correct 29 ms 4888 KB Output is correct
26 Correct 30 ms 4896 KB Output is correct
27 Correct 30 ms 4904 KB Output is correct
28 Correct 30 ms 4896 KB Output is correct
29 Correct 30 ms 4912 KB Output is correct
30 Correct 30 ms 4944 KB Output is correct
31 Correct 30 ms 4908 KB Output is correct
32 Correct 40 ms 4868 KB Output is correct
33 Correct 31 ms 4896 KB Output is correct
34 Correct 35 ms 4940 KB Output is correct
35 Correct 30 ms 4896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 3 ms 4428 KB Output is correct
4 Correct 2 ms 4428 KB Output is correct
5 Correct 3 ms 4564 KB Output is correct
6 Correct 4 ms 4564 KB Output is correct
7 Correct 4 ms 4696 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 11 ms 5768 KB Output is correct
10 Correct 14 ms 5972 KB Output is correct
11 Correct 55 ms 11752 KB Output is correct
12 Correct 30 ms 8968 KB Output is correct
13 Correct 42 ms 10248 KB Output is correct
14 Correct 52 ms 11948 KB Output is correct
15 Correct 68 ms 14604 KB Output is correct
16 Correct 53 ms 12008 KB Output is correct
17 Correct 32 ms 9636 KB Output is correct
18 Correct 50 ms 12512 KB Output is correct
19 Correct 43 ms 13532 KB Output is correct
20 Correct 26 ms 10184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 2 ms 4436 KB Output is correct
4 Correct 2 ms 4428 KB Output is correct
5 Correct 3 ms 4436 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 3 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 3 ms 4436 KB Output is correct
11 Correct 2 ms 4436 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4436 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4428 KB Output is correct
16 Correct 3 ms 4488 KB Output is correct
17 Correct 4 ms 4436 KB Output is correct
18 Correct 6 ms 4436 KB Output is correct
19 Correct 10 ms 4616 KB Output is correct
20 Correct 20 ms 4736 KB Output is correct
21 Correct 29 ms 4824 KB Output is correct
22 Correct 29 ms 4888 KB Output is correct
23 Correct 36 ms 4888 KB Output is correct
24 Correct 41 ms 4776 KB Output is correct
25 Correct 29 ms 4888 KB Output is correct
26 Correct 30 ms 4896 KB Output is correct
27 Correct 30 ms 4904 KB Output is correct
28 Correct 30 ms 4896 KB Output is correct
29 Correct 30 ms 4912 KB Output is correct
30 Correct 30 ms 4944 KB Output is correct
31 Correct 30 ms 4908 KB Output is correct
32 Correct 40 ms 4868 KB Output is correct
33 Correct 31 ms 4896 KB Output is correct
34 Correct 35 ms 4940 KB Output is correct
35 Correct 30 ms 4896 KB Output is correct
36 Correct 2 ms 4436 KB Output is correct
37 Correct 2 ms 4436 KB Output is correct
38 Correct 3 ms 4428 KB Output is correct
39 Correct 2 ms 4428 KB Output is correct
40 Correct 3 ms 4564 KB Output is correct
41 Correct 4 ms 4564 KB Output is correct
42 Correct 4 ms 4696 KB Output is correct
43 Correct 5 ms 5076 KB Output is correct
44 Correct 11 ms 5768 KB Output is correct
45 Correct 14 ms 5972 KB Output is correct
46 Correct 55 ms 11752 KB Output is correct
47 Correct 30 ms 8968 KB Output is correct
48 Correct 42 ms 10248 KB Output is correct
49 Correct 52 ms 11948 KB Output is correct
50 Correct 68 ms 14604 KB Output is correct
51 Correct 53 ms 12008 KB Output is correct
52 Correct 32 ms 9636 KB Output is correct
53 Correct 50 ms 12512 KB Output is correct
54 Correct 43 ms 13532 KB Output is correct
55 Correct 26 ms 10184 KB Output is correct
56 Correct 66 ms 5320 KB Output is correct
57 Correct 159 ms 6364 KB Output is correct
58 Correct 293 ms 7324 KB Output is correct
59 Correct 408 ms 8280 KB Output is correct
60 Correct 559 ms 9316 KB Output is correct
61 Correct 719 ms 10524 KB Output is correct
62 Correct 873 ms 11584 KB Output is correct
63 Correct 1018 ms 12084 KB Output is correct
64 Correct 1335 ms 12648 KB Output is correct
65 Correct 2897 ms 12736 KB Output is correct
66 Correct 1403 ms 13032 KB Output is correct
67 Correct 1538 ms 14220 KB Output is correct
68 Correct 1659 ms 14532 KB Output is correct
69 Correct 1627 ms 14640 KB Output is correct
70 Correct 1702 ms 14632 KB Output is correct
71 Correct 1651 ms 14636 KB Output is correct
72 Correct 1881 ms 14632 KB Output is correct
73 Correct 1870 ms 14608 KB Output is correct
74 Correct 1878 ms 14648 KB Output is correct
75 Correct 1687 ms 14640 KB Output is correct
76 Correct 1653 ms 14636 KB Output is correct
77 Correct 1749 ms 14640 KB Output is correct
78 Correct 1691 ms 14712 KB Output is correct
79 Correct 1656 ms 14760 KB Output is correct
80 Correct 2974 ms 13480 KB Output is correct