# 2018 ICPC-ACM shenyang G - Best ACMer Solves the Hardest Problem

Gym - 101955G

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn = 6000 + 20;

int point[maxn][maxn];
int vis[maxn][maxn];
vector<pair<int, int>> pos[10000000 + 20];
int dir[2][4] = { 1, 1, -1, -1, 1, -1, 1, -1 };

int main() {
ll lastans;
int t;
int n, m;
int op;
int x, y, w, k;
int xx, yy;
int cas = 0;
scanf("%d", &t);
for (int i = 0; i <= 6000; i++) {
for (int j = 0; j <= 6000; j++) {
if (i * i + j * j < 1e7 + 5)
pos[i * i + j * j].push_back(make_pair(i, j));
}
}
while (t--) {
printf("Case #%d:\n", ++cas);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", &x, &y, &w);
point[x][y] = w;
vis[x][y] = cas;
}
lastans = 0;
set<pair<int, int>> s;
while (m--) {
scanf("%d%d%d", &op, &x, &y);
x = (x + lastans) % 6000 + 1;
y = (y + lastans) % 6000 + 1;
if (op == 1) {
scanf("%d", &w);
point[x][y] = w;
vis[x][y] = cas;
}
if (op == 2) {
point[x][y] = 0;
vis[x][y] = 0;
}
if (op == 3) {
s.clear();
scanf("%d%d", &k, &w);
for (int i = 0; i < pos[k].size(); i++) {
for (int ii = 0; ii < 4; ii++) {
xx = x + pos[k][i].first * dir[0][ii];
yy = y + pos[k][i].second * dir[1][ii];
if (xx >= 1 && xx <= 6000 && yy >= 1 && yy <= 6000
&& vis[xx][yy] == cas && !s.count(make_pair(xx, yy))) {
s.insert(make_pair(xx, yy));
point[xx][yy] += w;
}
}
}
}
if (op == 4) {
scanf("%d", &k);
s.clear();
ll ans = 0;
for (int i = 0; i < pos[k].size(); i++) {
for (int ii = 0; ii < 4; ii++) {
xx = x + pos[k][i].first * dir[0][ii];
yy = y + pos[k][i].second * dir[1][ii];
if (xx >= 1 && xx <= 6000 && yy >= 1 && yy <= 6000
&& vis[xx][yy] == cas && !s.count(make_pair(xx, yy))) {
s.insert(make_pair(xx, yy));
ans += point[xx][yy];
}
}
}
lastans = ans;
printf("%lld\n", ans);
}
}
}
return 0;
}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

许可可可可

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

11-18 944
05-26 2055