#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
vector<ll> a(n);
for(ll &i : a) cin >> i;
ll q;
cin >> q;
while(q--){
ll ty;
cin >> ty;
if(ty==1){
ll x,y;
cin >> x >> y;
a[x-1] = y;
}else{
ll l,r;
cin >> l >> r;
l--;r--;
vector<ll> v;
for(ll i = l;i<=r;i++) v.push_back(a[i]);
sort(v.begin(),v.end());
ll w = r-l+1;
vector<ll> u(w);
u[0] = v[0];
for(ll i = 1;i<w;i++) u[i]=v[i]+u[i-1];
//cout << "got";for(ll i : v) cout << " " << i; cout << "\n";
//cout << "pre";for(ll i : u) cout << " " << i; cout << "\n";
ll left = w-1;
for(ll i = 0;i<w;i++){
ll to = i;
while(to<w-1&&u[to]>=v[to+1]) to++;
//cout << i << " to " << to << "\n";
if (to==w-1){
left = i;
//cout << "left=" << left << " w=" << w << "\n";
break;
}
i = to;
}
cout << (w-left) << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |