This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n];
for(int x=0;x<n;x++){
cin >> a[x];
}
int q;
cin >> q;
while(q--){
int t;
cin >> t;
if(t == 1){
int pos, val;
cin >> pos >> val;
pos--;
a[pos] = val;
} else if(t == 2){
int l, r;
cin >> l >> r;
l--; r--;
int ans = 0;
for(int x=l;x<=r;x++){
ll sum = a[x];
int left = x-1, right = x+1;
while(left >= l && right <= r){
if(a[left] <= a[right]){
if(a[left] > sum) break;
sum += a[left--];
} else {
if(a[right] > sum) break;
sum += a[right++];
}
}
while(left >= l){
if(a[left] > sum) break;
sum += a[left--];
}
while(right <= r){
if(a[right] > sum) break;
sum += a[right++];
}
if(left == l-1 && right == r+1){
ans++;
}
}
cout << ans << "\n";
} else {
assert(false);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |