cdoj 1256 昊昊爱运动 预处理
昊昊爱运动
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
昊昊喜欢运动
他NN天内会参加MM种运动(每种运动用一个[1,m][1,m]的整数表示)
舍友有QQ个问题
问昊昊第ll天到第rr天参加了多少种不同的运动
Input
输入两个数NN, MM (1≤N≤20001≤N≤2000, 1≤M≤1001≤M≤100);
输入NN个数aiai表示在第i天昊昊做了第aiai类型的运动;
输入一个数QQ(1≤Q≤1061≤Q≤106);
输入QQ行 每行两个数 ll, rr(1≤l≤r≤n1≤l≤r≤n);
Output
一共QQ行
每一行输出一个数 表示昊昊在第ll天到第rr天一共做了多少种活动
Sample input and output
| Sample Input | Sample Output |
|---|---|
5 3 |
3 |
Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=2e3+,M=4e6+,inf=1e9+;
int sum[N][N];
int a[N];
int main()
{
int n,m,t;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
for(int i=; i<=n; i++)
{
for(t=; t<=m; t++)
sum[t][i]=sum[t][i-];
sum[a[i]][i]=sum[a[i]][i-]+;
}
int q;
scanf("%d",&q);
while(q--)
{
int l,r,ans=;
scanf("%d%d",&l,&r);
for(int i=;i<=m;i++)
if(sum[i][r]-sum[i][l-]>)
ans++;
printf("%d\n",ans);
}
return ;
}
cdoj 1256 昊昊爱运动 预处理的更多相关文章
- cdoj 1256 昊昊爱运动 预处理/前缀和
昊昊爱运动 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1256 Descr ...
- UESTC 1256 昊昊爱运动 Map
昊昊爱运动 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 昊昊喜欢运动 他N天 ...
- CDOJ 1259 昊昊爱运动 II 线段树+bitset
昊昊爱运动 II 昊昊喜欢运动 他N天内会参加M种运动(每种运动用一个[1,m]的整数表示) 现在有Q个操作,操作描述如下 昊昊把第l天到第r天的运动全部换成了x(x∈[1,m]) 问昊昊第l天到第r ...
- CDOJ 1259 昊昊爱运动 II bitset+线段树
题目链接 昊昊喜欢运动 他N天内会参加M种运动(每种运动用一个[1,m]的整数表示) 现在有Q个操作,操作描述如下 昊昊把第l天到第r天的运动全部换成了x(x∈[1,m]) 问昊昊第l天到第r天参加了 ...
- cdojQ - 昊昊爱运动 II
地址:http://acm.uestc.edu.cn/#/contest/show/95 题目: Q - 昊昊爱运动 II Time Limit: 3000/1000MS (Java/Others) ...
- UESTC-1259 昊昊爱运动 II
昊昊爱运动 II Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 昊昊喜 ...
- CDOJ 1256 打表+数组 统计
昊昊爱运动 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit St ...
- CDOJ 1256 二维前缀和处理
昊昊喜欢运动 他NN 天内会参加MM 种运动(每种运动用一个[1,m][1,m] 的整数表示) 舍友有QQ 个问题 问昊昊第ll 天到第rr 天参加了多少种不同的运动 Input 输入两个数NN , ...
- bzoj 3704 昊昊的机油之GRST 贪心dp,思维
昊昊的机油之GRST Time Limit: 10 Sec Memory Limit: 1024 MBSubmit: 80 Solved: 33[Submit][Status][Discuss] ...
随机推荐
- Atitit.mysql 5.0 5.5 5.6 5.7 新特性 新功能
Atitit.mysql 5.0 5.5 5.6 5.7 新特性 新功能 1. MySQL 5.6 5 大新特性1 1.1. 优化器的改进1 1.2. InnoDB 改进1 1.3. 使用 ...
- [译]GLUT教程 - 每秒帧数
Lighthouse3d.com >> GLUT Tutorial >> Extras >> Frames per Second 你的程序实际上跑得多快? 有时我们 ...
- 【C#学习笔记】之用button使得textbox中数字的值增减
代码段: string t = ""; t = mv.textBox2.Text; int n = int.Parse(t); n = n + 1; mv.textBox2.Tex ...
- git add . git add -u git add -A命令区别图解
git版本不同会有所区别: Git Version 1.x: Git Version 2.x: git add . 修改(modified)以及新文件(new),但不包括被删除的文件. git ...
- ps -ef 和 aux 区别
Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...
- F - 数论
F - 数论 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description ...
- 解决iOS11 UIScrollView下移问题
iOS11 系统为UIScrollView增加一个contentInsetAdjustmentBehavior属性,默认为UIScrollViewContentInsetAdjustmentAutom ...
- Generally a good method to avoid this is to randomly shuffle the data prior to each epoch of training.
http://ufldl.stanford.edu/tutorial/supervised/OptimizationStochasticGradientDescent/
- java中枚举类型的使用
Java 枚举(enum) 详解7种常见的用法 JDK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. web项目里实体类使用枚举类型: 一般在该实体 ...
- Latex: Expression under summation on multiple lines
Purpose Describe the sum symbol like this: zebk=1Nk∑i∈Rkj∈W(i)∩Rkmax(fi−fj) Solution code z_{ebk}=\f ...