code:
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define eps 1e-6
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m;
map <int, map<int, int> > m1, m2, m3;
void work()
{
int q;cin >> n >> m >> q;
m1.clear(); m2.clear(); m3.clear();
for(int i = 1, x, y, s; i <= q; ++i){
cin >> x >> y >> s;
++m3[x][y];
int ss = min({s, x - 1, y - 1});
++m1[x - ss][y - ss];
ss = min({s, n - x, m - y});
--m1[x + ss + 1][y + ss + 1];
ss = min({s, x - 1, m - y});
++m2[x - ss][y + ss];
ss = min({s, n - x, y - 1});
--m2[x + ss + 1][y - ss - 1];
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
{
m1[i][j] += m1[i - 1][j - 1];
m2[i][j] += m2[i - 1][j + 1];
cout << (m1[i][j] + m2[i][j] - m3[i][j]) << " \n"[j == m];
}
}
int main()
{
ios::sync_with_stdio(0);
int TT;cin>>TT;while(TT--)
work();
return 0;
}
本文提供了一段针对XCPC竞赛的代码实现方案,通过使用C++语言和多种数据结构(如map),解决了一个涉及二维矩阵操作的问题。该算法能够高效地处理大量查询,并通过巧妙的数据结构设计减少了复杂度。

3364

被折叠的 条评论
为什么被折叠?



