답안 #1081474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081474 2024-08-30T05:35:22 Z Evirir Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 7972 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;

#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 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 4 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 4 ms 492 KB Output is correct
9 Correct 6 ms 488 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 488 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 13 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 5256 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5260 KB Output is correct
5 Correct 16 ms 5076 KB Output is correct
6 Correct 20 ms 5264 KB Output is correct
7 Correct 18 ms 5076 KB Output is correct
8 Correct 19 ms 5072 KB Output is correct
9 Correct 16 ms 5260 KB Output is correct
10 Correct 23 ms 5092 KB Output is correct
11 Correct 18 ms 5076 KB Output is correct
12 Correct 21 ms 5260 KB Output is correct
13 Correct 18 ms 5076 KB Output is correct
14 Correct 18 ms 5208 KB Output is correct
15 Correct 18 ms 5152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 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 4 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 4 ms 492 KB Output is correct
9 Correct 6 ms 488 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 488 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 13 ms 492 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 18 ms 5256 KB Output is correct
23 Correct 17 ms 5072 KB Output is correct
24 Correct 19 ms 5260 KB Output is correct
25 Correct 16 ms 5076 KB Output is correct
26 Correct 20 ms 5264 KB Output is correct
27 Correct 18 ms 5076 KB Output is correct
28 Correct 19 ms 5072 KB Output is correct
29 Correct 16 ms 5260 KB Output is correct
30 Correct 23 ms 5092 KB Output is correct
31 Correct 18 ms 5076 KB Output is correct
32 Correct 21 ms 5260 KB Output is correct
33 Correct 18 ms 5076 KB Output is correct
34 Correct 18 ms 5208 KB Output is correct
35 Correct 18 ms 5152 KB Output is correct
36 Correct 1600 ms 7712 KB Output is correct
37 Correct 2432 ms 7684 KB Output is correct
38 Correct 2804 ms 7840 KB Output is correct
39 Correct 627 ms 7672 KB Output is correct
40 Correct 3085 ms 7684 KB Output is correct
41 Correct 2415 ms 7676 KB Output is correct
42 Correct 3018 ms 7672 KB Output is correct
43 Correct 2556 ms 7972 KB Output is correct
44 Correct 2972 ms 7692 KB Output is correct
45 Correct 1747 ms 7688 KB Output is correct
46 Correct 2436 ms 7780 KB Output is correct
47 Correct 3104 ms 7704 KB Output is correct
48 Correct 1000 ms 7688 KB Output is correct
49 Correct 3505 ms 7684 KB Output is correct
50 Correct 1891 ms 7680 KB Output is correct
51 Execution timed out 4051 ms 7160 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 5256 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5260 KB Output is correct
5 Correct 16 ms 5076 KB Output is correct
6 Correct 20 ms 5264 KB Output is correct
7 Correct 18 ms 5076 KB Output is correct
8 Correct 19 ms 5072 KB Output is correct
9 Correct 16 ms 5260 KB Output is correct
10 Correct 23 ms 5092 KB Output is correct
11 Correct 18 ms 5076 KB Output is correct
12 Correct 21 ms 5260 KB Output is correct
13 Correct 18 ms 5076 KB Output is correct
14 Correct 18 ms 5208 KB Output is correct
15 Correct 18 ms 5152 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4058 ms 7936 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 5256 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5260 KB Output is correct
5 Correct 16 ms 5076 KB Output is correct
6 Correct 20 ms 5264 KB Output is correct
7 Correct 18 ms 5076 KB Output is correct
8 Correct 19 ms 5072 KB Output is correct
9 Correct 16 ms 5260 KB Output is correct
10 Correct 23 ms 5092 KB Output is correct
11 Correct 18 ms 5076 KB Output is correct
12 Correct 21 ms 5260 KB Output is correct
13 Correct 18 ms 5076 KB Output is correct
14 Correct 18 ms 5208 KB Output is correct
15 Correct 18 ms 5152 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Execution timed out 4088 ms 7228 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 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 4 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 4 ms 492 KB Output is correct
9 Correct 6 ms 488 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 488 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 13 ms 492 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 18 ms 5256 KB Output is correct
23 Correct 17 ms 5072 KB Output is correct
24 Correct 19 ms 5260 KB Output is correct
25 Correct 16 ms 5076 KB Output is correct
26 Correct 20 ms 5264 KB Output is correct
27 Correct 18 ms 5076 KB Output is correct
28 Correct 19 ms 5072 KB Output is correct
29 Correct 16 ms 5260 KB Output is correct
30 Correct 23 ms 5092 KB Output is correct
31 Correct 18 ms 5076 KB Output is correct
32 Correct 21 ms 5260 KB Output is correct
33 Correct 18 ms 5076 KB Output is correct
34 Correct 18 ms 5208 KB Output is correct
35 Correct 18 ms 5152 KB Output is correct
36 Correct 1600 ms 7712 KB Output is correct
37 Correct 2432 ms 7684 KB Output is correct
38 Correct 2804 ms 7840 KB Output is correct
39 Correct 627 ms 7672 KB Output is correct
40 Correct 3085 ms 7684 KB Output is correct
41 Correct 2415 ms 7676 KB Output is correct
42 Correct 3018 ms 7672 KB Output is correct
43 Correct 2556 ms 7972 KB Output is correct
44 Correct 2972 ms 7692 KB Output is correct
45 Correct 1747 ms 7688 KB Output is correct
46 Correct 2436 ms 7780 KB Output is correct
47 Correct 3104 ms 7704 KB Output is correct
48 Correct 1000 ms 7688 KB Output is correct
49 Correct 3505 ms 7684 KB Output is correct
50 Correct 1891 ms 7680 KB Output is correct
51 Execution timed out 4051 ms 7160 KB Time limit exceeded
52 Halted 0 ms 0 KB -