CodeForces 835 C.Star sky(水~)

xiaoxiao2021-02-28  76

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; }
转载请注明原文地址: https://www.6miu.com/read-61607.html

最新回复(0)