HDU multi-school third 1008 Game - three teams of everolimus + prefix XOR

Topic links: point I ah ╭ (╯ ^ ╰) ╮

Subject to the effect:

     n n heap of stones, each can be taken from a pile of at least one, at most take complete
     A l i c e Alice first move, q q times asking
    ①: inquiry [ L , R ] [L,R] how many children are within range A l i c e Alice win
    ②: exchange a i a_i versus a i + 1 a_{i+1}

Problem-solving ideas:

    according to N i m it game, exclusive OR is as interval 0 0 Shi A l i c e Alice losing
    the pre-processing an exclusive or prefix, with three teams can everolimus

     c n t [ x ] cnt[x] indicates that an interval within the current prefix x x number of b b as a prefix
    to r r is transferred, directly c n t [ b [ r ] ] cnt[b[r]] can be discussed
    for l l transferred, if used c n t [ b [ l ] ] cnt[b[l]] , the whole range can not be discussed [ l , r ] [l,r] case
    so for each interrogation interval l l should be a Save


    Timestamp modification can transform the team in Mozambique a a and b b value
    after the conversion can be done first of all start from the last time a team of Mo
    because if the t i m e = 0 time=0 begin Mo team, then we must ensure that a a and b b 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]);
	}
}
Published 221 original articles · won praise 220 · views 20000 +

Guess you like

Origin blog.csdn.net/Scar_Halo/article/details/102887532