一共有 nnn個數,第 iii 個數 xix_ixi 能夠取 [ai,bi][a_i , b_i][ai,bi] 中任意值。
設 S=∑xi2S = \sum{{x_i}^2}S=∑xi2,求 SSS 種類數。ios
第一行一個數 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≤100ui
臭名昭著的巧合spa
考場上只想到了暴力,徹底沒想到bitset優化qwq。code
考慮到$\sum_1^{100*100} * 100 = 1e6$blog
而後開個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; }