传送门
题意:给定n个点,m个操作,n和m都是1e5级别的。让后每个操作是将这个点绕原点顺时针、逆时针转90°,将这个点按照 x = p 或着 y = p 做对称。再有q个询问,q也是1e5级别的。让后每个询问是问B这个点在第A次操作之后在哪里。
显然我们不能直接暴力,因为都达到了1e5级别。
一开始像找一下规律,看看是否这几个操作是相互独立的,一开始发现了点,但是随着越来越多的例子,很快否定了我找规律的想法。
现在问题就是我们能否将点的变换转变成类似乘法除法之类可以累计的变量呢?显然就会发现矩阵是满足这个性质的,我们只需要对每个操作递推维护一个右乘矩阵,当需要进行前A次操作的时候只需要乘一下A这个操作之前的矩阵乘积即可。
下面依次给出这几个操作的矩阵。
当然为了方便我们可以把初始矩阵写成
(xy1)\begin{pmatrix} x & y & 1\\ \end{pmatrix} (xy1)
(0−10100001)\begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} ⎝⎛010−100001⎠⎞
(010−100001)\begin{pmatrix} 0 & 1 & 0 \\ -1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} ⎝⎛0−10100001⎠⎞
(−1000102p01)\begin{pmatrix} -1 & 0 & 0 \\ 0 & 1 & 0 \\ 2p & 0 & 1 \end{pmatrix} ⎝⎛−102p010001⎠⎞
(1000−1002p1)\begin{pmatrix} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 2p &1 \end{pmatrix} ⎝⎛1000−12p001⎠⎞
为什么多加了一维呢?想必看到上面矩阵的时候大家也知道了,因为对称的时候会多一个常数,所以加一维比较方便处理常数。
下面代码仅供参考,写的比较乱
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m;
struct Point
{int x,y;
}q[N];
struct Query
{LL mp[3][3];
}node[N],t;
vector<Query>v;void mult(int id,Query v,int op)
{int x;if(op==3||op==4) scanf("%d",&x);if(op==3) v.mp[2][0]=2*x;else if(op==4) v.mp[2][1]=2*x;for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++)node[id+1].mp[i][j]+=node[id].mp[i][k]*v.mp[k][j];
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);t.mp[0][0]=0; t.mp[0][1]=-1; t.mp[0][2]=0;t.mp[1][0]=1; t.mp[1][1]=0; t.mp[1][2]=0;t.mp[2][0]=0; t.mp[2][1]=0; t.mp[2][2]=1;v.push_back(t);t.mp[0][0]=0; t.mp[0][1]=1; t.mp[0][2]=0;t.mp[1][0]=-1; t.mp[1][1]=0; t.mp[1][2]=0;t.mp[2][0]=0; t.mp[2][1]=0; t.mp[2][2]=1;v.push_back(t);t.mp[0][0]=-1; t.mp[0][1]=0; t.mp[0][2]=0;t.mp[1][0]=0; t.mp[1][1]=1; t.mp[1][2]=0;t.mp[2][0]=0; t.mp[2][1]=0; t.mp[2][2]=1;v.push_back(t);t.mp[0][0]=1; t.mp[0][1]=0; t.mp[0][2]=0;t.mp[1][0]=0; t.mp[1][1]=-1; t.mp[1][2]=0;t.mp[2][0]=0; t.mp[2][1]=0; t.mp[2][2]=1;v.push_back(t);scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d%d",&q[i].x,&q[i].y);scanf("%d",&m);node[0].mp[0][0]=node[0].mp[1][1]=node[0].mp[2][2]=1;for(int i=1;i<=m;i++){int op; scanf("%d",&op);mult(i-1,v[op-1],op);}int _; scanf("%d",&_);while(_--){int a,b; scanf("%d%d",&a,&b);Query t,ans;memset(t.mp,0,sizeof(t.mp));memset(ans.mp,0,sizeof(ans.mp));t.mp[0][0]=q[b].x,t.mp[0][1]=q[b].y,t.mp[0][2]=1;for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++)ans.mp[i][j]+=t.mp[i][k]*node[a].mp[k][j];printf("%lld %lld\n",ans.mp[0][0],ans.mp[0][1]);}return 0;
}
/**/