Submission #795158

# Submission time Handle Problem Language Result Execution time Memory
795158 2023-07-27T07:11:19 Z eltu0815 Fish 2 (JOI22_fish2) C++14
5 / 100
4000 ms 3156 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];
ll sum[100005];
 
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) sum[i] = sum[i - 1] + arr[i];
    
    cin >> q;
    while(q--) {
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 1) {
            arr[a] = b;
            for(int i = a; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
        }
        else {
            vector<pii> tmp;
            stack<int> st;
            for(int i = a; i <= b; ++i) {
                while(!st.empty() && arr[st.top()] <= arr[i]) {
                    if(st.top() + 1 < i && sum[i - 1] - sum[st.top()] < arr[st.top()]) tmp.push_back({st.top() + 1, i - 1});
                    st.pop();
                }
                st.push(i);
            }
            while(!st.empty()) {
                if(st.top() + 1 < b + 1 && sum[b] - sum[st.top()] < arr[st.top()]) tmp.push_back({st.top() + 1, b});
                st.pop();
            }
            
            for(int i = b; i >= a; --i) {
                while(!st.empty() && arr[st.top()] <= arr[i]) {
                    if(i + 1 < st.top() && sum[st.top() - 1] - sum[i] < arr[st.top()]) tmp.push_back({i + 1, st.top() - 1});
                    st.pop();
                }
                st.push(i);
            }
            while(!st.empty()) {
                if(a < st.top() && sum[st.top() - 1] - sum[a - 1] < arr[st.top()]) tmp.push_back({a, st.top() - 1});
                st.pop();
            }
            
            int ans = 0;
            for(int i = a; i <= b; ++i) {
                int flag = 1;
                for(auto p : tmp) {
                    if(p.first <= i && i <= p.second) flag = 0;
                }
                ans += flag;
            }
            cout << ans << '\n';
        }
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 12 ms 352 KB Output is correct
9 Correct 16 ms 352 KB Output is correct
10 Correct 5 ms 332 KB Output is correct
11 Correct 8 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 14 ms 332 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 8 ms 340 KB Output is correct
16 Correct 13 ms 360 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
19 Correct 5 ms 340 KB Output is correct
20 Correct 43 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4045 ms 3156 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 12 ms 352 KB Output is correct
9 Correct 16 ms 352 KB Output is correct
10 Correct 5 ms 332 KB Output is correct
11 Correct 8 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 14 ms 332 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 8 ms 340 KB Output is correct
16 Correct 13 ms 360 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
19 Correct 5 ms 340 KB Output is correct
20 Correct 43 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Execution timed out 4045 ms 3156 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4045 ms 3156 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4045 ms 3156 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 12 ms 352 KB Output is correct
9 Correct 16 ms 352 KB Output is correct
10 Correct 5 ms 332 KB Output is correct
11 Correct 8 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 14 ms 332 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 8 ms 340 KB Output is correct
16 Correct 13 ms 360 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
19 Correct 5 ms 340 KB Output is correct
20 Correct 43 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Execution timed out 4045 ms 3156 KB Time limit exceeded
23 Halted 0 ms 0 KB -