Submission #596793

# Submission time Handle Problem Language Result Execution time Memory
596793 2022-07-15T05:28:01 Z 반딧불(#8447) Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 7812 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct segTree{
    pair<ll, int> tree[400002];

    void init(int i, int l, int r, ll* A){
        if(l==r){
            tree[i] = make_pair(A[l], l);
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m, A);
        init(i*2+1, m+1, r, A);
        tree[i] = max(tree[i*2], tree[i*2+1]);
    }

    void update(int i, int l, int r, int x, int v){
        if(l==r){
            tree[i] = make_pair(v, l);
            return;
        }
        int m = (l+r)>>1;
        if(x<=m) update(i*2, l, m, x, v);
        else update(i*2+1, m+1, r, x, v);
        tree[i] = max(tree[i*2], tree[i*2+1]);
    }

    pair<ll, int> query(int i, int l, int r, int s, int e){
        if(r<s || e<l) return make_pair(0, 0);
        if(s<=l && r<=e) return tree[i];
        int m = (l+r)>>1;
        return max(query(i*2, l, m, s, e), query(i*2+1, m+1, r, s, e));
    }
} tree;

struct Fenwick{
    int n;
    ll tree[100002];

    void init(int _n){
        n = _n;
        for(int i=0; i<=n; i++) tree[i] = 0;
    }

    void add(int x, int v){
        while(x<=n){
            tree[x] += v;
            x += x&-x;
        }
    }

    ll sum(int x){
        ll ret = 0;
        while(x){
            ret += tree[x];
            x -= x&-x;
        }
        return ret;
    }

    ll sum(int l, int r){
        return sum(r) - sum(l-1);
    }
} fenwick;

int n, q;
ll arr[100002];

int dnc(int l, int r, ll lim = 0){
    if(l>r) return 0;
    pair<ll, int> tmp = tree.query(1, 1, n, l, r);
    ll sum = fenwick.sum(l, r);
    if(sum < lim) return 0;
    int ret = 1;

    int m = tmp.second;
    ll tsum = fenwick.sum(l, m-1);
    if(tsum >= arr[m]) ret += dnc(l, m-1, arr[m]);
    tsum = fenwick.sum(m+1, r);
    if(tsum >= arr[m]) ret += dnc(m+1, r, arr[m]);
    return ret;
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
    tree.init(1, 1, n, arr);
    fenwick.init(n);
    for(int i=1; i<=n; i++) fenwick.add(i, arr[i]);

    scanf("%d", &q);
    while(q--){
        int t, l, r;
        scanf("%d %d %d", &t, &l, &r);
        if(t==1){
            tree.update(1, 1, n, l, r);
            fenwick.add(l, r-arr[l]);
            arr[l] = r;
            continue;
        }
        printf("%d\n", dnc(l, r));
    }
}

Compilation message

