Pagini recente » Cod sursa (job #157113) | Cod sursa (job #61480) | Cod sursa (job #2145779) | Cod sursa (job #434366) | Cod sursa (job #2907489)
/*
Programmer : Alexandru Olteanu
*/
#include<bits/stdc++.h>
using namespace std;
// GCC Optimizations
// #pragma GCC optimize("Ofast");
// #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt")
// #pragma GCC target("abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize(3)
// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse")
// #pragma GCC optimize("-fgcse-lm")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-ftree-pre")
// #pragma GCC optimize("-ftree-vrp")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("unroll-loops")
// Useful
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define FastEverything ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define HighPrecision cout<<fixed<<setprecision(17);
typedef long long ll;
typedef pair<int,int> pii;
ll const mod=1000000007LL;
ll const mod2 = 100000000LL;
ll const md=998244353LL;
ll mypowr(ll a,ll b, ll mod1) {ll res=1;if(b<0)b=0;a%=mod1; assert(b>=0);
for(;b;b>>=1){if(b&1)res=res*a%mod1;a=a*a%mod1;}return res;}
ll mypow(ll a,ll b) {ll res=1;if(b<0)b=0;assert(b>=0);
for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
ifstream in("aib.in");
ofstream out("aib.out");
#define cin in
#define cout out
const ll infll = 9e18;
const int inf = 2e9;
const ll maxn = 2e5 + 2;
/*
Template created by Alexandru Olteanu
*/
template<typename A>
struct FenwickTree{
vector<A> array;
int n;
FenwickTree(int length){
array.resize(length + 1);
n = length;
}
void modify(int x, ll val){
for(; x <= n; x += x & -x){
array[x] += val;
}
return;
}
ll calc(int x){
ll val = 0;
for(; x > 0; x -= x & -x){
val += array[x];
}
return val;
}
ll get(int l, int r){
return calc(r) - calc(l - 1);
}
};
int main()
{
FastEverything
HighPrecision
int test = 1;
// cin >> test;
for (int tt = 1; tt <= test; ++tt) {
int n, m;
cin >> n >> m;
FenwickTree<int> f(n);
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
f.modify(i, x);
}
for (int i = 1; i <= m; ++i) {
int p, x, y;
cin >> p >> x;
if (p == 0) {
cin >> y;
f.modify(x, y);
}
if (p == 1) {
cin >> y;
cout << f.get(x, y) << '\n';
}
if (p == 2) {
int left = 1, right = n;
int answer = -1;
while (left <= right) {
int mid = left + (right - left) / 2;
int res = f.get(1, mid);
if (res == x) {
answer = mid;
right = mid - 1;
continue;
}
if (res < x) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
cout << answer << '\n';
}
}
}
return 0;
}