Topic links: point I ah ╭ (╯ ^ ╰) ╮
Subject to the effect:
heap of stones, each can be taken from a pile of at least one, at most take complete
first move,
times asking
①: inquiry
how many children are within range
win
②: exchange
versus
Problem-solving ideas:
according to
game, exclusive OR is as interval
Shi
losing
the pre-processing an exclusive or prefix, with three teams can everolimus
indicates that an interval within the current prefix
number of
as a prefix
to
is transferred, directly
can be discussed
for
transferred, if used
, the whole range can not be discussed
case
so for each interrogation interval
should be a Save
Timestamp modification can transform the team in Mozambique
and
value
after the conversion can be done first of all start from the last time a team of Mo
because if the
begin Mo team, then we must ensure that
and
changes
Core: Maintenance of everolimus team with three different prefixes or nature
#include<bits/stdc++.h>
#define deb(x) cerr<<#x<<" = "<<(x)<<'\n';
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn], belong[maxn];
int cntq, cntc, n, m, size, bnum;
ll sum, cnt[1<<21], ans[maxn];
struct query {
int l, r, time, id;
} q[maxn];
struct modify {
int pos, pre, val;
} c[maxn];
int cmp(query a, query b) {
return (belong[a.l] ^ belong[b.l]) ? belong[a.l] < belong[b.l] :\
((belong[a.r] ^ belong[b.r]) ? belong[a.r] < belong[b.r] : a.time < b.time);
}
inline void add(int x){
sum += cnt[x];
cnt[x]++;
}
inline void del(int x){
--cnt[x];
sum -= cnt[x];
}
int main() {
while(~scanf("%d%d", &n, &m)){
size = pow(n, 2.0 / 3.0);
bnum = ceil((double)n / size);
for(int i=1; i<=bnum; ++i)
for(int j=(i-1)*size+1; j<=i*size; ++j)
belong[j] = i;
for(int i=1; i<=n; ++i){
scanf("%d", a+i);
b[i] = b[i-1] ^ a[i];
}
cntq = cntc = 0;
for(int i=1; i<=m; ++i) {
int op, pos;
scanf("%d", &op);
if(op == 1) {
++cntq;
scanf("%d%d", &q[cntq].l, &q[cntq].r);
--q[cntq].l;
q[cntq].time = cntc;
q[cntq].id = cntq;
} else {
++cntc;
scanf("%d", &pos);
c[cntc].pos = pos;
c[cntc].pre = b[pos];
c[cntc].val = b[pos+1] ^ a[pos];
b[pos] = b[pos+1] ^ a[pos];
swap(a[pos], a[pos+1]);
}
}
sort(q+1, q+cntq+1, cmp);
memset(cnt, 0, sizeof(cnt)), sum = 0;
int l = 1, r = 0, time = cntc, ql, qr, qt;
for(int i = 1; i <= cntq; ++i) {
ql = q[i].l, qr = q[i].r, qt = q[i].time;
while(l < ql) del(b[l++]);
while(l > ql) add(b[--l]);
while(r < qr) add(b[++r]);
while(r > qr) del(b[r--]);
while(time < qt) {
++time;
if(ql <= c[time].pos && c[time].pos <= qr) {
del(c[time].pre);
add(c[time].val);
}
b[c[time].pos] = c[time].val;
}
while(time > qt) {
if(ql <= c[time].pos && c[time].pos <= qr) {
del(c[time].val);
add(c[time].pre);
}
b[c[time].pos] = c[time].pre;
--time;
}
ans[q[i].id] = 1ll*(qr-ql+1)*(qr-ql)/2 - sum;
}
for(int i=1; i<=cntq; ++i) printf("%lld\n", ans[i]);
}
}