题目链接:http://codeforces.com/contest/835/problem/C

题意:在二维坐标里,有n个星星,m个询问,星星的最大亮度c。然后输入n个星星的坐标和初始亮度,对于每个询问你需要回答对于左下角(x1,y1)和右上角(x2,y2)的矩形区域中的星星中,经过t秒后亮度和是多少?    对于一个星星如果在第t秒亮度为x,那么在t+1秒亮度将变成x+1(x+1<=c时)或0(x+1>c)。

思路:由于c<=10.所以对于一个矩形区域只需要统计初始每个亮度出现的数量,假设初始亮度为i的数目有cnt[i]个,那么经过t秒后的对于总亮度的共享为 cnt[i]*(i+t)%(c+1)。  然后我们定义val[i][j][k]表示坐标(i,j)中亮度为k的有多少个,然后统计一个前缀和计算即可。  还有另外一种方法是维护10个二维树状数组,然后枚举亮度后用二维树状数组统计矩形区域的和。

注意坑点:存在多个星星在同一个位置,并且可能亮度也相同。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
const int INF = 1e9;
const int mod = 1e9 + ;
int n, q, c;
LL val[MAXN][MAXN][], tmpc[];
int main(){
#ifdef kirito
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
while (~scanf("%d%d%d", &n, &q, &c)){
memset(val, , sizeof(val));
for (int i = ; i <= n; i++){
int x, y, s;
scanf("%d%d%d", &x, &y, &s);
val[x][y][s]++;
}
for (int i = ; i <= ; i++){
for (int j = ; j <= ; j++){
for (int k = ; k <= ; k++){
val[i][j][k] += val[i][j - ][k];
}
}
}
for (int i = ; i <= q; i++){
int x1, y1, x2, y2, t;
scanf("%d%d%d%d%d", &t, &x1, &y1, &x2, &y2);
memset(tmpc, , sizeof(tmpc));
for (int j = x1; j <= x2; j++){
for (int k = ; k <= ; k++){
tmpc[k] += (val[j][y2][k] - val[j][y1 - ][k]);
}
}
LL res = ;
for (int k = ; k <= ; k++){
res = res + (1LL * tmpc[k] * ((k + t) % (c + )));
}
printf("%lld\n", res);
}
}
return ;
}

Codeforces Round #427 (Div. 2) - C的更多相关文章

  1. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  2. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  3. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  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 #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  6. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  7. Codeforces Round #427 (Div. 2)—A,B,C,D题

    A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...

  8. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

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

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

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

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

随机推荐

  1. 关于项目中的一些经验:封装activity、service的基类,封装数据对象

    经验一,将几个页面公用的数据,和方法进行封装,形成一个baseActivity的类: package com.ctbri.weather.control; import java.util.Array ...

  2. [LeetCode]-algorithms-Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  3. css中如何使用border属性与display属性

    border属性介绍 border属性设置元素边框. 边框3个要素如:粗细.线型.颜色. 边框线型属性值说明表如: 属性指 描述 none 定义无边框. hidden 与 "none&quo ...

  4. 关于vue给对象新增属性页面不会动态更新

    不知道大家有没有遇到过这个问题,当我们给data里边声明或者已经赋值过的对象或者数组,添加新的属性时,如果更新此属性的值是不会动态更新视图的. $set 看以下实例: 我们开始给drug_list追加 ...

  5. c++11多线程---线程操作

    1.等待线程执行完成 join() 方法数会阻塞主线程直到目标线程调用完毕,即join会直接执行该子线程的函数体部分. 2.暂停线程(线程休眠) 使用std::this_thread::sleep_f ...

  6. C#中winform下利用ArcEngine调用ArcGIS Server发布的服务 AE9.3

    主要使用了AE中的IAGSServerOject接口及IMapServer接口.Private void GetServerTest_Click(object sender, EventArgs e) ...

  7. Linux-定时任务-打包与压缩

    figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...

  8. JSON.toJSONString时保留null值

    QuoteFieldNames———-输出key时是否使用双引号,默认为true WriteMapNullValue——–是否输出值为null的字段,默认为false WriteNullNumberA ...

  9. 使用ntpdate 同步 linux的时间

    1. linux 查看时间和时区的命令 timedatectl 效果为: Local time: Sun -- :: CST Universal time: Sun -- :: UTC RTC tim ...

  10. Hibernate 日期映射 条件查询

    1. hql: ...and accopt_time > ?" 2. query.setDate Query query = session.createQuery(hql); int ...