标签:clu lse val sync eve cost nts ack blank
InputThe input contains several test cases, terminated by EOF.
For each test case, the first line contains a single integer N, denoting there are N battleships of evil in a line. (1 <= N <= 100000)
The second line contains N integers Ei, indicating the endurance value of each battleship from the beginning of the line to the end. You can assume that the sum of all endurance value is less than 2 63.
The next line contains an integer M, denoting the number of actions and queries. (1 <= M <= 100000)
For the following M lines, each line contains three integers T, X and Y. The T=0 denoting the action of the secret weapon, which will decrease the endurance value of the battleships between the X-th and Y-th battleship, inclusive. The T=1 denoting the query of the commander which ask for the sum of the endurance value of the battleship between X-th and Y-th, inclusive.
OutputFor each test case, print the case number at the first line. Then print one line for each query. And remember follow a blank line after each test case.Sample Input
10 1 2 3 4 5 6 7 8 9 10 5 0 1 10 1 1 10 1 1 5 0 5 8 1 4 8
Sample Output
Case #1: 19 7 6
#include <iostream> #include <algorithm> #include <cstring> #include <string> #include <vector> #include <map> #include <set> #include <list> #include <deque> #include <queue> #include <stack> #include <cstdlib> #include <cstdio> #include <cmath> #include <iomanip> #define ull unsigned long long #define ll long long #define pb push_back #define mem(sum,x) memset(sum,x,sizeof(sum)) #define rep(i,start,end) for(int i=start;i<=end;i++) #define per(i,end,start) for(int i=end;i>=start;i--) #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; const int mod = 998244353; const int mxn = 1e5 +7; int _,n,m,t,u,v,ans,cnt,ok,lim; ll w[mxn] , cost[mxn] , far[mxn] , siz[mxn]; double num[mxn]; #define lc now<<1 #define rc now<<1|1 string str ; struct node {ll l,r,val,lazy,mx,mn;}p[mxn<<4]; void pushup(int now){ p[now].val = p[lc].val+p[rc].val; /// p[now].mx = max(p[lc].mx , p[rc].mx); /// p[now].mn = min(p[lc].mn , p[rc].mn); } void pushdown(int now) { if(p[now].lazy) { p[lc].lazy = p[rc].lazy = p[now].lazy; p[lc].val = p[now].lazy*(p[lc].r-p[lc].l+1); p[rc].val = p[now].lazy*(p[rc].r-p[rc].l+1); p[now].lazy = 0 ; } } void build(int l,int r,int now) { p[now].l = l,p[now].r = r ;///, p[now].lazy = 0 ; if(l==r){ /// cin>>p[now].val; scanf("%lld",&p[now].val); return ; } int mid = (l+r)>>1; build(l,mid,lc);build(mid+1,r,rc);pushup(now); } void add(int l,int r,int now) { if(p[now].r-p[now].l+1 == p[now].val) return ; if(p[now].l==p[now].r) { p[now].val = sqrt(p[now].val); return ; } ///pushdown(now); int mid = (p[now].l+p[now].r)>>1; if(l<=mid) add(l,r,lc); if(r>mid) add(l,r,rc); pushup(now); } ll ask(int l,int r,int now) { if(p[now].l>=l && p[now].r<=r) { return p[now].val; } int mid = (p[now].l+p[now].r)>>1; ll ans = 0 ; if(l<=mid) ans+=ask(l,r,lc); if(r>mid) ans+=ask(l,r,rc); return ans; } int main() { tle;int Case = 1 ; while(~scanf("%d",&n)) { printf("Case #%d:\n",Case++); build(1,n,1); scanf("%d",&m); int k,l,r; while(m--) { cin>>k>>l>>r; if(l>r) swap(l,r); if(k) printf("%lld\n",ask(l,r,1)); else add(l,r,1); } printf("\n"); } }
Can you answer these queries? HDU - 4027 (区间修改+区间查询)
标签:clu lse val sync eve cost nts ack blank
原文地址:https://www.cnblogs.com/Shallow-dream/p/12828882.html