【Link】:http://codeforces.com/contest/835/problem/C

【Description】



给你n个星星的坐标(xi,yi);

第i个星星在第t秒,闪烁值变为(si+t)%(c+1);

给你q个询问,每个询问由时间t和一个矩形的左下角和右上角组成;

问这个矩形区域内的星星闪烁值的总和;

【Solution】



朴素的做法;

    a[j][k][l]表示(j,k)这个点一开始闪烁值为l的星星有多少个;
for (int i = 1;i <= q;i++){
int temp = 0;
for (int j = 1;j <= 100;j++)
for (int k = 1;k <= 100;k++)
for (int l = 0;l <= c;l++)
temp += a[j][k][l]*((t[i]+l)%(c+1));
out(temp);
}

这里可以把两层1..100的for循环,用一个前缀和省掉.





【NumberOf WA】



0



【Reviw】

【Code】

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100;
const int C = 10; int a[N+10][N+10][C+10];
int n,q,c; int getsum(int x1,int y1,int x2,int y2,int k){
int temp1 = a[x2][y2][k];
int temp2 = a[x2][y1-1][k];
int temp3 = a[x1-1][y2][k];
int temp4 = a[x1-1][y1-1][k];
return temp1-temp2-temp3+temp4;
} main(){
scanf("%lld%lld%lld",&n,&q,&c);
for (int i = 1;i <= n;i++){
int x,y,s;
scanf("%lld%lld%lld",&x,&y,&s);
a[x][y][s]++;
}
for (int i = 1;i <= N;i++)
for (int j = 1;j <= N;j++)
for (int k = 0;k <= c;k++)
a[i][j][k] += a[i][j-1][k]+a[i-1][j][k]-a[i-1][j-1][k];
for (int i = 1;i <= q;i++){
int t,x1,y1,x2,y2;
scanf("%lld%lld%lld%lld%lld",&t,&x1,&y1,&x2,&y2);
int temp = 0;
for (int j = 0;j <= c;j++){
temp += getsum(x1,y1,x2,y2,j)*((j+t)%(c+1));
}
printf("%lld\n",temp);
}
}

【Codeforces Round #427 (Div. 2) C】Star sky的更多相关文章

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

    [Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...

  2. 【Codeforces Round #427 (Div. 2) A】Key races

    [Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...

  3. 【Codeforces Round #427 (Div. 2) B】The number on the board

    [Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...

  4. 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 coordinat ...

  5. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  6. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  7. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  8. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  9. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

随机推荐

  1. 包及常用模块(time、datetime、random、sys)

    什么是包?‘ #官网解释 Packages are a way of structuring Python’s module namespace by using “dotted module nam ...

  2. 【Fiddler】使用fiddler抓取指定浏览器的包

    参考资料:http://blog.csdn.net/sufubo/article/details/49331705 使用fiddler抓取不到浏览器的包时常用的解决办法: 1.必须先打开Fiddler ...

  3. C#-修改图书借阅管理系统-错误与SQL server 2008错误、复制数据库

    VS2012错误: *)不存在从对象类型 System.Object[] 到已知的托管提供程序本机类型的映射 public DataTable loadData2UserSearch(params o ...

  4. HTML学习----------DAY2第五节

    属性为 HTML 元素提供附加信息. HTML 属性 HTML 标签可以拥有属性.属性提供了有关 HTML 元素的更多的信息. 属性总是以名称/值对的形式出现,比如:name="value& ...

  5. C++ priority_queue的使用 & Java PriorityQueue

    刚刚那道BST的题目,也用到了priority_queue,那是那个没有定义比较函数. 那么下面这个,就要定义比较函数. 它的模板声明带有三个参数,priority_queue<Type, Co ...

  6. POJ2823 单调队列

    POJ2823 http://poj.org/problem?id=2823 最基础的单调队列,说是数据结构,其实就是一种更新数组数据的方法. 之前还准备用deque,超时了,直接head,tail快 ...

  7. Hadoop的多节点集群详细启动步骤(3或5节点)

    版本1 利用自己写的脚本来启动,见如下博客 hadoop-2.6.0-cdh5.4.5.tar.gz(CDH)的3节点集群搭建 hadoop-2.6.0.tar.gz的集群搭建(3节点) hadoop ...

  8. 创建一个基于ViSP的图片显示程序

    创建一个图片读取,并在windows下窗口显示的程序. #include <visp/vpDisplayD3D.h> #include <visp/vpDisplayGDI.h> ...

  9. SQL Server 2008 R2 超详细安装图文教程及问题解决(锐姿公司安装)

    问题点: 1.为了sqlserver与mysql 的安全,建议数据库低权限运行.禁止远程访问 1433与 3306端口等. 2.安装提示.net 3.5没有安装 ,在server2012的添加 3. ...

  10. sublime 编辑器汉化

    一.下载Sublime编辑器 官网下载地址:http://www.sublimetext.com/3 二.下载汉化包 汉化包下载地址:http://files.cnblogs.com/akwwl/su ...