Effect: in the range of $ I $ elements in a given sequence of $ A $ $ [L_i, R_i] $, $ A $ find the sum of squares of the number of kinds.
Bitset with optimization, complexity $ O (\ frac {n ^ 5} {\ omega}) $
#include <iostream> #include <algorithm> #include <cstdio> #include <bitset> #define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std; const int N = 1e6+10; int n, a[N]; bitset<N> ans, t; int main () { scanf("%d", &n); years [0] = 1; REP(i,1,n) { you are, r; scanf("%d%d", &l, &r); t.reset(); REP(j,l,r) t |= ans<<(j*j); years = t; } printf("%d\n", (int)ans.count()); }