Submission #1081475

# Submission time Handle Problem Language Result Execution time Memory
1081475 2024-08-30T05:36:59 Z Evirir Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 7916 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
struct Hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 100005;
const int LG = 21;

int n,Q;
vector<ll> a;

struct DSU {
    struct Node {
        int p, sz;
        int alive;
        ll sum = 0;
    };
    vector<Node> comp;
    int cc;
    Node& operator[](int id) { return comp[rt(id)]; }
    DSU(int n = 0) {
        comp.resize(n); cc = n;
        forn(i, 0, n) { comp[i] = {i, 1, 1, a[i]}; }
    }
    inline int rt(int u) { return (comp[u].p == u) ? u : comp[u].p = rt(comp[u].p); }
    inline bool sameset(int u, int v) { return rt(u) == rt(v); }
    void merge(int u0, int v0) {
        int u = rt(u0); int v = rt(v0);
        if (u == v) return;
        int eaten = v, eater = u;
        if (comp[u].sz < comp[v].sz) swap(u, v);
        comp[v].p = u;
        comp[u].sz += comp[v].sz;
        if (comp[eaten].sum >= a[u0])
            comp[u].alive += comp[v].alive; // vore uwu
        else
            comp[u].alive = comp[eater].alive;
        comp[u].sum += comp[v].sum;
        cc--;
    }
};


