Submission #876300

# Submission time Handle Problem Language Result Execution time Memory
876300 2023-11-21T14:02:14 Z danikoynov Fish 2 (JOI22_fish2) C++14
25 / 100
4000 ms 5080 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;


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

}

vector < pair < int, int > > ranges;
void get_ranges()
{

    for (int i = 1; i <= n; i ++)
        pref[i] = pref[i - 1] + a[i];
    pref[n + 1] = pref[n];

    ranges.clear();
    stack < int > st;
    st.push(0);
    for (int i = 1; i <= n; i ++)
    {
        while(!st.empty() && a[st.top()] < a[i])
            st.pop();


        if (pref[i - 1] - pref[st.top()] < a[i])
            ranges.push_back({st.top() + 1, i - 1});

        st.push(i);
    }

    while(!st.empty())
        st.pop();
    st.push(n + 1);
    for (int i = n; i > 0; i --)
    {
        while(!st.empty() && a[st.top()] < a[i])
            st.pop();

        if (pref[st.top() - 1] - pref[i] < a[i])
            ranges.push_back({i + 1, st.top() - 1});

        st.push(i);
    }
}

int b[maxn];
void solve_query(int left, int right)
{
    get_ranges();
    for (int i = 1; i <= n; i ++)
        b[i] = 0;
    for (pair < int, int > cur : ranges)
        for (int i = cur.first; i <= cur.second; i ++)
        b[i] ++;
    //for (pair < int, int > cur : ranges)
      //  cout << cur.first << " : " << cur.second << endl;

    int lb = left, rb = right;
    for (int i = left; i <= right; i ++)
    {
        if (a[i] > pref[i - 1] - pref[left - 1])
            lb = max(lb, i);
        if (a[i] > pref[right] - pref[i])
            rb = min(rb, i);
    }

    int minx = 1e9;
    for (int i = lb; i <= rb; i ++)
        minx = min(minx, b[i]);

    int ans = 0;
    for (int i = lb; i <= rb; i ++)
        if (b[i] == minx)
        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;
}
# 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 2 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 2 ms 484 KB Output is correct
13 Correct 5 ms 472 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 6 ms 348 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 5 ms 508 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 4568 KB Output is correct
3 Correct 10 ms 4568 KB Output is correct
4 Correct 11 ms 4700 KB Output is correct
5 Correct 10 ms 4564 KB Output is correct
6 Correct 13 ms 5080 KB Output is correct
7 Correct 11 ms 4312 KB Output is correct
8 Correct 13 ms 5008 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 11 ms 4700 KB Output is correct
11 Correct 10 ms 4336 KB Output is correct
12 Correct 10 ms 4564 KB Output is correct
13 Correct 10 ms 4312 KB Output is correct
14 Correct 13 ms 4784 KB Output is correct
15 Correct 12 ms 4828 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 2 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 2 ms 484 KB Output is correct
13 Correct 5 ms 472 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 6 ms 348 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 5 ms 508 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 11 ms 4568 KB Output is correct
23 Correct 10 ms 4568 KB Output is correct
24 Correct 11 ms 4700 KB Output is correct
25 Correct 10 ms 4564 KB Output is correct
26 Correct 13 ms 5080 KB Output is correct
27 Correct 11 ms 4312 KB Output is correct
28 Correct 13 ms 5008 KB Output is correct
29 Correct 9 ms 4308 KB Output is correct
30 Correct 11 ms 4700 KB Output is correct
31 Correct 10 ms 4336 KB Output is correct
32 Correct 10 ms 4564 KB Output is correct
33 Correct 10 ms 4312 KB Output is correct
34 Correct 13 ms 4784 KB Output is correct
35 Correct 12 ms 4828 KB Output is correct
36 Correct 1308 ms 4820 KB Output is correct
37 Correct 2245 ms 4568 KB Output is correct
38 Correct 2836 ms 4568 KB Output is correct
39 Correct 568 ms 4568 KB Output is correct
40 Correct 2903 ms 4568 KB Output is correct
41 Correct 2391 ms 5076 KB Output is correct
42 Correct 3068 ms 5076 KB Output is correct
43 Correct 2388 ms 4312 KB Output is correct
44 Correct 3107 ms 4312 KB Output is correct
45 Correct 1468 ms 4808 KB Output is correct
46 Correct 2035 ms 4580 KB Output is correct
47 Correct 2692 ms 4312 KB Output is correct
48 Correct 1024 ms 4316 KB Output is correct
49 Correct 3213 ms 4568 KB Output is correct
50 Correct 1394 ms 4828 KB Output is correct
51 Correct 2710 ms 5080 KB Output is correct
52 Correct 2719 ms 4828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 4568 KB Output is correct
3 Correct 10 ms 4568 KB Output is correct
4 Correct 11 ms 4700 KB Output is correct
5 Correct 10 ms 4564 KB Output is correct
6 Correct 13 ms 5080 KB Output is correct
7 Correct 11 ms 4312 KB Output is correct
8 Correct 13 ms 5008 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 11 ms 4700 KB Output is correct
11 Correct 10 ms 4336 KB Output is correct
12 Correct 10 ms 4564 KB Output is correct
13 Correct 10 ms 4312 KB Output is correct
14 Correct 13 ms 4784 KB Output is correct
15 Correct 12 ms 4828 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4064 ms 4544 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 11 ms 4568 KB Output is correct
3 Correct 10 ms 4568 KB Output is correct
4 Correct 11 ms 4700 KB Output is correct
5 Correct 10 ms 4564 KB Output is correct
6 Correct 13 ms 5080 KB Output is correct
7 Correct 11 ms 4312 KB Output is correct
8 Correct 13 ms 5008 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 11 ms 4700 KB Output is correct
11 Correct 10 ms 4336 KB Output is correct
12 Correct 10 ms 4564 KB Output is correct
13 Correct 10 ms 4312 KB Output is correct
14 Correct 13 ms 4784 KB Output is correct
15 Correct 12 ms 4828 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4074 ms 4884 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 2 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 2 ms 484 KB Output is correct
13 Correct 5 ms 472 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 6 ms 348 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 5 ms 508 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 11 ms 4568 KB Output is correct
23 Correct 10 ms 4568 KB Output is correct
24 Correct 11 ms 4700 KB Output is correct
25 Correct 10 ms 4564 KB Output is correct
26 Correct 13 ms 5080 KB Output is correct
27 Correct 11 ms 4312 KB Output is correct
28 Correct 13 ms 5008 KB Output is correct
29 Correct 9 ms 4308 KB Output is correct
30 Correct 11 ms 4700 KB Output is correct
31 Correct 10 ms 4336 KB Output is correct
32 Correct 10 ms 4564 KB Output is correct
33 Correct 10 ms 4312 KB Output is correct
34 Correct 13 ms 4784 KB Output is correct
35 Correct 12 ms 4828 KB Output is correct
36 Correct 1308 ms 4820 KB Output is correct
37 Correct 2245 ms 4568 KB Output is correct
38 Correct 2836 ms 4568 KB Output is correct
39 Correct 568 ms 4568 KB Output is correct
40 Correct 2903 ms 4568 KB Output is correct
41 Correct 2391 ms 5076 KB Output is correct
42 Correct 3068 ms 5076 KB Output is correct
43 Correct 2388 ms 4312 KB Output is correct
44 Correct 3107 ms 4312 KB Output is correct
45 Correct 1468 ms 4808 KB Output is correct
46 Correct 2035 ms 4580 KB Output is correct
47 Correct 2692 ms 4312 KB Output is correct
48 Correct 1024 ms 4316 KB Output is correct
49 Correct 3213 ms 4568 KB Output is correct
50 Correct 1394 ms 4828 KB Output is correct
51 Correct 2710 ms 5080 KB Output is correct
52 Correct 2719 ms 4828 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Execution timed out 4064 ms 4544 KB Time limit exceeded
55 Halted 0 ms 0 KB -