内存限制:256 MiB时间限制:1000 ms标准输入输出
题目类型:传统评测方式:文本比较
上传者: nzhtl1477

题目描述

一共有 nnn个数,第 iii 个数 xix_ix​i​​ 可以取 [ai,bi][a_i , b_i][a​i​​,b​i​​] 中任意值。
设 S=∑xi2S = \sum{{x_i}^2}S=∑x​i​​​2​​,求 SSS 种类数。

输入格式

第一行一个数 nnn。
然后 nnn 行,每行两个数表示 ai,bia_i,b_ia​i​​,b​i​​。

输出格式

输出一行一个数表示答案。

样例

样例输入

5
1 2
2 3
3 4
4 5
5 6

样例输出

26

数据范围与提示

1≤n,ai,bi≤1001 \le n , a_i , b_i \le 1001≤n,a​i​​,b​i​​≤100

臭名昭著的巧合

考场上只想到了暴力,完全没想到bitset优化qwq。

考虑到$\sum_1^{100*100} * 100 = 1e6$

然后开个bitset每次暴力合并就行了

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<bitset>
#define rg register
using namespace std;
const int MAXN = 1e6 + , mod = ;
inline int read() {
char c = getchar();int x = ,f = ;
while(c < '' || c > ''){if(c == '-')f = -;c = getchar();}
while(c >= '' && c <= ''){x = x * + c - '',c = getchar();}
return x * f;
}
int N;
bitset<MAXN> pre, nxt;
int main() {
N = read();N--;
int l = read(), r = read();
for(rg int i = l; i <= r; i++) pre[i * i] = ;
for(rg int i = ; i <= N; i++) {
int l = read(), r = read();
nxt.reset();
for(rg int k = l; k <= r; k++)
nxt |= pre << (k * k);
pre = nxt;
}
printf("%d", nxt.count());
return ;
}

LOJ#515. 「LibreOJ β Round #2」贪心只能过样例(bitset)的更多相关文章

  1. [LOJ#515]「LibreOJ β Round #2」贪心只能过样例

    [LOJ#515]「LibreOJ β Round #2」贪心只能过样例 试题描述 一共有 \(n\) 个数,第 \(i\) 个数 \(x_i\) 可以取 \([a_i , b_i]\) 中任意值. ...

  2. LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例

    题目描述 一共有 nnn个数,第 iii 个数 xix_ix​i​​ 可以取 [ai,bi][a_i , b_i][a​i​​,b​i​​] 中任意值.设 S=∑xi2S = \sum{{x_i}^2 ...

  3. loj515 「LibreOJ β Round #2」贪心只能过样例[bitset+bool背包]

    由于bitset极其不熟练且在实际题目中想不起来运用它来优化,于是练了几道题. 这题是一个分组的bool背包,每组必须选一个,暴力的话是$O(n^5)$. 如果dp数组不要一维滚动的话,有两种枚举方法 ...

  4. Loj515 「LibreOJ β Round #2」贪心只能过样例 - Bitset,Dp

    bitset的基本应用了 类似可行性背包的dp考虑 复杂度O(nmL/64) #include <bits/stdc++.h> using namespace std; bitset &l ...

  5. loj515 「LibreOJ β Round #2」贪心只能过样例

    传送门:https://loj.ac/problem/515 [题解] 容易发现S最大到1000000. 于是我们有一个$O(n^2*S)$的dp做法. 容易发现可以被bitset优化. 于是复杂度就 ...

  6. LibreOJ β Round #2」贪心只能过样例

    题目友链:https://loj.ac/problem/515 话说这题蛮简单,bitset暴力直接过. 话不多说,上代码! #include <bits/stdc++.h> using ...

  7. [LOJ#531]「LibreOJ β Round #5」游戏

    [LOJ#531]「LibreOJ β Round #5」游戏 试题描述 LCR 三分钟就解决了问题,她自信地输入了结果-- > -- 正在检查程序 -- > -- 检查通过,正在评估智商 ...

  8. [LOJ#530]「LibreOJ β Round #5」最小倍数

    [LOJ#530]「LibreOJ β Round #5」最小倍数 试题描述 第二天,LCR 终于启动了备份存储器,准备上传数据时,却没有找到熟悉的文件资源,取而代之的是而屏幕上显示的一段话: 您的文 ...

  9. [LOJ#516]「LibreOJ β Round #2」DP 一般看规律

    [LOJ#516]「LibreOJ β Round #2」DP 一般看规律 试题描述 给定一个长度为 \(n\) 的序列 \(a\),一共有 \(m\) 个操作. 每次操作的内容为:给定 \(x,y\ ...

随机推荐

  1. Missing artifact jdk.tools:jdk.tools:jar:1.6

    今天从svn上面下载了一个mavan项目,出现Missing artifact jdk.tools:jdk.tools:jar:1.6 这个错误. 怎么解决了,在我的根pom.xml 下加入这个依赖就 ...

  2. PHP函数库(core)

    数组函数: array_change_key_case — 返回字符串键名全为小写或大写的数组 array_change_key_case() 将 input 数组中的所有键名改为全小写或大写.改变是 ...

  3. HTML中6种空白空格

    HTML提供了5种空格实体(space entity),它们拥有不同的宽度,非断行空格( )是常规空格的宽度,可运行于所有主流浏览器.其他几种空格(       ‌‍)在不同浏览器中宽度各异.     ...

  4. canvas制作雪花效果

    <!DOCTYPE html><html> <head>    <meta http-equiv="Content-type" conte ...

  5. [SVN]TortoiseSVN工具培训1─为什么要用SVN?

    你是否有经历过以下情况: SVN的使用理由/好处:

  6. C#保存图片到数据库并读取显示图片的方法

    private void button2_Click_1(object sender, System.EventArgs e) { string pathName; if (this.openFile ...

  7. 【转】run方法与start方法的区别

    在java线程中 start与run的不同start与run方法的主要区别在于当程序调用start方法一个新线程将会被创建,并且在run方法中的代码将会在新线程上运行,然而在你直接调用run方法的时候 ...

  8. JavaScript如何转换数据库DateTime字段类型?

    Javascript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在html(标 ...

  9. Ubuntu小工具

    更好的工具 更多的界面风格: https://github.com/anmoljagetia/Flatabulous 更丰富的终端zsh: https://github.com/robbyrussel ...

  10. 解决使用phpmyadmin导出导入数据库时提示的“超出长度”、“超时”问题

    IIS请求筛选模块被配置为拒绝超过请求内容长度的请求 1. 修改IIS的applicationhost.config a.文件位置: %windir%/system32/inetsrv/config/ ...