Submission #596888

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

using namespace std;

typedef long long ll;

ll arr[100002];

struct segTree{
    int tree[400002];

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

    void update(int i, int l, int r, int x, int v){
        if(l==r) 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] = (arr[tree[i*2]] > arr[tree[i*2+1]]) ? tree[i*2] : tree[i*2+1];
    }

    int query(int i, int l, int r, int s, int e){
        if(r<s || e<l) return 0;
        if(s<=l && r<=e) return tree[i];
        int m = (l+r)>>1;
        int t1 = query(i*2, l, m, s, e), t2 = query(i*2+1, m+1, r, s, e);
        return (arr[t1] > arr[t2]) ? t1 : t2;
    }
} 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;

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

    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){
            fenwick.add(l, r-arr[l]);
            arr[l] = r;
            tree.update(1, 1, n, l, r);
            continue;
        }
        printf("%d\n", dnc(l, r));
    }
}

Compilation message

fish2.cpp: In function 'int main()':
fish2.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fish2.cpp:88:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
fish2.cpp:93:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
fish2.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         scanf("%d %d %d", &t, &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 4 ms 224 KB Output is correct
11 Correct 7 ms 256 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 2 ms 300 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 9 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 16 ms 2776 KB Output is correct
3 Correct 21 ms 2780 KB Output is correct
4 Correct 18 ms 2828 KB Output is correct
5 Correct 15 ms 2868 KB Output is correct
6 Correct 32 ms 2876 KB Output is correct
7 Correct 15 ms 2812 KB Output is correct
8 Correct 30 ms 2884 KB Output is correct
9 Correct 11 ms 2772 KB Output is correct
10 Correct 18 ms 2928 KB Output is correct
11 Correct 12 ms 2876 KB Output is correct
12 Correct 15 ms 2904 KB Output is correct
13 Correct 16 ms 2804 KB Output is correct
14 Correct 23 ms 4340 KB Output is correct
15 Correct 29 ms 4412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 4 ms 224 KB Output is correct
11 Correct 7 ms 256 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 2 ms 300 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 9 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 16 ms 2776 KB Output is correct
23 Correct 21 ms 2780 KB Output is correct
24 Correct 18 ms 2828 KB Output is correct
25 Correct 15 ms 2868 KB Output is correct
26 Correct 32 ms 2876 KB Output is correct
27 Correct 15 ms 2812 KB Output is correct
28 Correct 30 ms 2884 KB Output is correct
29 Correct 11 ms 2772 KB Output is correct
30 Correct 18 ms 2928 KB Output is correct
31 Correct 12 ms 2876 KB Output is correct
32 Correct 15 ms 2904 KB Output is correct
33 Correct 16 ms 2804 KB Output is correct
34 Correct 23 ms 4340 KB Output is correct
35 Correct 29 ms 4412 KB Output is correct
36 Correct 244 ms 3648 KB Output is correct
37 Correct 108 ms 2884 KB Output is correct
38 Correct 73 ms 2772 KB Output is correct
39 Correct 104 ms 3296 KB Output is correct
40 Correct 93 ms 2804 KB Output is correct
41 Correct 3131 ms 2876 KB Output is correct
42 Correct 3689 ms 2880 KB Output is correct
43 Correct 19 ms 2772 KB Output is correct
44 Correct 18 ms 2900 KB Output is correct
45 Correct 252 ms 3028 KB Output is correct
46 Correct 389 ms 2896 KB Output is correct
47 Correct 38 ms 2876 KB Output is correct
48 Correct 16 ms 2916 KB Output is correct
49 Correct 54 ms 3228 KB Output is correct
50 Correct 1337 ms 4320 KB Output is correct
51 Execution timed out 4090 ms 4420 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 16 ms 2776 KB Output is correct
3 Correct 21 ms 2780 KB Output is correct
4 Correct 18 ms 2828 KB Output is correct
5 Correct 15 ms 2868 KB Output is correct
6 Correct 32 ms 2876 KB Output is correct
7 Correct 15 ms 2812 KB Output is correct
8 Correct 30 ms 2884 KB Output is correct
9 Correct 11 ms 2772 KB Output is correct
10 Correct 18 ms 2928 KB Output is correct
11 Correct 12 ms 2876 KB Output is correct
12 Correct 15 ms 2904 KB Output is correct
13 Correct 16 ms 2804 KB Output is correct
14 Correct 23 ms 4340 KB Output is correct
15 Correct 29 ms 4412 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4083 ms 3248 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 16 ms 2776 KB Output is correct
3 Correct 21 ms 2780 KB Output is correct
4 Correct 18 ms 2828 KB Output is correct
5 Correct 15 ms 2868 KB Output is correct
6 Correct 32 ms 2876 KB Output is correct
7 Correct 15 ms 2812 KB Output is correct
8 Correct 30 ms 2884 KB Output is correct
9 Correct 11 ms 2772 KB Output is correct
10 Correct 18 ms 2928 KB Output is correct
11 Correct 12 ms 2876 KB Output is correct
12 Correct 15 ms 2904 KB Output is correct
13 Correct 16 ms 2804 KB Output is correct
14 Correct 23 ms 4340 KB Output is correct
15 Correct 29 ms 4412 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4085 ms 2892 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 4 ms 224 KB Output is correct
11 Correct 7 ms 256 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 2 ms 300 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 9 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 16 ms 2776 KB Output is correct
23 Correct 21 ms 2780 KB Output is correct
24 Correct 18 ms 2828 KB Output is correct
25 Correct 15 ms 2868 KB Output is correct
26 Correct 32 ms 2876 KB Output is correct
27 Correct 15 ms 2812 KB Output is correct
28 Correct 30 ms 2884 KB Output is correct
29 Correct 11 ms 2772 KB Output is correct
30 Correct 18 ms 2928 KB Output is correct
31 Correct 12 ms 2876 KB Output is correct
32 Correct 15 ms 2904 KB Output is correct
33 Correct 16 ms 2804 KB Output is correct
34 Correct 23 ms 4340 KB Output is correct
35 Correct 29 ms 4412 KB Output is correct
36 Correct 244 ms 3648 KB Output is correct
37 Correct 108 ms 2884 KB Output is correct
38 Correct 73 ms 2772 KB Output is correct
39 Correct 104 ms 3296 KB Output is correct
40 Correct 93 ms 2804 KB Output is correct
41 Correct 3131 ms 2876 KB Output is correct
42 Correct 3689 ms 2880 KB Output is correct
43 Correct 19 ms 2772 KB Output is correct
44 Correct 18 ms 2900 KB Output is correct
45 Correct 252 ms 3028 KB Output is correct
46 Correct 389 ms 2896 KB Output is correct
47 Correct 38 ms 2876 KB Output is correct
48 Correct 16 ms 2916 KB Output is correct
49 Correct 54 ms 3228 KB Output is correct
50 Correct 1337 ms 4320 KB Output is correct
51 Execution timed out 4090 ms 4420 KB Time limit exceeded
52 Halted 0 ms 0 KB -