HDU 4737 A Bit Fun (2013成都网络赛)
A Bit Fun
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 423 Accepted Submission(s): 270
The problem is really simple: please count the number of different pairs of (i, j) where f(i, j) < m.
For each test case, first line contains two numbers n and m.(1 <= n <= 100000, 1 <= m <= 230) Then n numbers come in the second line which is the array a, where 1 <= ai <= 230.
Then follows the answer.
3 6
1 3 5
2 4
5 4
Case #2: 0
用位数num维护l,r两个指针。
扫描一遍。
复杂度31*n
/* ***********************************************
Author :kuangbin
Created Time :2013/9/14 星期六 11:59:04
File Name :2013成都网络赛\1010.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
int a[MAXN];
int num[];
int bit[]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T;
int n,m;
bit[] = ;
for(int i = ;i <= ;i++)
bit[i] = *bit[i-];
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase++;
scanf("%d%d",&n,&m);
for(int i = ;i < n;i++)
scanf("%d",&a[i]);
long long tot = (long long)n*(n+)/;
int last = ;
int i = ,j = ;
memset(num,,sizeof(num));
long long sum = ;
while(j < n)
{
for(int k = ;k <=;k++)
if(a[j] & bit[k])
num[k]++;
int s = ;
for(int k = ;k <= ;k++)
if(num[k])
s += bit[k];
if(s >= m)
{
while(s >=m)
{
for(int k = ;k <= ;k++)
if(a[i] & bit[k])
num[k]--;
s = ;
for(int k = ;k <= ;k++)
if(num[k])
s += bit[k];
i++;
//cout<<i<<endl;
}
sum += (long long)(n-j)*(i-last);
last = i;
}
j++;
}
printf("Case #%d: ",iCase);
//cout<<tot<<" "<<sum<<endl;
cout<<tot-sum<<endl;
}
return ;
}
HDU 4737 A Bit Fun (2013成都网络赛)的更多相关文章
- HDU 4737 A Bit Fun 2013成都 网络赛 1010
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737 题目大意:给定一系列数,F(i,j)表示对从ai到aj连续求或运算,(i<=j)求F(i, ...
- HDU 4734 F(x) (2013成都网络赛,数位DP)
F(x) Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)
Minimum palindrome Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 4733 G(x) (2013成都网络赛,递推)
G(x) Time Limit: 2000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4763 Theme Section (2013长春网络赛1005,KMP)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
随机推荐
- python导出数据到excel
1,SMTP发送带excel附件的邮件: def sendMail(filename, addressee): """ :param content: 发送内容 :par ...
- 【webService客户端】webservice客户端工具
public static Object invokeWebService(String namespaces,String url, String method, Object[] params, ...
- vs中如何统计整个项目的代码行数
在一个大工程中有很多的源文件和头文件,如何快速统计总行数? ------解决方案--------------------b*[^:b#/]+.*$^b*[^:b#/]+.*$ ctrl + shift ...
- 使用badblocks命令检测、修复硬盘坏道(待验证)
今天我的新硬盘到了.暂时没想好怎么用它.可以把它装入光驱位硬盘架给G430用,也可以把它当成移动硬盘来用. 想起以前记录过一个badblocks的用法,用来检查坏道,这里再贴一遍备用. ####### ...
- C++ Primer读书笔记(2)
getline(cin,string s)可以读取一整行,包括空白符.使用ctrl+Z结束 字符串字面值与string是不同的类型.两个字符串字面值不能直接相加. 处理string对象中的字符时,C+ ...
- 前后端分离之mockjs基本介绍
安装与使用 # 安装 npm install mockjs #使用 Mock var Mock = require('mockjs') var data = Mock.mock({ // 属性 lis ...
- linux 环境变量设置方法总结(PATH / LD_LIBRARY_PATH)
PATH和LD_LIBRARY_PATH本质都是变量,所谓变量的意思就是由别人赋值产生的,直觉往往会让我们添加和减少这个变量本身的某些路径,实际上这是不正确的.正确的做法是我们要去修改赋予这个变量数值 ...
- ajax发送多个跨域请求回调不混乱
var count = 0; var codes = ""; function refreshCache(urls){ try { var url = urls.split(&qu ...
- CF 554B 找相同行
给定一个由n*n块地砖铺成的房间,每块砖用0表示未打扫,1表示已打扫. 要求打扫时只能整列地扫,未打扫的会变为已打扫,已打扫的会变为未打扫.即1会变成0,而0会变成1,目标是 使最后整行为1的行数最大 ...
- FileSystemResource在Srping FrameWork 5中的变化
之前在项目中一直使用FileSystemResource这个类作为PropertyPlaceholderConfigurer的Resource引入部署目录外的配置文件,并设置了setIgnoreRes ...