标签:ref 连续 amp ever OWIN nbsp 读者 href 个人
1
10
1 2 3 4 5 6 7 8 9 10
Query 1 3
Add 3 6
Query 2 7
Sub 10 2
Add 6 3
Query 3 10
End
Sample Output
Case 1: 6 33 59
#define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10);
#define lc now<<1
#define rc now<<1|1
#define ls now<<1,l,mid
#define rs now<<1|1,mid+1,r
#define half no[now].l+((no[now].r-no[now].l)>>1)
const int mxn = 50000+5;
struct node
{
int l,r,val,lazy;
}no[mxn<<2];
void pushup(int now) { no[now].val = no[lc].val+no[rc].val; return ;}
void build(int now , int l,int r)
{
no[now].l = l;no[now].r = r;
if(l==r)
{
cin>>no[now].val;
//cout<<no[now].val<<" ";
return ;
}
int mid = l+((r-l)>>1);
build(lc,l,mid);
build(rc,mid+1,r);
pushup(now);
}
int query(int now,int l,int r)
{
if(no[now].l>=l && r>=no[now].r)
return no[now].val;
int mid = no[now].l+((no[now].r-no[now].l)>>1),cnt = 0;
if(l<=mid)
cnt+=query(lc,l,r);
if(r>mid)
cnt+=query(rc,l,r);
return cnt;
}
void updata(int now,int pos,int key)
{
if(no[now].l==no[now].r)
{
no[now].val+=key;
return ;
}
int mid = half;
if(pos<=mid)
updata(lc,pos,key);
else
updata(rc,pos,key);
pushup(now);
}
int main()
{
TLE;
int t,n,l,r;
string str;
cin>>t;
for(int i=1;i<=t;i++)
{
cout<<"Case "<<i<<":"<<endl;
cin>>n;
build(1,1,n);
while(cin>>str&&(str[0]!=‘E‘))
{
if(str[0]==‘Q‘)
{
cin>>l>>r;
cout<<query(1,l,r)<<endl;
}
else if(str[0]==‘A‘)
{
cin>>l>>r;
updata(1,l,r);
}
else if(str[0]==‘S‘)
{
cin>>l>>r;
updata(1,l,-1*r);
}
}
}
return 0;
}
5 6
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
Sample Output
5
6
5
9
Hint
Huge input,the C function scanf() will work better than cin
#define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10);
#define lc now<<1
#define rc now<<1|1
#define ls now<<1,l,mid
#define rs now<<1|1,mid+1,r
#define half no[now].l+((no[now].r-no[now].l)>>1)
const int mxn = 200000+5; int mx;
struct node
{
int l,r,val,lazy;
}no[mxn<<2];
void pushup(int now) { no[now].val = max( no[lc].val,no[rc].val); return ;}
void build(int now , int l,int r)
{
no[now].l = l;no[now].r = r;
if(l==r)
{
cin>>no[now].val;
return ;
}
int mid = l+((r-l)>>1);
build(lc,l,mid);
build(rc,mid+1,r);
pushup(now);
}
void query(int now,int l,int r)
{
if(no[now].l>=l && r>=no[now].r)
{mx = max(mx,no[now].val);return ;}
int mid = no[now].l+((no[now].r-no[now].l)>>1);
if(l<=mid)
query(lc,l,r);
if(r>mid)
query(rc,l,r);
}
void updata(int now,int pos,int key)
{
if(no[now].l==no[now].r&&no[now].l==pos)
{
no[now].val = key;
return ;
}
int mid = half;
if(pos<=mid)
updata(lc,pos,key);
else
updata(rc,pos,key);
pushup(now);
}
int main()
{
TLE;
int t,n,l,r;
while(cin>>n>>t)
{
build(1,1,n);
while(t--)
{
mx = -1;
char ch;
cin>>ch>>l>>r;
if(ch==‘Q‘)
{
query(1,l,r);
cout<<mx<<endl;
}
else
updata(1,l,r);
}
}
return 0;
}
2 10 10 20 20 15 15 25 25.5 0Sample Output
Test case #1 Total explored area: 180.00
明天更新吧,到了睡觉时间了
标签:ref 连续 amp ever OWIN nbsp 读者 href 个人
原文地址:https://www.cnblogs.com/Shallow-dream/p/11741472.html