Codeforces Round #427 (Div. 2) C. Star sky

水平较水,想了老久,都结束了,才发现数据这么小,打个表预处理下不就好了。然后才想到,表怎么打?真是傻了这里写图片描述
去看了看别人怎么打的。。。
光照强度每c+1轮循环一次,c<=10,共循环c+1轮,把每轮的都打出来,然后O(1)查询。。。

#include <bits/stdc++.h>
using namespace std;

struct star
{
    int x,y,s;
};
const int MAXN = 1e5+10;
int table[15][110][110];
star stars[MAXN];
int n,q,c;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> q >> c;

    for(int i = 0; i < n; ++i)
        cin >> stars[i].x >> stars[i].y >> stars[i].s;

    for(int t = 0; t <= c; ++t)
    {
        for(int i = 0; i < n; ++i)
            table[t][stars[i].x][stars[i].y] += stars[i].s;

        for(int i = 1; i < 110; ++i)
            for(int j = 1; j < 110; ++j)
                table[t][i][j] += table[t][i][j-1];
        for(int i = 1; i < 110; ++i)
            for(int j = 1; j < 110; ++j)
                table[t][j][i] += table[t][j-1][i];

        for(int i = 0; i < n; ++i) stars[i].s = (stars[i].s+1)%(c+1);
    }
    int t,x1,y1,x2,y2;
    while(q--)
    {
        cin >> t >> x1 >> y1 >> x2 >> y2;
        t %= (c+1);
        int res = table[t][x2][y2]-table[t][x1-1][y2]
        -table[t][x2][y1-1]+table[t][x1-1][y1-1];
        cout << res << endl;
    }
    return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值