CodeForces 835 C.Star sky(水~)

Description
在二维平面有n个星星,其亮度上限为c,第i个星星坐标为(x[i],y[i]),初始亮度为s[i],每秒亮度增加1,当亮度为c时下一秒亮度为0,q次查询,每次查询一个子矩阵中的星星在第t秒的亮度之和
Input
第一行输入三个整数n,q,c分别表示星星个数,查询数以及星星亮度上限,之后n行第i行输入第i个星星的坐标和初始亮度x[i],y[i],s[i],最后q行每行输入五个整数t,x1,y1,x2,y2表示查询以(x1,y1)为左上角,(x2,y2)为右上角的子矩阵中星星在第t秒的亮度之和(1<=n,q<=1e5,1<=c<=10,1<=x[i],y[i],x1,y1,x2,y2<=100,0<=s[i]<=c,0<=t<=1e9)
Output
对于每次查询输出一个答案
Sample Input
2 3 3
1 1 1
3 2 0
2 1 1 2 2
0 2 1 4 5
5 1 1 5 5
Sample Output
3
0
3
Solution
num[i][j][k]表示前i行前j列初始亮度为k的星星个数,对于每次查询,该子矩阵中初始亮度为k的星星个数为num[x2][y2][k]+num[x1-1][y1-1][k]-num[x2][y1-1][k]-num[x1-1][y2][k],t秒的时候这些星星亮度为(k+t)%(c+1),枚举k累加该值即为该次查询的答案
Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=101;
int n,q,c,num[maxn][maxn][12];
int main()
{
    while(~scanf("%d%d%d",&n,&q,&c))
    {
        c++;
        int sum=0;
        memset(num,0,sizeof(num));
        while(n--)
        {
            int x,y,s;
            scanf("%d%d%d",&x,&y,&s);
            num[x][y][s]++,sum+=s;
        }
        for(int k=0;k<c;k++)
            for(int i=1;i<=100;i++)
                for(int j=1;j<=100;j++) 
                    num[i][j][k]+=num[i-1][j][k]+num[i][j-1][k]-num[i-1][j-1][k];
        while(q--)
        {
            int t,x1,y1,x2,y2;
            scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
            int ans=0;
            for(int k=0;k<c;k++)
            {
                int cnt=num[x2][y2][k]+num[x1-1][y1-1][k]-num[x2][y1-1][k]-num[x1-1][y2][k];
                ans+=cnt*((k+t)%c);
            }
            printf("%d\n",ans);
        }           
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值