线段树经典题目……
/*
线段树单点更新 节点记录元素个数
查找第K元素所在
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#define lson l , mid , dex<<1
#define rson mid + 1 , r , dex<<1|1
#define havemid int mid = (l + r) >> 1
#define LL long long
const double eps = 1e-8;
const double PI = 2.0 * asin(1.0);
using namespace std;
const int Max = 100010;
LL sum[Max<<2];
void Push_up(int dex)
{
sum[dex] = sum[dex<<1] + sum[dex<<1|1];
}
void update(LL pos , LL change , int l , int r , int dex)
{
if(l == r)
{
sum[dex] = change;
return ;
}
havemid;
if(pos <= mid) update(pos , change , lson);
else update(pos , change , rson);
Push_up(dex);
}
int query(int pos , int l , int r , int dex)
{
// cout<<"l: "<<l<<" r:"<<r<<" pos:"<<pos<<endl;
if(l == r) return l;
havemid;
if(sum[dex<<1] >= pos) return query(pos , lson);
else
{
// pos -= sum[dex<<1];
return query(pos - sum[dex<<1], rson);
}
}
int main()
{
// freopen("3279.txt","r",stdin);
int n;
while(~scanf("%d",&n))
{
memset(sum , 0 , sizeof(sum));
for(int i=1; i<=n ;i++)
{
LL a;
scanf("%lld",&a);
update(i , a , 1 , n , 1);
}
int q;
scanf("%d",&q);
while(q--)
{
char ch[5];
int a;
LL b;
scanf("%s",ch);
if(ch[0] == 'q')
{
scanf("%d",&a);
printf("%d\n",query(a , 1 , n , 1));
}
else
{
scanf("%d %lld",&a, &b);
update(a , b , 1 , n , 1);
}
}
}
return 0;
}