int query(int l, int r)
{
    vector<ii> vp;
    fore(i,l,r) vp.pb({a[i], i});
    sort(all(vp));

    DSU dsu(n);
    for (const auto& [val, p] : vp)
    {
        if (p - 1 >= l && a[p] >= a[p - 1]) dsu.merge(p, p - 1);
        if (p + 1 <= r && a[p] >= a[p + 1]) dsu.merge(p, p + 1);
    }
    return dsu[l].alive;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);

    cin>>n;
    a.resize(n);
    forn(i,0,n) cin>>a[i];

    cin>>Q;
    forn(z,0,Q)
    {
        int t; cin>>t;
        if (t == 1)
        {
            int p; ll val; cin>>p>>val; p--;
            a[p] = val;
        }
        else
        {
            int l,r; cin>>l>>r; l--; r--;
            cout << query(l, r) << '\n';
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 484 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 12 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 17 ms 5240 KB Output is correct
3 Correct 16 ms 5072 KB Output is correct
4 Correct 17 ms 5076 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 22 ms 5076 KB Output is correct
7 Correct 17 ms 5264 KB Output is correct
8 Correct 18 ms 5076 KB Output is correct
9 Correct 15 ms 5076 KB Output is correct
10 Correct 17 ms 5076 KB Output is correct
11 Correct 13 ms 5076 KB Output is correct
12 Correct 17 ms 5268 KB Output is correct
13 Correct 16 ms 5076 KB Output is correct
14 Correct 17 ms 5076 KB Output is correct
15 Correct 18 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 484 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 12 ms 488 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 17 ms 5240 KB Output is correct
23 Correct 16 ms 5072 KB Output is correct
24 Correct 17 ms 5076 KB Output is correct
25 Correct 15 ms 5072 KB Output is correct
26 Correct 22 ms 5076 KB Output is correct
27 Correct 17 ms 5264 KB Output is correct
28 Correct 18 ms 5076 KB Output is correct
29 Correct 15 ms 5076 KB Output is correct
30 Correct 17 ms 5076 KB Output is correct
31 Correct 13 ms 5076 KB Output is correct
32 Correct 17 ms 5268 KB Output is correct
33 Correct 16 ms 5076 KB Output is correct
34 Correct 17 ms 5076 KB Output is correct
35 Correct 18 ms 5072 KB Output is correct
36 Correct 1419 ms 7916 KB Output is correct
37 Correct 2209 ms 7688 KB Output is correct
38 Correct 2500 ms 7684 KB Output is correct
39 Correct 569 ms 7676 KB Output is correct
40 Correct 2726 ms 7684 KB Output is correct
41 Correct 2150 ms 7688 KB Output is correct
42 Correct 2706 ms 7676 KB Output is correct
43 Correct 2262 ms 7684 KB Output is correct
44 Correct 2685 ms 7680 KB Output is correct
45 Correct 1552 ms 7672 KB Output is correct
46 Correct 2143 ms 7696 KB Output is correct
47 Correct 2756 ms 7700 KB Output is correct
48 Correct 905 ms 7668 KB Output is correct
49 Correct 3157 ms 7684 KB Output is correct
50 Correct 1715 ms 7644 KB Output is correct
51 Execution timed out 4037 ms 7168 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 17 ms 5240 KB Output is correct
3 Correct 16 ms 5072 KB Output is correct
4 Correct 17 ms 5076 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 22 ms 5076 KB Output is correct
7 Correct 17 ms 5264 KB Output is correct
8 Correct 18 ms 5076 KB Output is correct
9 Correct 15 ms 5076 KB Output is correct
10 Correct 17 ms 5076 KB Output is correct
11 Correct 13 ms 5076 KB Output is correct
12 Correct 17 ms 5268 KB Output is correct
13 Correct 16 ms 5076 KB Output is correct
14 Correct 17 ms 5076 KB Output is correct
15 Correct 18 ms 5072 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Execution timed out 4090 ms 7712 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 17 ms 5240 KB Output is correct
3 Correct 16 ms 5072 KB Output is correct
4 Correct 17 ms 5076 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 22 ms 5076 KB Output is correct
7 Correct 17 ms 5264 KB Output is correct
8 Correct 18 ms 5076 KB Output is correct
9 Correct 15 ms 5076 KB Output is correct
10 Correct 17 ms 5076 KB Output is correct
11 Correct 13 ms 5076 KB Output is correct
12 Correct 17 ms 5268 KB Output is correct
13 Correct 16 ms 5076 KB Output is correct
14 Correct 17 ms 5076 KB Output is correct
15 Correct 18 ms 5072 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Execution timed out 4050 ms 7408 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 484 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 12 ms 488 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 17 ms 5240 KB Output is correct
23 Correct 16 ms 5072 KB Output is correct
24 Correct 17 ms 5076 KB Output is correct
25 Correct 15 ms 5072 KB Output is correct
26 Correct 22 ms 5076 KB Output is correct
27 Correct 17 ms 5264 KB Output is correct
28 Correct 18 ms 5076 KB Output is correct
29 Correct 15 ms 5076 KB Output is correct
30 Correct 17 ms 5076 KB Output is correct
31 Correct 13 ms 5076 KB Output is correct
32 Correct 17 ms 5268 KB Output is correct
33 Correct 16 ms 5076 KB Output is correct
34 Correct 17 ms 5076 KB Output is correct
35 Correct 18 ms 5072 KB Output is correct
36 Correct 1419 ms 7916 KB Output is correct
37 Correct 2209 ms 7688 KB Output is correct
38 Correct 2500 ms 7684 KB Output is correct
39 Correct 569 ms 7676 KB Output is correct
40 Correct 2726 ms 7684 KB Output is correct
41 Correct 2150 ms 7688 KB Output is correct
42 Correct 2706 ms 7676 KB Output is correct
43 Correct 2262 ms 7684 KB Output is correct
44 Correct 2685 ms 7680 KB Output is correct
45 Correct 1552 ms 7672 KB Output is correct
46 Correct 2143 ms 7696 KB Output is correct
47 Correct 2756 ms 7700 KB Output is correct
48 Correct 905 ms 7668 KB Output is correct
49 Correct 3157 ms 7684 KB Output is correct
50 Correct 1715 ms 7644 KB Output is correct
51 Execution timed out 4037 ms 7168 KB Time limit exceeded
52 Halted 0 ms 0 KB -