Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 3618
It hurts. Use CIN to enter the letter "tle !!!
#include<iostream>#include<vector>#include<map>#include<stack>#include<algorithm>#include<queue>#include<list>#include<set>#include<string.h>#include<stdlib.h>#include<math.h>#include<stdio.h>#include<ctype.h>#include<iomanip>using namespace std;#define LL long long#define pi acos(-1)#define N 100010#define INF 999999999#define eps 1e-8//****************************************//zoj 3279//Copyright@leolin All rights reserved.//****************************************int level[N],tree[N];int n;int lowbit(int t){ return t&(-t);}void update(int pos,int num){ while(pos<=n) { tree[pos]+=num; pos+=lowbit(pos); }}int sum(int i){ int tot=0; while(i>0) { tot+=tree[i]; i-=lowbit(i); } return tot;}int find(int a){ int i,j,k; int low=1,up=n,mid; while(low<=up) { mid=(low+up)>>1; if(sum(mid)>=a) { up=mid-1; } else low=mid+1; } return low;}char str[10];char c[100];int main(){ //freopen("a.txt","r",stdin); while(scanf("%d",&n)!=EOF) { int i; for(i=0;i<=n;i++)tree[i]=0; for(i=1;i<=n;i++) { scanf("%d",&level[i]); update(i,level[i]); } int m; scanf("%d",&m); while(m--) { scanf("%s",str); if(str[0]=='p') { int a,b; scanf("%d%d",&a,&b); update(a,-level[a]); level[a]=b; update(a,level[a]); } if(str[0]=='q') { int a; scanf("%d",&a); printf("%d\n",find(a)); } } } return 0;}