Submission #791706

# Submission time Handle Problem Language Result Execution time Memory
791706 2023-07-24T08:59:16 Z eltu0815 Fish 2 (JOI22_fish2) C++14
25 / 100
4000 ms 4856 KB
#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1987654321)
 
using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
int n, q;
int arr[100005], l[100005], r[100005], ord[100005], chk[100005];
ll sum[100005];
pii tmp[100005];

void update_sum() {
    for(int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
}

void update_sort(int idx) {
    int j = 0, k = 0;
    for(int i = 1; i <= n; ++i) if(ord[i] == idx) j = i;
    for(int i = j; i < n; ++i) ord[i] = ord[i + 1];
    for(int i = 1; i < n; ++i) if(arr[ord[i]] >= arr[idx]) k = i;
    for(int i = n; i > k + 1; --i) ord[i] = ord[i - 1];
    ord[k + 1] = idx;
}

void update_r() {
    stack<int> st;
    for(int i = 1; i <= n; ++i) r[i] = n + 1;
    for(int i = 1; i <= n; ++i) {
        while(!st.empty() && arr[st.top()] < arr[i]) {
            r[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
}

void update_l() {
    stack<int> st;
    for(int i = 1; i <= n; ++i) l[i] = 0;
    for(int i = n; i >= 1; --i) {
        while(!st.empty() && arr[st.top()] < arr[i]) {
            l[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> arr[i];
    for(int i = 1; i <= n; ++i) tmp[i] = {arr[i], i};
    sort(tmp + 1, tmp + n + 1, greater<pii>());
    for(int i = 1; i <= n; ++i) ord[i] = tmp[i].second;
    update_sum(); update_l(); update_r();
    
    cin >> q;
    while(q--) {
        int t, a, b; cin >> t >> a >> b;
        if(t == 1) {
            arr[a] = b;
            update_sum(); update_l(); update_r();
            update_sort(a);
        }
        else {
            int ans = 0;
            for(int i = 1; i <= n; ++i) chk[i] = 0;
            for(int i = 1; i <= n; ++i) {
                if(ord[i] < a || ord[i] > b) continue;
                int lv = l[ord[i]] >= a ? arr[l[ord[i]]] : inf, li = max(l[ord[i]], a - 1);
                int rv = r[ord[i]] <= b ? arr[r[ord[i]]] : inf, ri = min(r[ord[i]], b + 1);
                ll sumv = sum[ri - 1] - sum[li];
                if(lv == inf && rv == inf) chk[ord[i]] = 1;
                else if(lv <= rv && lv != -1 && chk[li] && sumv >= lv) chk[ord[i]] = 1;
                else if(rv <= lv && rv != -1 && chk[ri] && sumv >= rv) chk[ord[i]] = 1;
                ans += chk[ord[i]];
            }
            cout << ans << '\n';
        }
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 276 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 17 ms 4308 KB Output is correct
3 Correct 15 ms 4140 KB Output is correct
4 Correct 18 ms 4352 KB Output is correct
5 Correct 16 ms 4044 KB Output is correct
6 Correct 21 ms 4756 KB Output is correct
7 Correct 16 ms 3924 KB Output is correct
8 Correct 20 ms 4856 KB Output is correct
9 Correct 16 ms 4052 KB Output is correct
10 Correct 21 ms 4380 KB Output is correct
11 Correct 17 ms 4108 KB Output is correct
12 Correct 17 ms 4092 KB Output is correct
13 Correct 20 ms 4060 KB Output is correct
14 Correct 18 ms 4392 KB Output is correct
15 Correct 19 ms 4396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 276 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 17 ms 4308 KB Output is correct
23 Correct 15 ms 4140 KB Output is correct
24 Correct 18 ms 4352 KB Output is correct
25 Correct 16 ms 4044 KB Output is correct
26 Correct 21 ms 4756 KB Output is correct
27 Correct 16 ms 3924 KB Output is correct
28 Correct 20 ms 4856 KB Output is correct
29 Correct 16 ms 4052 KB Output is correct
30 Correct 21 ms 4380 KB Output is correct
31 Correct 17 ms 4108 KB Output is correct
32 Correct 17 ms 4092 KB Output is correct
33 Correct 20 ms 4060 KB Output is correct
34 Correct 18 ms 4392 KB Output is correct
35 Correct 19 ms 4396 KB Output is correct
36 Correct 812 ms 4436 KB Output is correct
37 Correct 613 ms 4168 KB Output is correct
38 Correct 358 ms 4180 KB Output is correct
39 Correct 1022 ms 4436 KB Output is correct
40 Correct 386 ms 4300 KB Output is correct
41 Correct 1562 ms 4804 KB Output is correct
42 Correct 1233 ms 4804 KB Output is correct
43 Correct 1052 ms 4044 KB Output is correct
44 Correct 587 ms 4040 KB Output is correct
45 Correct 840 ms 4412 KB Output is correct
46 Correct 734 ms 4404 KB Output is correct
47 Correct 323 ms 4116 KB Output is correct
48 Correct 2023 ms 4100 KB Output is correct
49 Correct 624 ms 4092 KB Output is correct
50 Correct 1171 ms 4456 KB Output is correct
51 Correct 1541 ms 4452 KB Output is correct
52 Correct 1201 ms 4580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 17 ms 4308 KB Output is correct
3 Correct 15 ms 4140 KB Output is correct
4 Correct 18 ms 4352 KB Output is correct
5 Correct 16 ms 4044 KB Output is correct
6 Correct 21 ms 4756 KB Output is correct
7 Correct 16 ms 3924 KB Output is correct
8 Correct 20 ms 4856 KB Output is correct
9 Correct 16 ms 4052 KB Output is correct
10 Correct 21 ms 4380 KB Output is correct
11 Correct 17 ms 4108 KB Output is correct
12 Correct 17 ms 4092 KB Output is correct
13 Correct 20 ms 4060 KB Output is correct
14 Correct 18 ms 4392 KB Output is correct
15 Correct 19 ms 4396 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Execution timed out 4042 ms 4576 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 17 ms 4308 KB Output is correct
3 Correct 15 ms 4140 KB Output is correct
4 Correct 18 ms 4352 KB Output is correct
5 Correct 16 ms 4044 KB Output is correct
6 Correct 21 ms 4756 KB Output is correct
7 Correct 16 ms 3924 KB Output is correct
8 Correct 20 ms 4856 KB Output is correct
9 Correct 16 ms 4052 KB Output is correct
10 Correct 21 ms 4380 KB Output is correct
11 Correct 17 ms 4108 KB Output is correct
12 Correct 17 ms 4092 KB Output is correct
13 Correct 20 ms 4060 KB Output is correct
14 Correct 18 ms 4392 KB Output is correct
15 Correct 19 ms 4396 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Execution timed out 4057 ms 4576 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 276 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 17 ms 4308 KB Output is correct
23 Correct 15 ms 4140 KB Output is correct
24 Correct 18 ms 4352 KB Output is correct
25 Correct 16 ms 4044 KB Output is correct
26 Correct 21 ms 4756 KB Output is correct
27 Correct 16 ms 3924 KB Output is correct
28 Correct 20 ms 4856 KB Output is correct
29 Correct 16 ms 4052 KB Output is correct
30 Correct 21 ms 4380 KB Output is correct
31 Correct 17 ms 4108 KB Output is correct
32 Correct 17 ms 4092 KB Output is correct
33 Correct 20 ms 4060 KB Output is correct
34 Correct 18 ms 4392 KB Output is correct
35 Correct 19 ms 4396 KB Output is correct
36 Correct 812 ms 4436 KB Output is correct
37 Correct 613 ms 4168 KB Output is correct
38 Correct 358 ms 4180 KB Output is correct
39 Correct 1022 ms 4436 KB Output is correct
40 Correct 386 ms 4300 KB Output is correct
41 Correct 1562 ms 4804 KB Output is correct
42 Correct 1233 ms 4804 KB Output is correct
43 Correct 1052 ms 4044 KB Output is correct
44 Correct 587 ms 4040 KB Output is correct
45 Correct 840 ms 4412 KB Output is correct
46 Correct 734 ms 4404 KB Output is correct
47 Correct 323 ms 4116 KB Output is correct
48 Correct 2023 ms 4100 KB Output is correct
49 Correct 624 ms 4092 KB Output is correct
50 Correct 1171 ms 4456 KB Output is correct
51 Correct 1541 ms 4452 KB Output is correct
52 Correct 1201 ms 4580 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Execution timed out 4042 ms 4576 KB Time limit exceeded
55 Halted 0 ms 0 KB -