Codeforces Round #427 (Div. 2) C. Star sky(二维前缀和)

题目链接:Codeforces Round #427 (Div. 2) C. Star sky

题意:

在一个二维平面上有n个星星,每个星星有一个初始的亮度,每过去一秒,星星的亮度变化为(s+1)%(c+1).

现在有q个询问,问t秒后一个矩形区域的星星的总亮度为多少。

题解:

由于c不大,将每颗星星按照初始亮点分类,每一类在任意时间的亮度都是相同的,然后对应加一加就行了。

 1 #include<bits/stdc++.h>
 2 #define RT(l,r) (l+r|l!=r)
 3 #define mst(a,b) memset(a,b,sizeof(a))
 4 #define F(i,a,b) for(int i=a;i<=b;++i)
 5 #define ___ freopen("c:\\code\\in.txt","r",stdin);
 6 using namespace std;
 7 typedef long long ll;
 8 typedef pair<int,int>P;
 9
10 const int N=1e5+7;
11
12 int n,q,c,mp[12][111][111];
13
14 int sum(int v,int x,int y)
15 {
16     int ret = 0;
17     for(int i = x;i > 0;i -= i&-i)
18         for(int j = y;j > 0;j -= j&-j)
19             ret += mp[v][i][j];
20     return ret;
21 }
22 void add(int v,int x,int y,int val)
23 {
24     for(int i = x;i <= 100;i += i&-i)
25         for(int j = y;j <= 100;j += j&-j)
26             mp[v][i][j] += val;
27 }
28
29 int get(int v,int x1,int y1,int x2,int y2)
30 {
31     return sum(v,x2,y2)-sum(v,x1-1,y2)-sum(v,x2,y1-1)+sum(v,x1-1,y1-1);
32 }
33
34 int main()
35 {
36     scanf("%d%d%d",&n,&q,&c);
37     F(i,1,n)
38     {
39         int x,y,v;
40         scanf("%d%d%d",&x,&y,&v);
41         add(v,x,y,1);
42     }
43     F(i,1,q)
44     {
45         int t,x1,y1,x2,y2;
46         scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
47         t%=(c+1);
48         int ans=0;
49         F(j,0,c)
50         {
51             int tmp=(t+j)%(c+1);
52             ans+=tmp*get(j,x1,y1,x2,y2);
53         }
54         printf("%d\n",ans);
55     }
56     return 0;
57 }

时间: 2024-08-06 03:38:26

Codeforces Round #427 (Div. 2) C. Star sky(二维前缀和)的相关文章

Codeforces Round #427 (Div. 2) D. Palindromic characteristics(Manacher求回文串)

题目链接:Codeforces Round #427 (Div. 2) D. Palindromic characteristics 题意: 给你一个串,定义k-th回文串,让你求每个k-th的数量. 题解: manacher处理好后做一下dp就行了. 当然也可以直接dp不用manacher. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespace std; 4 5 cons

CF427 C star sky 二维数组前缀和

用pre[t][i][j]存时间等价于t时坐标(1, 1) 和(i, j)组成的矩形区域的星星总亮度.再注意一下一个坐标处可以有多颗星星就可以了. star sky 1 // http://codeforces.com/contest/835/problem/C 2 #include <cstdio> 3 #include <cstring> 4 const int M = 12, N = 102; 5 int pre[M][N][N]; 6 int main() 7 { 8 in

Codeforces Round #427 (Div. 2)

B. The number on the board 题意: 有一个数字,它的每个数位上的数字的和不小于等于k.现在他改变了若干位,变成了一个新的数n,问现在的数和原来的数最多有多少位不同. 思路: 如果现在的数字各位数字之和大于等于k,那么它就可能没有被改变. 反之,那么每个数的最大改变量就是9减去这个数,于是把9减去每个数得到的结果从大到小排序,用k减去现在的数位和得到的结果记为kk,遍历一遍差量数组,用kk去减,知道kk小于0跳出. 代码: 1 #include <stdio.h> 2

Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c). Over time the stars twinkle. At moment 0 the i-th

Codeforces Round #427 (Div. 2) D. Palindromic characteristics

D. Palindromic characteristics Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes. A string is 1-palindrome if and only if

Codeforces Round #427 (Div. 2) D dp

D. Palindromic characteristics 题意:求给定字符串每阶回文子串有多少个. tags:根本没想到 dp..直接看官方题解吧 dp[i][j] 代表第 i 个字符到第 j 个字符的子串是几阶回文. Solution. Let's calculate the following dp. dp[l][r] is the maximum k such that the substring built from characters from l to r is k-palin

Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)

http://codeforces.com/problemset/problem/1163/B2 题意:有n天,每天有一个颜色,截取前x天,随便抽掉一天,使剩下的各个颜色出现的次数相等. 解题,也可以解决B1: 有三种情况: 1.一种颜色出项一次,其他相等,抽掉出现1次颜色的那一天,例如13天分别是 6 222 333 444 555 2.只有两种颜色次数,次数相差1,并且最大出现次数的颜色只有1次,例如13天分别是 777 333 222 8888 3.所有颜色都只出现过1次,例如 1 2 3

Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理

#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <t

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/