内存限制:256 MiB时间限制:1000 ms标准输入输出
题目类型:传统评测方式:文本比较
上传者: nzhtl1477
一共有 nnn个数,第 iii 个数 xix_ixi 可以取 [ai,bi][a_i , b_i][ai,bi] 中任意值。 设 S=∑xi2S = \sum{{x_i}^2}S=∑xi2,求 SSS 种类数。
第一行一个数 nnn。 然后 nnn 行,每行两个数表示 ai,bia_i,b_iai,bi。
输出一行一个数表示答案。
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,ai,bi≤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 + 10001, mod = 19650827;
inline int read() {
char c = getchar();int x = 0,f = 1;
while(c < '0' || c > '9'){if(c == '-')f = -1;c = getchar();}
while(c >= '0' && c <= '9'){x = x * 10 + c - '0',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] = 1;
for(rg int i = 1; 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 0;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有