思路:
bitset写dp
#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#includeusing namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair #define pii pair #define piii pair #define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//headconst int N = 1e6 + 5;bitset dp[2];int main() { int n, l, r; scanf("%d", &n); int now = 0; dp[now].set(0); for (int i = 0; i < n; i++) { scanf("%d %d", &l, &r); now ^= 1; dp[now].reset(); for (int j = l; j <= r; j++) { dp[now] |= dp[now^1] << (j*j); } } printf("%d\n", dp[now].count()); return 0;}