gym101955G

include

include

include

include

include

include

include

include

include

include

include

include

//#include

include

include

pragma GCC optimize(2)

define up(i,a,b) for(int i=a;i<b;i++)

define dw(i,a,b) for(int i=a;i>b;i--)

define upd(i,a,b) for(int i=a;i<=b;i++)

define dwd(i,a,b) for(int i=a;i>=b;i--)

//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
char ch = getchar(); ll x = 0, f = 1;
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
typedef pair<int, int> pir;

define lson l,mid,root<<1

define rson mid+1,r,root<<1|1

define lrt root<<1

define rrt root<<1|1

const int N = 1e7 + 10;
const int MAXNODE = 6e3 + 10;
const int mod = 6000;
vectorvec[N];
ll grp[MAXNODE][MAXNODE];
void init() {
upd(i, 0, MAXNODE - 9) {
upd(j, 0, MAXNODE - 9) {
ll tmp = 1ll * ii + 1ll * j * j;
if (tmp <= N-9) {
vec[tmp].push_back({ i,j });
}
}
}
upd(i, 0, N - 10) {
sort(vec[i].begin(), vec[i].end());
vec[i].erase(unique(vec[i].begin(), vec[i].end()), vec[i].end());
}
/
int ans = 0;
upd(i, 1, N - 10) {
ans = max(ans, (int)vec[i].size());
}
cout << ans << endl;*/
}
int dx[4] = { 1,1,-1,-1 };
int dy[4] = { -1,1,1,-1 };
int T, n, m;
int decode(int x,ll lastans) {
return ((x + lastans) % mod) + 1;
}
queueq;
int main() {
T = read();
init();
upd(cs, 1, T) {
printf("Case #%d:\n", cs);
n = read(), m = read();
int x, y, w, k, op;
while (!q.empty())
{
pir top = q.front();
grp[top.first][top.second]=0; q.pop();
}
upd(i, 1, n) {
x = read(), y = read(), w = read();
grp[x][y] = w;
q.push({ x,y });
}
ll lastans = 0;
while (m--) {
op = read();
x = read(), y = read();
x = decode(x, lastans); y = decode(y, lastans);
q.push({ x, y });
if (op == 1) {
w = read();
grp[x][y] = w;
}
else if (op == 2) {
grp[x][y] = 0;
}
else if (op == 3) {
k = read(), w = read();
up(i, 0, 4) {
for (auto k : vec[k]) {
if (k.second == 0 || k.first == 0)
if (i & 1)continue;
int xx = dx[i] * k.first + x;
int yy = dy[i] * k.second + y;
if (xx <= 0 || xx>6000 || yy <= 0 || yy>6000)continue;
if (grp[xx][yy]) { grp[xx][yy] += w; }
}
}
}
else {
k = read();
ll ans = 0;
up(i, 0, 4) {
for (auto k : vec[k]) {
if (k.second == 0 || k.first == 0)
if (i & 1)continue;
int xx = dx[i] * k.first + x;
int yy = dy[i] * k.second + y;
if (xx <= 0 || xx>6000 || yy <= 0 || yy>6000)continue;
ans += 1ll * grp[xx][yy];
}
}
lastans = ans;
printf("%lld\n", ans);
}
}
}
return 0;
}

posted @ 2020-12-06 22:45  LORDXX  阅读(64)  评论(0编辑  收藏  举报