本文共 2620 字,大约阅读时间需要 8 分钟。
线段树裸题,,对每一行每一列开线段树
#include #include #include #include #include #include #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)#define REP(i,n) for (int i = 1; i <= (n); i++)#define mp(a,b,c) (node){a,b,c}#define cls(s) memset(s,0,sizeof(s))#define cp node#define LL long long intusing namespace std;const int maxn = 100005,maxm = 8000005,INF = 1000000000,P = 1000000007;inline LL read(){ LL out = 0,flag = 1; char c = getchar(); while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();} while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();} return out * flag;}struct node{LL a,b,c;};map rt1,rt2;LL x[maxn],y[maxn],m;LL sum[maxm],sum2[maxm],num[maxm],cnt;int ls[maxm],rs[maxm],n;void upd(int u){ sum[u] = (sum[ls[u]] + sum[rs[u]]) % P; sum2[u] = (sum2[ls[u]] + sum2[rs[u]]) % P; num[u] = num[ls[u]] + num[rs[u]];}void modify(int& u,int l,int r,int pos,LL v,LL vv){ if (!u) u = ++cnt; if (l == r){v %= P; sum[u] = v; sum2[u] = v * v % P; num[u] = vv; return;} int mid = l + r >> 1; if (mid >= pos) modify(ls[u],l,mid,pos,v,vv); else modify(rs[u],mid + 1,r,pos,v,vv); upd(u);}cp query(int u,int l,int r,int L,int R){ if (!u) return mp(0,0,0); if (l >= L && r <= R) return mp(sum[u],sum2[u],num[u]); int mid = l + r >> 1; if (mid >= R) return query(ls[u],l,mid,L,R); if (mid < L) return query(rs[u],mid + 1,r,L,R); cp t1 = query(ls[u],l,mid,L,R),t2 = query(rs[u],mid + 1,r,L,R); return mp((t1.a + t2.a) % P,(t1.b + t2.b) % P,t1.c + t2.c);}LL lans,t,l,r,d,X,Y;int main(){ n = read(); m = read(); REP(i,n){ x[i] = read(); y[i] = read(); modify(rt1[x[i]],1,n,i,y[i] % P,1); modify(rt2[y[i]],1,n,i,x[i] % P,1); } int T = read(); char opt; cp u; while (T--){ opt = getchar(); while (!isalpha(opt)) opt = getchar(); if (opt == 'Q'){ t = read() ^ lans; l = read(); r = read(); u = query(rt1[x[t]],1,n,l,r); X = x[t] % P; Y = y[t] % P; lans = ((Y * Y % P * u.c % P - 2ll * Y % P * u.a % P) % P + u.b)% P; u = query(rt2[y[t]],1,n,l,r); lans = (lans + (X * X % P * u.c % P - 2ll * X % P * u.a % P) % P + u.b) % P; lans = (lans % P + P) % P; printf("%lld\n",lans); } else { t = read() ^ lans; d = read(); modify(rt1[x[t]],1,n,t,0,0); modify(rt2[y[t]],1,n,t,0,0); switch(opt){ case 'U':y[t] += d;break; case 'D':y[t] -= d;break; case 'L':x[t] -= d;break; case 'R':x[t] += d;break; default:break; } modify(rt1[x[t]],1,n,t,y[t] % P,1); modify(rt2[y[t]],1,n,t,x[t] % P,1); } } return 0;}
转载于:https://www.cnblogs.com/Mychael/p/9098438.html