10.2 simulation game summary
T1.
Digital dp:
A very very very very clear that digital DP
\([L,R] = [1,R]-[1,L-1]\)
It is equal to the number seeking two were less than a certain number of programs
\ (f (i, j, k) \) from a lower number of plays \ (I \) bits, in accordance with the rules for calculating the answer is \ (j \ quad (j = 0,1) \)
\ (k \) indicates that only consider the end of the back and \ (lmt \) behind the relationship between the size of several of \ ((k = 0,1) \ )
Consider the first \ (i + 1 \) magnitude bits, the digital count and the new configuration is determined to be the
Noting \ (L, R \) data is particularly large range, precision needed, the final result to be output in binary, it is possible to accurately position the pressure
(Solution to a problem over the steak)
This problem is a normal person would expect to find the law:
Then there playing table: (1 to 100)
Then gone (what? There are high-precision it)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define LL long long
using namespace std;
int n, q, v, t, L, R, len;
char s[208];
struct bigint
{
int len, zz;
int v[1005];
bigint(){len = 0; memset(v, 0, sizeof v); zz = 1;}
bigint(int x)
{
if(x >= 0) zz = 1;
else x = -x, zz = 0;
len = 0;
memset(v, 0, sizeof v);
while(x)
{
v[ ++len] = x % 10;
x /= 10;
}
}
friend bool operator < (const bigint &a, const bigint &b)
{
if(a.len < b.len) return 1;
if(a.len > b.len) return 0;
for(int i = a.len ; i >= 1; i -- )
{
if(a.v[i] < b.v[i]) return 1;
if(a.v[i] > b.v[i]) return 0;
}
return 0;
}
friend bool operator == (const bigint &a, const bigint &b)
{
if(a.len != b.len ) return 0;
for(int i = a.len; i >= 1; i --)
{
if(a.v[i] != b.v[i]) return 0;
}
return 1;
}
friend bool operator <= (const bigint &a, const bigint &b)
{
if(a < b) return 1;
else if(a == b) return 1;
else return 0;
}
friend bool operator != (const bigint &a, const bigint &b)
{
if(a.len != b.len) return 1;
for(int i = a.len; i >= 1; i --)
{
if(a.v[i] != b.v[i]) return 1;
}
return 0;
}
}x, y, res;
bigint operator + (bigint a, bigint b)
{
int len = a.len + b.len;
bigint c;
c.len = len;
for(int i = 1; i <= len; i ++)
c.v[i] = a.v[i] + b.v[i];
for(int i = 1; i <= len; i ++)
{
if(c.v[i] >= 10)
{
++c.v[i+1];
c.v[i] -= 10;
}
}
while(c.len&&!c.v[c.len]) c.len --;
return c;
}
bigint operator - (bigint a, bigint b)
{
int len = max(a.len, b.len);
bigint c;
for(int i = 1; i <= len; i ++)
c.v[i] = a.v[i] - b.v[i];
c.len = len;
for(int i = 1; i <= c.len; i ++)
{
if(c.v[i] < 0)
{
c.v[i+1]--;
c.v[i] += 10;
}
}
while(c.len&&!c.v[c.len]) c.len --;
return c;
}
bigint operator *(bigint a,bigint b)
{
bigint c;
for(int i = 1; i <= a.len; ++ i)
for(int j = 1; j <= b.len; ++ j)
c.v[i+j-1] += a.v[i] * b.v[j];
c.len = a.len + b.len;
for(int i = 1; i <= c.len - 1; ++ i)
{
if(c.v[i] >= 10)
{
c.v[i+1] += c.v[i] / 10;
c.v[i] %= 10;
}
}
while(c.v[c.len] == 0&&c.len > 1) -- c.len;
return c;
}
bigint operator /(bigint a,long long b)
{
bigint c;int d = 0;
for(int i = a.len; i >= 1; -- i)
c.v[++ c.len] = ((d * 10 + a.v[i]) / b),d=(d*10+a.v[i])%b;
for(int i=1;i<=c.len/2;++i)swap(c.v[i],c.v[c.len-i+1]);
while(c.v[c.len]==0&&c.len>1)--c.len;
return c;
}
bigint Min(bigint a, bigint b)
{
if(a < b) return a;
else return b;
}
bigint work(bigint x)
{
if(x < bigint(4)) return bigint(1);
bigint l = bigint(4), r = Min(x, bigint(7)), res = bigint(1);
int opt = 1;
for(; ; l = r + bigint(1), r = Min(r * bigint(2) + bigint(1), x), opt ^= 1 )
{
if(opt)
res = res + (r - l + bigint(1));
if(r == x) break;
}
return res;
}
void out(bigint x)
{
if(!x.len) return (void)printf("0");
bigint qwq = bigint(1);
while(qwq <= x) qwq = qwq * bigint(2);
qwq = qwq / 2;
for(; ; qwq = qwq /2)
{
if(qwq <= x)
{
printf("1");
x = x - qwq;
}
else printf("0");
if(qwq == bigint(1))break;
}
}
void solve()
{
x = y = res = bigint(0);
scanf("%s", s + 1);
for(int i = 1; i <= n; i ++)
{
x = x * 2 + bigint(s[i] - '0');
}
scanf("%s", s + 1);
for(int i = 1; i <= n; i ++)
{
y = y * 2 + bigint(s[i] - '0');
}
res = work(y) - work(x - bigint(1));
if((n&1) == (q&1)) res = y - x + 1 - res;
out(res);
puts("");
}
signed main()
{
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
scanf("%d", &t);
while(t --)
{
scanf("%d%d",&n, &q);
solve();
}
return 0;
}
T2
Sb a problem, nothing summarized. .
.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define LL long long
#define N 100005
using namespace std;
struct node
{
int w1, w2, l1, l2;
}q[N];
int n, m, t, minw = 2e9, maxw = -233, minl = 2e9, maxl = -233, flag;
signed main()
{
freopen("b.in", "r",stdin);
freopen("b.out", "w", stdout);
scanf("%d", &t);
while(t -- )
{
flag = 0; minw = minl = 2e9; maxw = maxl = -233;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d%d%d%d", &q[i].w1, &q[i].w2, &q[i].l1, &q[i].l2);
for(int i = 1; i <= n; i ++)
{
minw = min(minw, q[i].w1);
maxw = max(maxw, q[i].w2);
minl = min(minl, q[i].l1);
maxl = max(maxl, q[i].l2);
}
for(int i = 1; i <= n; i ++)
{
if(q[i].w1 <= minw&&q[i].w2 >= maxw&&q[i].l1 <= minl&&q[i].l2 >= maxl)
{flag = 1; break; }
}
if(flag)printf("TAK\n");
else printf("NIE\n");
}
return 0;
}
T3
Number of tumor topic data structure +
- Given 1, n, d, v for all sequences satisfy \ (gcd (x, n) = d \) a \ (X \) , to \ (A [X] + = V \) ;
Equivalent \ (a [x] + = v [gcd (x, n) == d] \)
Then you can happily push the formula
\(\ \ \ \ v[\gcd(x,n) = d]\)
$ = v [\gcd(\frac{x}{d},\frac{n}{d})=1]$
$ = V \ sum \ limits_ {k | \ gcd (\ frac {x} {d}, \ frac {n} {d})} \ mu (k) $ (daily inversion)
$ = v\sum\limits_{k|\frac{x}{d},k|\frac{n}{d}} \mu(k)$
\(=\sum\limits_{k|\frac{n}{d},kd|x} v\mu(k)\)
Violence is clearly to enumerate \ (X \) , for each \ ({k | \ frac { n} {d} and KD | X} \) , are coupled with \ (v \ mu (k) \) ,
It is equivalent to
For a valid \ (K | \ {n-dfrac} {D} \) , then \ (X = KD, 2kD, 3kD ... \) , enumeration \ (K \) , all \ (KD \) , plus multiples are \ (V \ MU (K) \) ;
Although this \ (O (1) \) queries, but the complexity of the modification is too large
Consider the complexity of shared equally
We opened an array of \ (f \) indicates that all is \ (i \) , multiple locations are plus \ (f [i] \)
Modifying just need to find a legitimate \ (K \) , then \ (F [KD] + = V \ MU (K) \) , eliminating the enumeration \ (KD \) multiples;
Then queries a number of query \ (I \) time, it would be \ (\ sum_ {d | i } f (d) \)
The \ (x \) prefix, and is
\(\sum\limits_{i=1}^x\sum\limits_{d|i} f(d)=\sum\limits_{d=1}^x f(d)\lfloor \frac{x}{d}\rfloor\)
Can then be divided by block, each block of the block that is necessary to obtain \ (F \) and; modified single-point array can maintain a tree summing interval;
Time complexity $ O (q \ sqrt {l} \ log l + l \ log l) $
Can the Sahua
Then the persimmon understanding
\(\sum\limits_{i=1}^x\sum\limits_{d|i}1=\sum\limits_{d=1}^{x}\lfloor\frac{x}{d}\rfloor\)
1 about the number of all numbers to each number x
Is equivalent to a divisor of enumeration, the number of the divisor multiples, the multiples of the number of x is less than d \ (\ lfloor \ FRAC {x} {d} \ rfloor \) ;