Submission #597885

# Submission time Handle Problem Language Result Execution time Memory
597885 2022-07-17T04:03:46 Z qwerasdfzxcl Fish 2 (JOI22_fish2) C++14
31 / 100
1041 ms 20824 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
int n, a[100100];

struct Seg1{
    ll tree[200200], sz;
    void init(int n){
        sz = n;
        for (int i=sz;i<sz*2;i++) tree[i] = a[i-sz];
        for (int i=sz-1;i;i--) tree[i] = tree[i<<1] + tree[i<<1|1];
    }
    void update(int p, int x){
        for (tree[p+=sz]=x;p>1;p>>=1) tree[p>>1] = tree[p] + tree[p^1];
    }
    ll query(int l, int r){
        ++r;
        ll ret = 0;
        for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
            if (l&1) ret += tree[l++];
            if (r&1) ret += tree[--r];
        }
        return ret;
    }
}tree1;

struct Seg2{
    int tree[400400];
    void init(int i, int l, int r){
        if (l==r) {tree[i] = a[l]; return;}
        int m = (l+r)>>1;
        init(i<<1, l, m); init(i<<1|1, m+1, r);
        tree[i] = max(tree[i<<1], tree[i<<1|1]);
    }
    void update(int i, int l, int r, int p, int x){
        if (p<l || r<p) return;
        if (l==r) {tree[i] = x; return;}
        int m = (l+r)>>1;
        update(i<<1, l, m, p, x); update(i<<1|1, m+1, r, p, x);
        tree[i] = max(tree[i<<1], tree[i<<1|1]);
    }
    int left_bound(int i, int l, int r, int s, int e, ll x){
        if (r<s || e<l) return -1;
        if (tree[i] <= x) return -1;
        if (l==r) return l;

        int m = (l+r)>>1;
        int tmp = left_bound(i<<1|1, m+1, r, s, e, x);
        if (tmp!=-1) return tmp;
        return left_bound(i<<1, l, m, s, e, x);
    }
    int right_bound(int i, int l, int r, int s, int e, ll x){
        if (r<s || e<l) return -1;
        if (tree[i] <= x) return -1;
        if (l==r) return l;

        int m = (l+r)>>1;
        int tmp = right_bound(i<<1, l, m, s, e, x);
        if (tmp!=-1) return tmp;
        return right_bound(i<<1|1, m+1, r, s, e, x);
    }
}tree2;

struct Node{
    int mn, cnt;
    Node(){}
    Node(int _mn, int _cnt): mn(_mn), cnt(_cnt) {}
    Node operator + (const Node &N) const{
        if (mn < N.mn) return *this;
        if (mn > N.mn) return N;
        return Node(mn, cnt+N.cnt);
    }
};

struct Seg3{
    Node tree[400400];
    int lazy[400400];
    void init(int i, int l, int r){
        if (l==r) {tree[i] = Node(0, 1); return;}
        int m = (l+r)>>1;
        init(i<<1, l, m); init(i<<1|1, m+1, r);
        tree[i] = tree[i<<1] + tree[i<<1|1];
    }
    void propagate(int i, int l, int r){
        tree[i].mn += lazy[i];
        if (l!=r){
            lazy[i<<1] += lazy[i];
            lazy[i<<1|1] += lazy[i];
        }
        lazy[i] = 0;
    }
    void update(int i, int l, int r, int s, int e, int x){
        propagate(i, l, r);
        if (r<s || e<l) return;
        if (s<=l && r<=e){
            lazy[i] += x;
            propagate(i, l, r);
            return;
        }
        int m = (l+r)>>1;
        update(i<<1, l, m, s, e, x); update(i<<1|1, m+1, r, s, e, x);
        tree[i] = tree[i<<1] + tree[i<<1|1];
    }
    Node query(int i, int l, int r, int s, int e){
        propagate(i, l, r);
        if (r<s || e<l) return Node(1e9, 0);
        if (s<=l && r<=e) return tree[i];
        int m = (l+r)>>1;
        return query(i<<1, l, m, s, e) + query(i<<1|1, m+1, r, s, e);
    }
}tree3;

struct Seg4{
    vector<pair<int, int>> tree[400400];
    void update(int i, int l, int r, int s, int e){
        if (l==r) {
            tree[i].emplace_back(s, e);
            tree3.update(1, 1, n, s, e, 1);
            return;
        }

        int m = (l+r)>>1;
        if (e<=m) update(i<<1, l, m, s, e);
        else if (m+1<=s) update(i<<1|1, m+1, r, s, e);
        else{
            tree[i].emplace_back(s, e);
            tree3.update(1, 1, n, s, e, 1);
        }
    }
}tree4;

bool cmp(pair<int, int> &x, pair<int, int> &y){return x.second-x.first < y.second-y.first;}

bool ok(int l, int r, int s, int e){
    ll L = s==l?1e18:a[s-1], R = e==r?1e18:a[e+1];
    ll S = tree1.query(s, e);
    return S<L && S<R;
}

vector<int> getL(int l, int r, int s){
    vector<int> ret;
    int cur = s;
    while(true){
        int nxt = tree2.left_bound(1, 1, n, l, cur-1, tree1.query(cur, s));
        if (nxt==-1) break;
        ret.push_back(nxt+1);
        cur = nxt;
    }

    ret.push_back(l);
    return ret;
}

vector<int> getR(int l, int r, int s){
    vector<int> ret;
    int cur = s;
    while(true){
        int nxt = tree2.right_bound(1, 1, n, cur+1, r, tree1.query(s, cur));
        if (nxt==-1) break;
        //printf(" %d %d -> %d\n", s, cur, nxt);
        ret.push_back(nxt-1);
        cur = nxt;
    }
    ret.push_back(r);
    return ret;
}

