55分代码
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include<map>
#include <string>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include<stack>
#include<queue>
#include<set>
#include<unordered_map>
#include <climits>
#include <math.h>
//众所周知,set能有序地维护同一类型的元素,但相同的元素只能出现一次。
using namespace std;
typedef long long LL;
const int N = 1e3,mod=1e9+7;
int dex[] = { 1,1,0,-1,-1,-1,0,1 };
int dey[] = { 0,1,1,1,0,-1,-1,-1 };
int n, m, p, q;
int ui, vi, ti;
unordered_map<LL, int>dict;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> p >> q;
for (int i = 0; i < p; i++) {
int x, y;
cin >> x >> y;
x--, y--;
dict[(LL)y * n + x] = i + 1;
}
while (q--)
{
cin >> ui >> vi >> ti;
ui--, vi--;
int dist = INT_MAX;
int mindist = min(min(ui , n - ui - 1), min(vi, m - vi - 1));
if(n<10000)
for (int i = 0; i < 8; i++) {
for (int j = 1;; j++) {
int x = ui + j * dex[i];
int y = vi + j * dey[i];
if (x >= n || x < 0 || y < 0 || y >= m) break;
if (dict[(LL)n * y + x] != 0) {
dist = min(dist, j);
break;
}
}
}
else {
for (auto &item : dict) {
if (item.second == 0) continue;
int y = item.first / n;
int x = item.first % n;
if (y == vi && x!=ui) dist = min(dist, abs(x - ui));
else if (x == ui && y!=vi) dist = min(dist, abs(y - vi));
else if(abs(x-ui)!=0 && abs(x-ui)==abs(y-vi)) {
dist = min(dist, abs(x - ui));
}
}
}
//cout << dist << endl;
if (dist > mindist) continue;
vector<int> td;
for (int i = 0; i < 8; i++) {
td.push_back(dict[n * ((LL)dey[i] * dist + vi) + (LL)dist * dex[i] + ui]);
dict.erase(n * ((LL)dey[i] * dist + vi) + (LL)dist * dex[i] + ui);
}
for (int i = 0; i < 8; i++) {
int next = (i + ti) % 8;
int tx = ui + dex[next] * dist;
int ty = vi + dey[next] * dist;
LL keyy = (LL)ty * n + tx;
if (td[i] != 0) {
dict[keyy] = td[i];
}
}
}
LL ans = 0;
for (auto& item : dict) {
if (item.second != 0) {
int y = item.first / n;
int x = item.first % n;
//cout <<"id:" << item.second << " x:" << x + 1 << " y:" << y + 1 << endl;
ans =ans^( (LL)item.second * (x + 1) + y + 1);
}
}
cout << ans << endl;
return 0;
}
acwing 的数据好像比官网的强,不用试啦啦啦啦
~!!!!