CodeForces 835C

s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- -

/*
CodeForces 835C - Star sky [ 前缀和,容斥 ]  |  Codeforces Round #427 (Div. 2)
题意:
	有一片 100*100 的星空,上面有 n 颗星星,每个星星有一个亮度,且在 0~C 范围内周期性变化,现在给出 q 个查询,每个查询给出时间和一个矩形,求在该时间时矩形内星星的亮度和。
	c <= 10
分析:
	由于 c <= 10,则星星的亮度只有11种情况,全部预处理出来,再求个二维前缀和,查询直接容斥定理
*/
#include <bits/stdc++.h>
using namespace std;
int vis[105][105];
int a[105][105][15];
int n, q, c;
int main()
{
    scanf("%d%d%d", &n, &q, &c); c++;
    for (int i = 1; i <= n; i++)
    {
        int x, y, s; scanf("%d%d%d", &x, &y, &s);
        for (int t = 0; t < c; t++)
        {
            a[x][y][t] += s % c;
            s = (s+1) % c;
        }
        vis[x][y] = 1;
    }
    for (int t = 0; t < c; t++)
    {
        for (int i = 1; i <= 100; i++)
        {
            for (int j = 1; j <= 100; j++)
            {
                a[i][j][t] += a[i][j-1][t];
            }
        }
        for (int j = 1; j <= 100; j++)
        {
            for (int i = 1; i <= 100; i++)
            {
                a[i][j][t] += a[i-1][j][t];
            }
        }
    }
    while (q--)
    {
        int t, l, r, h, w;
        scanf("%d%d%d%d%d", &t, &h, &l, &w, &r);
        t %= c;
        int ans = 0;
        ans += a[w][r][t];
        ans -= a[h-1][r][t] + a[w][l-1][t];
        ans += a[h-1][l-1][t];
        printf("%d
", ans);
    }
}

  

我自倾杯,君且随意
原文地址:https://www.cnblogs.com/nicetomeetu/p/7271723.html