日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4879 ZCC loves march (并查集,set,map)

發布時間:2024/1/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4879 ZCC loves march (并查集,set,map) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題面以及思路:https://blog.csdn.net/glqac/article/details/38402101

代碼:

#include <bits/stdc++.h> #define LL long long using namespace std; const LL mod = 1000000007; const int maxn = 2000010; struct node {LL x, y;int cnt;node(){}node(LL x, LL y, int cnt) {this -> x = x;this -> y = y;this -> cnt = cnt;} }; node pos[maxn]; map<LL, set<int> > row, col; set<int> :: iterator it; int f[maxn]; int get(int x) {if(x == f[x]) return x;return f[x] = get(f[x]); } int tot; int main() {int n, m, T, p;LL x, y, ans, d;char s[10];while(~scanf("%d%d", &n, &m)) {row.clear();col.clear();for (int i = 1; i <= n; i++) {scanf("%lld%lld", &x, &y);pos[i] = node(x, y, 1);f[i] = i;row[x].insert(i);col[y].insert(i);}f[n + 1] = n + 1;tot = n + 1;scanf("%d", &T);ans = 0;while(T--) {scanf("%s",s + 1);if(s[1] == 'Q') {scanf("%d", &p);p = p ^ ans;p = get(p);node tmp = pos[p];int num = 0;ans = 0;LL xx = pos[p].x, yy = pos[p].y;for (it = row[xx].begin(); it != row[xx].end(); it++) {node& tmp = pos[*it];f[*it] = tot;col[yy].erase(*it);num += tmp.cnt;LL tmp1 = (abs(yy - tmp.y)) % mod;ans = (ans + (tmp1 * tmp1) % mod * tmp.cnt % mod) % mod;tmp.y = yy;}for (it = col[yy].begin(); it != col[yy].end(); it++) {node& tmp = pos[*it];f[*it] = tot;num += tmp.cnt;row[xx].erase(*it);LL tmp1 = (abs(xx - tmp.x)) % mod;ans = (ans + (tmp1 * tmp1) % mod) % mod;tmp.y = yy;}col[yy].clear();row[xx].clear();pos[tot] = node(xx, yy, num);col[yy].insert(tot);row[xx].insert(tot);tot++;f[tot] = tot;printf("%lld\n", ans);} else {scanf("%d%lld", &p, &d);p = p ^ ans;int p1 = p;p = get(p);node& tmp = pos[p];LL xx = tmp.x, yy = tmp.y;tmp.cnt--;if(tmp.cnt == 0) {row[xx].erase(p);col[yy].erase(p);}if(s[1] == 'L') {yy -= d;} else if(s[1] == 'U') {xx -= d;} else if(s[1] == 'D') {xx += d; } else {yy += d;}f[p1] = p1;pos[p1] = node(xx, yy, 1);row[xx].insert(p1);col[yy].insert(p1);}}}}

  

轉載于:https://www.cnblogs.com/pkgunboat/p/10547905.html

總結

以上是生活随笔為你收集整理的HDU 4879 ZCC loves march (并查集,set,map)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。