fish2.cpp: In function 'int main()':
fish2.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fish2.cpp:90:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
fish2.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
fish2.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         scanf("%d %d %d", &t, &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 16 ms 6052 KB Output is correct
3 Correct 13 ms 6196 KB Output is correct
4 Correct 19 ms 6452 KB Output is correct
5 Correct 14 ms 6204 KB Output is correct
6 Correct 29 ms 6848 KB Output is correct
7 Correct 13 ms 6092 KB Output is correct
8 Correct 28 ms 6956 KB Output is correct
9 Correct 16 ms 6156 KB Output is correct
10 Correct 18 ms 6484 KB Output is correct
11 Correct 17 ms 6228 KB Output is correct
12 Correct 15 ms 6152 KB Output is correct
13 Correct 12 ms 6100 KB Output is correct
14 Correct 22 ms 7304 KB Output is correct
15 Correct 22 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 16 ms 6052 KB Output is correct
23 Correct 13 ms 6196 KB Output is correct
24 Correct 19 ms 6452 KB Output is correct
25 Correct 14 ms 6204 KB Output is correct
26 Correct 29 ms 6848 KB Output is correct
27 Correct 13 ms 6092 KB Output is correct
28 Correct 28 ms 6956 KB Output is correct
29 Correct 16 ms 6156 KB Output is correct
30 Correct 18 ms 6484 KB Output is correct
31 Correct 17 ms 6228 KB Output is correct
32 Correct 15 ms 6152 KB Output is correct
33 Correct 12 ms 6100 KB Output is correct
34 Correct 22 ms 7304 KB Output is correct
35 Correct 22 ms 7252 KB Output is correct
36 Correct 184 ms 6936 KB Output is correct
37 Correct 121 ms 6304 KB Output is correct
38 Correct 78 ms 6304 KB Output is correct
39 Correct 93 ms 6756 KB Output is correct
40 Correct 74 ms 6304 KB Output is correct
41 Correct 2882 ms 6936 KB Output is correct
42 Correct 3684 ms 7024 KB Output is correct
43 Correct 21 ms 6100 KB Output is correct
44 Correct 24 ms 6196 KB Output is correct
45 Correct 270 ms 6608 KB Output is correct
46 Correct 402 ms 6604 KB Output is correct
47 Correct 40 ms 6244 KB Output is correct
48 Correct 18 ms 6228 KB Output is correct
49 Correct 57 ms 6388 KB Output is correct
50 Correct 1486 ms 7328 KB Output is correct
51 Execution timed out 4064 ms 7436 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 16 ms 6052 KB Output is correct
3 Correct 13 ms 6196 KB Output is correct
4 Correct 19 ms 6452 KB Output is correct
5 Correct 14 ms 6204 KB Output is correct
6 Correct 29 ms 6848 KB Output is correct
7 Correct 13 ms 6092 KB Output is correct
8 Correct 28 ms 6956 KB Output is correct
9 Correct 16 ms 6156 KB Output is correct
10 Correct 18 ms 6484 KB Output is correct
11 Correct 17 ms 6228 KB Output is correct
12 Correct 15 ms 6152 KB Output is correct
13 Correct 12 ms 6100 KB Output is correct
14 Correct 22 ms 7304 KB Output is correct
15 Correct 22 ms 7252 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Execution timed out 4043 ms 7812 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 16 ms 6052 KB Output is correct
3 Correct 13 ms 6196 KB Output is correct
4 Correct 19 ms 6452 KB Output is correct
5 Correct 14 ms 6204 KB Output is correct
6 Correct 29 ms 6848 KB Output is correct
7 Correct 13 ms 6092 KB Output is correct
8 Correct 28 ms 6956 KB Output is correct
9 Correct 16 ms 6156 KB Output is correct
10 Correct 18 ms 6484 KB Output is correct
11 Correct 17 ms 6228 KB Output is correct
12 Correct 15 ms 6152 KB Output is correct
13 Correct 12 ms 6100 KB Output is correct
14 Correct 22 ms 7304 KB Output is correct
15 Correct 22 ms 7252 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4045 ms 6848 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 16 ms 6052 KB Output is correct
23 Correct 13 ms 6196 KB Output is correct
24 Correct 19 ms 6452 KB Output is correct
25 Correct 14 ms 6204 KB Output is correct
26 Correct 29 ms 6848 KB Output is correct
27 Correct 13 ms 6092 KB Output is correct
28 Correct 28 ms 6956 KB Output is correct
29 Correct 16 ms 6156 KB Output is correct
30 Correct 18 ms 6484 KB Output is correct
31 Correct 17 ms 6228 KB Output is correct
32 Correct 15 ms 6152 KB Output is correct
33 Correct 12 ms 6100 KB Output is correct
34 Correct 22 ms 7304 KB Output is correct
35 Correct 22 ms 7252 KB Output is correct
36 Correct 184 ms 6936 KB Output is correct
37 Correct 121 ms 6304 KB Output is correct
38 Correct 78 ms 6304 KB Output is correct
39 Correct 93 ms 6756 KB Output is correct
40 Correct 74 ms 6304 KB Output is correct
41 Correct 2882 ms 6936 KB Output is correct
42 Correct 3684 ms 7024 KB Output is correct
43 Correct 21 ms 6100 KB Output is correct
44 Correct 24 ms 6196 KB Output is correct
45 Correct 270 ms 6608 KB Output is correct
46 Correct 402 ms 6604 KB Output is correct
47 Correct 40 ms 6244 KB Output is correct
48 Correct 18 ms 6228 KB Output is correct
49 Correct 57 ms 6388 KB Output is correct
50 Correct 1486 ms 7328 KB Output is correct
51 Execution timed out 4064 ms 7436 KB Time limit exceeded
52 Halted 0 ms 0 KB -