## 雯舞

Love three things int he world -- Manchery

# [数论] LOJ #510. 「LibreOJ NOI Round #1」北校门外的回忆

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> abcd;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
}
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int M=5000005;

int ncnt;
int ls[M],rs[M],T[M];
inline void Add(int &x,int l,int r,int t,int a){
if (!x) x=++ncnt;
T[x]^=a;
if (l==r) return;
int mid=(l+r)>>1;
}
inline int Query(int x,int l,int r,int ql,int qr){
if (!x) return 0;
if (ql<=l && r<=qr) return T[x];
int mid=(l+r)>>1,ret=0;
if (ql<=mid) ret^=Query(ls[x],l,mid,ql,qr);
if (qr>mid) ret^=Query(rs[x],mid+1,r,ql,qr);
return ret;
}

const int N=200005;

int K;
int vst[N],clk,pre[N];
int cnt;
int deg[N];
int pos[N],p[N];
int sum[N];

inline void Pre(){
for (int i=1;i<K;i++){
if (vst[i]) continue;
int x=i;
while (vst[x]!=2 && !cir[x])
vst[x]=2,x=2*x%K;
if (cir[x]){
x=i;
while (vst[x]==2)
vst[x]=1,x=2*x%K;
continue;
}
x=i;
while (vst[x]==2)
vst[x]=1,x=2*x%K;
if (x==0) continue;
x=2*x%K;
cir[x]=cnt,x=2*x%K;
}
for (int i=1;i<=cnt;i++){
pre[2*x%K]=x;
if (2*x%K==head[i]) { p[i]=pos[x]+(2*x>K); break; }
pos[2*x%K]=pos[x]+(2*x>K);
}
sum[i]=sum[i-1]+p[i];
}
}

int rt[32][N];

#define P(x,y) (sum[(x)-1]+(y)+1)

map<int,int> Map;
map<abcd,int> Map2;

int m,c;

inline int lowbit(int n){
m=1; c=0;
while (n%K==0) n/=K,m*=K,c++;
return n%K*m;
}

int n,Q;

inline int Query(int x){
int l=lowbit(x),ans=0;
if (!cir[l/m]){
if (Map.count(x))
ans=Map[x];
}else{
int z=l/m,w=x/(m*K);
int cc=cir[z];
ans^=Query(rt[c][P(cc,(w+p[cc]-pos[z])%p[cc])],0,1<<30,0,w-1);
int t=z;
while (pos[t]==pos[z]){
ans^=Map2[abcd(w,t*m)];
if (pre[t]*2>K) break;
t=pre[t];
}
}
//printf("%d\n",ans);
return ans;
}

int main(){
int order,x,y;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
Pre();
while (Q--){
if (order==1){
int l=lowbit(x);
while (x<=n && !cir[l/m]){
Map[x]^=y;
x+=l; l=lowbit(x);
}
if (x>n) continue;
int z=l/m,w=x/(m*K);
int cc=cir[z];
Map2[abcd(w,z*m)]^=y;
}else{
int ret=0;
for (int i=x;i;i-=lowbit(i))
ret^=Query(i);
printf("%d\n",ret);
}
}
return 0;
}


#### [DP]LOJ NOI Round #1——接竹竿

2017-07-07 14:01:30

#### [Contest] UOJ NOI Round #1

2016-07-20 09:27:40

#### [链分治] LOJ #511. 「LibreOJ NOI Round #1」验题

2017-07-23 13:18:07

#### [数论] LOJ #508. 「LibreOJ NOI Round #1」失控的未来交通工具

2017-07-23 13:26:30

#### [反演] LOJ #509. 「LibreOJ NOI Round #1」动态几何问题

2017-07-23 13:22:57

#### LOJ #508. 「LibreOJ NOI Round #1」失控的未来交通工具 数论 并查集

2018-05-19 17:40:43

#### #507. 「LibreOJ NOI Round #1」接竹竿 dp

2017-07-08 08:00:42

#### 「LibreOJ NOI Round #1」接竹竿 (dp+前缀和优化)

2017-07-07 16:40:50

#### 【DP】LibreOJ NOI Round #1[A.接竹竿]题解

2017-07-07 14:50:19

#### LOJ#511. 「LibreOJ NOI Round #1」验题

2018-03-05 16:42:56