void update(int x, int y){
    ///todo
}

int query(int l, int r){
    auto R0 = getR(l, r-1, l);
    auto L0 = getL(l+1, r, r);

    int nl = l, nr = r;
    for (auto &x:R0) if (ok(l, r, l, x)) nl = x+1;
    for (auto &x:L0) if (ok(l, r, x, r)) nr = x-1;

    return tree3.query(1, 1, n, nl, nr).cnt;
}

int main(){
    scanf("%d", &n);
    for (int i=1;i<=n;i++) scanf("%d", a+i);

    tree1.init(n+1);
    tree2.init(1, 1, n);
    tree3.init(1, 1, n);

    vector<pair<int, int>> P;
    for (int i=1;i<=n;i++){
        //printf("ok %d\n", i);
        auto R = getR(1, n, i);
        for (auto &x:R) if (ok(1, n, i, x)){
            P.emplace_back(i, x);
            //printf("%d %d\n", i, x);
        }
    }
    sort(P.begin(), P.end(), cmp);
    for (auto &[l, r]:P) tree4.update(1, 1, n, l, r);

    int q;
    scanf("%d", &q);
    while(q--){
        int op, x, y;
        scanf("%d %d %d", &op, &x, &y);
        if (op==1) update(x, y);
        else printf("%d\n", query(x, y));
    }
    return 0;
}

Compilation message

fish2.cpp: In function 'int main()':
fish2.cpp:202:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  202 |     for (auto &[l, r]:P) tree4.update(1, 1, n, l, r);
      |                ^
fish2.cpp:185:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fish2.cpp:186:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  186 |     for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                            ~~~~~^~~~~~~~~~~
fish2.cpp:205:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  205 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
fish2.cpp:208:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  208 |         scanf("%d %d %d", &op, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9696 KB Output is correct
2 Correct 279 ms 17680 KB Output is correct
3 Correct 365 ms 17772 KB Output is correct
4 Correct 277 ms 17664 KB Output is correct
5 Correct 410 ms 17692 KB Output is correct
6 Correct 84 ms 17392 KB Output is correct
7 Correct 185 ms 16720 KB Output is correct
8 Correct 74 ms 17444 KB Output is correct
9 Correct 193 ms 16724 KB Output is correct
10 Correct 182 ms 16708 KB Output is correct
11 Correct 266 ms 16872 KB Output is correct
12 Correct 111 ms 17220 KB Output is correct
13 Correct 105 ms 17176 KB Output is correct
14 Correct 92 ms 18280 KB Output is correct
15 Correct 98 ms 18212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9696 KB Output is correct
2 Correct 279 ms 17680 KB Output is correct
3 Correct 365 ms 17772 KB Output is correct
4 Correct 277 ms 17664 KB Output is correct
5 Correct 410 ms 17692 KB Output is correct
6 Correct 84 ms 17392 KB Output is correct
7 Correct 185 ms 16720 KB Output is correct
8 Correct 74 ms 17444 KB Output is correct
9 Correct 193 ms 16724 KB Output is correct
10 Correct 182 ms 16708 KB Output is correct
11 Correct 266 ms 16872 KB Output is correct
12 Correct 111 ms 17220 KB Output is correct
13 Correct 105 ms 17176 KB Output is correct
14 Correct 92 ms 18280 KB Output is correct
15 Correct 98 ms 18212 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 887 ms 19944 KB Output is correct
18 Correct 660 ms 20268 KB Output is correct
19 Correct 873 ms 19976 KB Output is correct
20 Correct 880 ms 19924 KB Output is correct
21 Correct 852 ms 19944 KB Output is correct
22 Correct 668 ms 20316 KB Output is correct
23 Correct 853 ms 19700 KB Output is correct
24 Correct 996 ms 19932 KB Output is correct
25 Correct 873 ms 19944 KB Output is correct
26 Correct 942 ms 20088 KB Output is correct
27 Correct 262 ms 20248 KB Output is correct
28 Correct 269 ms 20256 KB Output is correct
29 Correct 277 ms 20264 KB Output is correct
30 Correct 712 ms 18664 KB Output is correct
31 Correct 717 ms 18616 KB Output is correct
32 Correct 1012 ms 18948 KB Output is correct
33 Correct 545 ms 18992 KB Output is correct
34 Correct 1041 ms 18480 KB Output is correct
35 Correct 764 ms 18320 KB Output is correct
36 Correct 769 ms 19208 KB Output is correct
37 Correct 357 ms 19104 KB Output is correct
38 Correct 328 ms 19112 KB Output is correct
39 Correct 330 ms 20824 KB Output is correct
40 Correct 320 ms 20612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9696 KB Output is correct
2 Correct 279 ms 17680 KB Output is correct
3 Correct 365 ms 17772 KB Output is correct
4 Correct 277 ms 17664 KB Output is correct
5 Correct 410 ms 17692 KB Output is correct
6 Correct 84 ms 17392 KB Output is correct
7 Correct 185 ms 16720 KB Output is correct
8 Correct 74 ms 17444 KB Output is correct
9 Correct 193 ms 16724 KB Output is correct
10 Correct 182 ms 16708 KB Output is correct
11 Correct 266 ms 16872 KB Output is correct
12 Correct 111 ms 17220 KB Output is correct
13 Correct 105 ms 17176 KB Output is correct
14 Correct 92 ms 18280 KB Output is correct
15 Correct 98 ms 18212 KB Output is correct
16 Incorrect 5 ms 9684 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -