CodeForces - 835C Star sky

CodeForces - 835C Star sky

题解:二维前缀和

二维平面上给你点和坐标,让你求总亮度,很容易想到二维前缀和,但是题目很抽象,又给了你一个时间,就是说,每过一个单位时间,它的亮度会有改变,这该怎么办?

实际上,我们观察发现,一开始初始亮度一样的点,在经历时间t后亮度还是保持一样,所以我们只需要去求出不同初始亮度下每个初始亮度对应的星星的数量,因为\(1<=c<=10\),所以我们考虑开一个三维数组,\(g[i][j][k]\),第一维代表初始亮度,后面两位代表坐标,然后在询问前先二维前缀和初始化,求出不同亮度的星星对应的数量,在询问时遍历一遍c,其实数量级也就2e6左右

#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10;
ll pre[15][110][110];
int n, q, c;
void pre_slove()
{
    for (int k = 0; k <= c; ++k)
    {
        for (int i = 1; i <= 105; ++i)
        {
            for (int j = 1; j <= 105; ++j)
            {
                pre[k][i][j] = pre[k][i][j] + pre[k][i][j - 1] + pre[k][i - 1][j] - pre[k][i - 1][j - 1];
            }
        }
    }
}
int main(void)
{
    Zeoy;
    int T = 1;
    // cin >> t;
    while (T--)
    {
        cin >> n >> q >> c;
        for (int i = 1; i <= n; ++i)
        {
            int x, y, v;
            cin >> x >> y >> v;
            pre[v][x][y]++;
        }
        pre_slove();
        while (q--)
        {
            int t, x1, y1, x2, y2;
            cin >> t >> x1 >> y1 >> x2 >> y2;
            ll ans = 0L;
            for (int i = 0; i <= c; ++i)
            {
                int val = (t + i) % (c + 1);
                ll num = pre[i][x2][y2] - pre[i][x2][y1 - 1] - pre[i][x1 - 1][y2] + pre[i][x1 - 1][y1 - 1];
                ans += val * num;
            }
            cout << ans << endl;
        }
    }
    return 0;
}
posted @ 2023-01-08 18:20  Zeoy_kkk  阅读(21)  评论(0编辑  收藏  举报