赞
踩
#include <bits/stdc++.h> #define mid ((l + r) >> 1) #define Lson rt << 1, l , mid #define Rson rt << 1|1, mid + 1, r #define ms(a,al) memset(a,al,sizeof(a)) #define log2(a) log(a)/log(2) #define lowbit(x) ((-x) & x) #define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define INF 0x3f3f3f3f #define LLF 0x3f3f3f3f3f3f3f3f #define f first #define s second #define endl '\n' using namespace std; const int N = 2e6 + 10, mod = 1e9 + 9; const int maxn = 500010; const long double eps = 1e-5; const int EPS = 500 * 500; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; typedef pair<double,double> PDD; template<typename T> void read(T &x) { x = 0;char ch = getchar();ll f = 1; while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();} while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; } template<typename T, typename... Args> void read(T &first, Args& ... args) { read(first); read(args...); } struct node { ll cnt; vector<PII> pre, suf; }tr[maxn << 2]; int n, m, x; int arr[maxn]; inline node merge(node a, node b) { if(!a.pre.size()) return b; if(!b.pre.size()) return a; node res; res.cnt = a.cnt + b.cnt; ll tot = 0; for(auto ita : a.suf) for(auto itb : b.pre) { if((ita.first|itb.first) >= x) tot += 1ll * ita.second * itb.second; } res.cnt += tot; res.pre = a.pre; ll num = a.pre.back().first; for(auto itb : b.pre) { if((itb.first|num)==num) res.pre.back().second += itb.second; else { res.pre.push_back({itb.first|num,itb.second}); num = num | itb.first; } } res.suf = b.suf; ll num1 = b.suf.back().first; for(auto ita : a.suf) { if((ita.first|num1)==num1) res.suf.back().second += ita.second; else { res.suf.push_back({ita.first|num1,ita.second}); num1 = num1 | ita.first; } } return res; } inline void pushup(int rt) { tr[rt] = merge(tr[rt<<1],tr[rt<<1|1]); } inline void build(int rt, int l, int r) { if(l == r) { tr[rt].pre.push_back({arr[l],1}); tr[rt].suf.push_back({arr[l],1}); tr[rt].cnt = (arr[l] >= x); return ; } build(Lson); build(Rson); pushup(rt); } node query(int rt, int l, int r, int L, int R) { if(L <= l && r <= R) return tr[rt]; if(mid < L) return query(Rson,L,R); else if(mid >= R) return query(Lson,L,R); else return merge(query(Lson,L,R),query(Rson,L,R)); } void update(int rt, int l, int r, int pos, int val) { if(l == r) { tr[rt].pre.back().first = val; tr[rt].suf.back().first = val; tr[rt].cnt = (val >= x); return; } if(pos <= mid) update(Lson,pos,val); else update(Rson,pos,val); pushup(rt); } int main() { IOS; cin >> n >> m >> x; for(int i = 1; i <= n; ++ i) cin >> arr[i]; build(1,1,n); while(m--) { int op; cin >> op; if(op == 1) { int x, y; cin >> x >> y; update(1,1,n,x,y); } else { int l, r; cin >> l >> r; cout << query(1,1,n,l,r).cnt << endl; } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。