Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #include<ctype.h>
- #include<stdlib.h>
- #include<cstdio>
- #include<cstring>
- #include<string>
- #include<cmath>
- #include<iostream>
- #include<cctype>
- #include<map>
- #include<stack>
- #include<cstdlib>
- #include<queue>
- #include<vector>
- #include<algorithm>
- #include<bitset>
- #include<algorithm>
- #include<set>
- #include<limits.h>
- #include <sstream>
- //#include <bits/stdc++.h>
- using namespace std;
- typedef long int LD;
- typedef long long int LLD;
- typedef float F;
- typedef double LF;
- typedef unsigned int U;
- typedef unsigned long int LU;
- typedef unsigned long long int LLU;
- typedef char C;
- /*----------simple input section ------------ */
- #define sf scanf
- #define sfi(x) scanf("%d",&x)
- #define sfc(x) scanf("%c",&x)
- #define sfi2(x,y) scanf("%d%d",&x,&y)
- #define sfll2(x,y) scanf("%lld%lld",&x,&y)
- #define sfu2(x,y) scanf("%llu%llu",&x,&y)
- #define sfl(x) scanf("%ld",&x)
- #define sfll(x) scanf("%lld",&x)
- #define sfd(x) scanf("%lf",&x)
- #define sfu(x) scanf("%llu",&x)
- #define sfs(x) scanf("%s",x)
- /*----------simple input section ------------ */
- #define pf printf
- #define pfi(x) printf("%d\n",x)
- #define pfl(x) printf("%ld\n",x)
- #define pfll(x) printf("%lld\n",x)
- #define pfu(x) printf("%llu\n",x)
- #define pfs(x) printf("%s\n",x)
- #define pfc(x) printf("%c\n",x)
- #define pfd(x) printf("%lf\n",x)
- /*----------file input section ------------ */
- #define f_input freopen("input.txt","r",stdin);
- #define f_output freopen("output.txt","w",stdout);
- #define pb(x) push_back(x)
- #define PI acos(-1.0)
- #define sq(x) (x)*(x)
- #define mem(x,y) memset(x,y,sizeof(x))
- #define TEST int cs,T;sfi(T);getchar();for(cs=1;cs<=T;cs++)
- #define nn printf("\n")
- // xx-> diagonal -> 8 horizontal/vertical->4
- const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
- const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};
- // KX-> Knight moves
- const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
- const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};
- /******** debug **********/
- #define chk1 printf("hi......1 \n")
- #define chk2 printf("hi......2 \n")
- template<class T> T power(T N,T P)
- {
- return (P==0)? 1: N*power(N,P-1); //N^P
- }
- #define mod 1000000007
- #define eps 10e-8
- #define sz 100005
- #define sz1 65
- #define sz2 1000005
- /******* start my code ********/
- LLU tree[4*sz][sz1];
- LLU arr[sz];
- void build(int pos,int l,int r)
- {
- if(l==r)
- {
- LLU x,i;
- x=arr[l];
- i=0;
- while(x)
- {
- tree[pos][i++]=(x&1);
- x=x>>1;
- }
- return;
- }
- int mid=(l+r)/2;
- build(pos*2,l,mid);
- build(pos*2+1,mid+1,r);
- for(int i=0; i<64; i++)
- tree[pos][i]=tree[pos*2][i]+tree[pos*2+1][i];
- }
- void update(int pos,int l,int r,int idx,LLU val)
- {
- if(l==r)
- {
- LLU x,i;
- x=val;
- i=0;
- while(x)
- {
- tree[pos][i++]=(x&1);
- x=x>>1;
- }
- return;
- // tree[pos]=val;
- // return;
- }
- int mid=(l+r)/2;
- if(idx<=mid) update(pos*2,l,mid,idx,val);
- else update(pos*2+1,mid+1,r,idx,val);
- for(int i=0; i<64; i++)
- tree[pos][i]=tree[pos*2][i]+tree[pos*2+1][i];
- }
- LLU query(int pos,int l,int r,int s,int e,int k)
- {
- if(l>e || r<s) return 0;
- if(l>=s && r<=e) return tree[pos][k];
- int mid=(l+r)/2;
- LLU q1=query(pos*2,l,mid,s,e,k);
- LLU q2=query(pos*2+1,mid+1,r,s,e,k);
- return q1+q2;
- }
- int main()
- {
- int i,j,k,n,m,l,a,b,q,t;
- LLU x;
- while(sfi(n)!=EOF)
- {
- mem(tree,0);
- for(i=1; i<=n; i++)
- {
- sfu(arr[i]);
- }
- build(1,1,n);
- sfi(q);
- while(q--)
- {
- sfi(t);
- if(t==1)
- {
- sfi(a);
- sfu(x);
- update(1,1,n,a,x);
- }
- else
- {
- sfi2(a,b);
- sfi(k);
- pfu(query(1,1,n,a,b,k));
- }
- }
- }
- return 0;
- }
- /*
- 5
- 1152921504606846976 1224979098644774912 1227230898458460160 1515461274610171904 1515602012098527232
- */
Advertisement
Add Comment
Please, Sign In to add comment