답안 #795222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795222 2023-07-27T07:38:14 Z eltu0815 Fish 2 (JOI22_fish2) C++14
0 / 100
9 ms 2388 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 {
            int mx[100005];
            stack<int> st;
            for(int i = a; i <= b; ++i) mx[i] = i - 1;
            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()]) mx[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()]) mx[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()]) mx[i + 1] = max(mx[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()]) mx[a] = max(mx[a], mx[st.top() - 1]);
                st.pop();
            }
            
            int ans = 0, i = a;
            while(i <= b) {
                ans += mx[i] - i + 1;
                i = max(i + 1, mx[i] + 1);
            }
            cout << b - a + 1 - ans << '\n';
        }
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Incorrect 1 ms 596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 716 KB Output is correct
2 Incorrect 9 ms 2388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Incorrect 1 ms 596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 716 KB Output is correct
2 Incorrect 9 ms 2388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 716 KB Output is correct
2 Incorrect 9 ms 2388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Incorrect 1 ms 596 KB Output isn't correct
4 Halted 0 ms 0 KB -