#include <stdio.h>
int mp[1100][1100] = {0};
int main(void)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
while (k--)
{
int x, y, v;
scanf("%d%d%d", &x, &y, &v);
mp[x][y] = v;
}
int q;
scanf("%d", &q);
while (q--)
{
int x1, x2, y1, y2;
unsigned long long s = 0;
scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
if (x1 > x2)
x1 ^= x2 ^= x1;
if (y1 > y2)
y1 ^= y2 ^= y1;
for (int i = x1; i <= x2; i++)
for (int j = y1; j <= y2; j++)
s += mp[i][j];
printf("%llu\n", s);
}
return 0;
}
fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuck 我再也不敢了,就这我debug了一年
if (x1 > x2)
t = x1, x1 = x2, x2 = t;
if (y1 > y2)
t = y1, y1 = y2, y2 = t;
香
#include <bits/stdc++.h>
using namespace std;
int mp[1100][1100] = {0};
int main(void)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
while (k--)
{
int x, y, v;
scanf("%d%d%d", &x, &y, &v);
mp[x][y] = v;
}
int q;
scanf("%d", &q);
while (q--)
{
int x1, x2, y1, y2;
unsigned long long s = 0;
scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
if (x1 > x2)
swap(x1, x2);
if (y1 > y2)
swap(y1, y2);
for (int i = x1; i <= x2; i++)
for (int j = y1; j <= y2; j++)
s += mp[i][j];
printf("%llu\n", s);
}
return 0;
}
这个解法其实不是正解(捂脸
估计是多测去掉之后就给水过去了...
我会的也就这一点点了,记得有个啥算法,忘了。就是一边迭代一边做差那个,完全搞不懂