HDU 4879ZCC loves march
来源:互联网 发布:飞凌单片机开发工具 编辑:程序博客网 时间:2024/06/14 20:44
On a m*m land stationed n troops, numbered from 1 to n. The i-th troop's position can be described by two numbers (xi,yi) (1<=xi<=m,1<=yi<=m). It is possible that more than one troop stationed in the same place.
Then there are t minutes, in each minute one of the following two events will occur:
(1)the x-th troop moves towards a direction( Up(U) Down(D) Left(L) Right(R))for d units;(You can suppose that the troops won't move out of the boundary)
(2)the x-th troop needs to regroup the troops which stations in the same row or column with the x-th troop. That is, these troops need to move to the x-th troop's station.
Suggest the cost of i-th troop moving to the j-th troop is (xi-xj)^2+(yi-yj)^2, every time a troop regroups, you should output the cost of the regrouping modulo 10^9+7.
Then there are t minutes, in each minute one of the following two events will occur:
(1)the x-th troop moves towards a direction( Up(U) Down(D) Left(L) Right(R))for d units;(You can suppose that the troops won't move out of the boundary)
(2)the x-th troop needs to regroup the troops which stations in the same row or column with the x-th troop. That is, these troops need to move to the x-th troop's station.
Suggest the cost of i-th troop moving to the j-th troop is (xi-xj)^2+(yi-yj)^2, every time a troop regroups, you should output the cost of the regrouping modulo 10^9+7.
Next n lines each line contain two numbers xi,yi(1<=xi,yi<=m)
Next line contains a number t.(t<=100000)
Next t lines, each line's format is one of the following two formats:
(1)S x d, S∈{U,L,D,R}, indicating the first event(1<=x<=n,0<=d<m)
(2)Q x, indicating the second event(1<=x<=n)
In order to force you to answer the questions online, each time you read x', x=x'�lastans("�" means "xor"), where lastans is the previous answer you output. At the beginning lastans=0.
5 31 32 12 22 33 26Q 1L 0 2L 5 2Q 5R 3 1Q 3
117
The input after decode:Q 1L 1 2L 4 2Q 4R 2 1Q 2将每次的移动,看做是一个新的点的诞生,合并使用并查集,用两个map套个容器就可以了。 #include<map> #include<set>#include<ctime> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<functional> using namespace std;#define ms(x,y) memset(x,y,sizeof(x)) #define rep(i,j,k) for(int i=j;i<=k;i++) #define per(i,j,k) for(int i=j;i>=k;i--) #define loop(i,j,k) for (int i=j;i!=-1;i=k[i]) #define inone(x) scanf("%d",&x) #define intwo(x,y) scanf("%d%d",&x,&y) #define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z) #define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p) #define lson x<<1,l,mid #define rson x<<1|1,mid+1,r #define mp(i,j) make_pair(i,j) #define ft first #define sd second typedef long long LL;typedef pair<LL, LL> pii;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 2e5 + 10;const double eps = 1e-10;int T, n, m, fa[N], cnt[N], sz, g[N], o;LL d;pii a[N];map<LL, set<int>> x, y;char s[N];int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }int main(){while (~scanf("%d%lld", &n, &d)){for (auto i : x) i.second.clear();for (auto i : y) i.second.clear(); x.clear(); y.clear();rep(i, 1, n){cnt[i] = 1; fa[i] = g[i] = i;scanf("%lld%lld", &a[i].ft, &a[i].sd);x[a[i].ft].insert(i); y[a[i].sd].insert(i);}sz = n;inone(m);int last = 0, ans;while (m--){scanf("%s", s);inone(o); o = o^last;int fo = get(g[o]);if (s[0] == 'Q'){ans = 0;for (auto i : x[a[fo].ft]){if (i == fo) continue;LL q = (a[i].sd - a[fo].sd) % mod;ans = (q * q % mod * cnt[i] + ans) % mod;cnt[fo] += cnt[i]; fa[i] = fo; cnt[i] = 0;}for (auto i : y[a[fo].sd]){if (i == fo) continue;LL q = (a[i].ft - a[fo].ft) % mod;ans = (q * q % mod * cnt[i] + ans) % mod;cnt[fo] += cnt[i]; fa[i] = fo; cnt[i] = 0;}x[a[fo].ft].clear(); x[a[fo].ft].insert(fo);y[a[fo].sd].clear(); y[a[fo].sd].insert(fo);printf("%d\n", last = ans); continue;}scanf("%lld", &d);++sz;cnt[sz] = 1; fa[sz] = sz; cnt[fo]--; a[sz] = a[fo]; g[o] = sz;if (s[0] == 'L' || s[0] == 'R') a[sz].sd += s[0] == 'L' ? -d : d;else a[sz].ft += s[0] == 'U' ? -d : d;x[a[sz].ft].insert(sz);y[a[sz].sd].insert(sz);}}return 0;}
0 0
- hdu 4879 ZCC loves march
- HDU 4879ZCC loves march
- hdu 4879 ZCC loves march (模拟+STL)
- HDU-4879-ZCC loves march(map+set+并查集)
- hdu 4879 ZCC loves march(STL+模拟+并查集)
- HDU 4879 ZCC loves march(并查集+set)
- [HDOJ 4879] ZCC loves march [模拟+数据结构]
- hdu 4882 ZCC Loves Codefires
- hdu 4882ZCC Loves Codefires
- HDU 4876 ZCC loves cards
- HDU-4876-ZCC loves cards
- hdu 4876 ZCC loves cards
- HDU 5229 ZCC loves strings
- hdu 5299 ZCC loves strings
- hdu 5229 ZCC loves strings
- hdu 5230 ZCC loves hacking
- hdu 5229 ZCC loves strings
- HDU 5229 ZCC loves strings
- QQ分享回调问题
- eclipse:xml-apis jar包冲突导致的getTextContent()方法无法找到解决
- 最小二乘法的证明以及最优化系数的求解 Least squares
- 有关输油管道问题的用时限制
- Java反射
- HDU 4879ZCC loves march
- Redis 安装
- 修改git 历史author name
- IDEA用maven创建springMVC项目和配置(XML配置和Java配置)
- android混淆打包
- ACM:蓝桥杯:矩形面积交
- Set克隆
- Kubernets搭建Kubernetes-dashboard
- vijos 1061 迎春舞会之三人组舞