답안 #876131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876131 2023-11-21T09:59:01 Z danikoynov Fish 2 (JOI22_fish2) C++14
5 / 100
4000 ms 2908 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;
struct Treap
{
    struct Node
    {
        ll key;
        int pr, sz;
        Node *lf, *rf;

        Node(ll _key)
        {
            key = _key;
            pr = rand();
            lf = rf = NULL;
        }

        void con()
        {
            sz = 1;
            if (lf) sz = sz + lf -> sz;
            if (rf) sz = sz + rf -> sz;
        }
    };

    Node *root;

    void Split(Node *T, Node *&L, Node *&R, ll value)
    {
        if (T == NULL)
        {
            L = R = NULL;
            return;
        }

        if (T -> key <= value)
        {
            L = T;
            Split(T -> rf, L -> rf, R, value);
        }
        else
        {
            R = T;
            Split(T -> lf, L, R -> lf, value);
        }

        T -> con();
    }

    void Merge(Node *&T, Node *L, Node *R)
    {
        if (L == NULL && R == NULL)
        {
            T = NULL;
            return;
        }

        if (L == NULL)
        {
            T = R;
            return;
        }

        if (R == NULL)
        {
            T = L;
            return;
        }

        if (L -> pr > R -> pr)
        {
            T = L;
            Merge(T -> rf, L -> rf, R);
        }
        else
        {
            T = R;
            Merge(T -> lf, L, R -> lf);
        }

        T -> con();
    }
};

int n, q;
ll a[maxn];
void input()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    cin >> q;

}

ll arr[maxn];
void solve_query(int l, int r)
{
    int len = r - l + 1;
    for (int i = l; i <= r; i ++)
        arr[i - l + 1] = a[i];


    ll last = 1, ans = 0;
    for (int i = 1; i <= len; i ++)
    {
        int lf = i - 1, rf = i + 1;
        ll sum = arr[i];
        while(lf > 0 || rf <= len)
        {
            if (lf > 0 && sum >= arr[lf])
                sum += arr[lf], lf --;
            else
            if (rf <= len && sum >= arr[rf])
                sum += arr[rf], rf ++;
            else
                break;
        }

        if (lf == 0 && rf == len + 1)
            ans ++;
    }

    cout << ans << endl;
}

void simulate()
{
    for (int i = 1; i <= q; i ++)
    {
        int type;
        cin >> type;
        if (type == 1)
        {
            int idx;
            ll x;
            cin >> idx >> x;
            a[idx] = x;
        }
        else
        {
            int l, r;
            cin >> l >> r;
            solve_query(l, r);
        }
    }
}
void solve()
{
    input();
    simulate();
}

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    speed();
    solve();
    return 0;
}

Compilation message

fish2.cpp: In function 'void solve_query(int, int)':
fish2.cpp:110:8: warning: unused variable 'last' [-Wunused-variable]
  110 |     ll last = 1, ans = 0;
      |        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 33 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 557 ms 2584 KB Output is correct
3 Correct 60 ms 2140 KB Output is correct
4 Correct 508 ms 2644 KB Output is correct
5 Correct 62 ms 2140 KB Output is correct
6 Execution timed out 4038 ms 2908 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 33 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 557 ms 2584 KB Output is correct
23 Correct 60 ms 2140 KB Output is correct
24 Correct 508 ms 2644 KB Output is correct
25 Correct 62 ms 2140 KB Output is correct
26 Execution timed out 4038 ms 2908 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 557 ms 2584 KB Output is correct
3 Correct 60 ms 2140 KB Output is correct
4 Correct 508 ms 2644 KB Output is correct
5 Correct 62 ms 2140 KB Output is correct
6 Execution timed out 4038 ms 2908 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 557 ms 2584 KB Output is correct
3 Correct 60 ms 2140 KB Output is correct
4 Correct 508 ms 2644 KB Output is correct
5 Correct 62 ms 2140 KB Output is correct
6 Execution timed out 4038 ms 2908 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 348 KB Output is correct
20 Correct 33 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 557 ms 2584 KB Output is correct
23 Correct 60 ms 2140 KB Output is correct
24 Correct 508 ms 2644 KB Output is correct
25 Correct 62 ms 2140 KB Output is correct
26 Execution timed out 4038 ms 2908 KB Time limit exceeded
27 Halted 0 ms 0 KB -