The intellect is completely gone ... I don't think I can get the bonus anymore. Qaq ...
A B-June's game
Because the data is 9b1l, so we can hash to try the data ...
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #define REP (i,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) using namespace Std;inline int Read () { int x=0,f =1;char C=getchar (); for (;! IsDigit (c); C=getchar ()) if (c== '-') f=-1; for (; IsDigit (c); C=getchar ()) x=x*10+c-' 0 '; return x*f;} typedef unsigned long Long ll;int main () {int n=read (); ll Ans=0,ans2=0;rep (i,1,n) {ll c;scanf ("%llu", &c); ans^=c;ans2 ^= (c%52501);} if ((ans&1) && (!) ( ANS&2) && (ans&4) && (ans2&1) && (! ( ANS2&2)) puts ("L"); else puts ("B"); return 0;}
B Perfect elimination
This digital DP problem should still be good, we first consider how to calculate the minimum number of steps to 0.
Consider each bit from high to low, set the current number to X, and delete all numbers greater than x in the stack if there is no number x in the stack and answer +1.
We put this idea into a digital DP, set F[LEN][S][K][C] to indicate the front len bit, the stack is set to S, currently has been done K operations, the current number and the size of the given number of relations.
When you move, enumerate the next one and fill in the numbers.
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #define REP (i,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) using namespace Std;inline int read () {int x=0,f=1; Char C=getchar (); for (;! IsDigit (c); C=getchar ()) if (c== '-') f=-1; for (; IsDigit (c); C=getchar ()) x=x*10+c-' 0 '; return x*f;} typedef long LONG Ll;int k,bit[20];ll f[20][1050][20][2];//f[len][s][sumv][<?=]ll solve (ll N) {memset (f,0,sizeof (f) ); int len=0;while (n) bit[++len]=n%10,n/=10;reverse (bit+1,bit+len+1); F[0][1][0][0]=1;rep (I,1,len) Rep (S,1,1023) rep (v,0,k) Rep (c,0,1) {ll ans=f[i-1][s][v][c];if (!ans) continue;rep (y,0,9) if (y<=bit[i]| | c) {int s2=s| ( 1<<y), K2=v+1;rep (j,y+1,9) if (s>>j&1) s2^= (1<<j), if (s>>y&1) k2--;f[i][s2][k2][c| ( Y<bit[i])]+=ans;}} ll Ans=0;rep (s,1,1023) Ans+=f[len][s][k][1];return ans;} int main () {ll l,r;scanf ("%lld%lld", &l,&r), K=read ();p rintf ("%lld\n", Solve (r+1)-solve (l)); return 0;}
C lYK and GCD
Enumeration (I,J) = k, consider maintenance s[k]=sigma{a[i] | K|i}, and then you can figure out the answer to each question.
So we preprocess all the numbers of the factor and the MU function, and then we can do it every time O (sqrt (N)).
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #define REP (i,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) using namespace Std;inline int read () {int x=0,f=1; Char C=getchar (); for (;! IsDigit (c); C=getchar ()) if (c== '-') f=-1; for (; IsDigit (c); C=getchar ()) x=x*10+c-' 0 '; return x*f;} const int Maxn=100010;const int maxm=2000010;typedef long long ll;int first[maxn],next[maxm],to[maxm],cnt,e;void Addpri (int u,int v) {to[++e]=v;next[e]=first[u];first[u]=e;} int vis[maxn],mu[maxn],pri[maxn];void init (int n) {rep (i,1,n) for (int j=i;j<=n;j+=i) ADDPRI (j,i); Mu[1]=1;rep (i,2,n {if (!vis[i]) Pri[++cnt]=i,mu[i]=-1;rep (j,1,cnt) {if (pri[j]*i>n) break;vis[pri[j]*i]=1;if (i%pri[j]==0) {mu[i* Pri[j]]=0;continue;} Mu[i*pri[j]]=-mu[i];}}} int b[maxn],sum;int n,m,a[maxn];void Add (int x,int v) {sum+=v;for (int i=first[x];i;i=next[i]) b[to[i]]+=v*mu[to[i]];} int query (int x) {int res=0;for (int i=first[x];i;i=next[i]) res+=b[to[i]];rEturn Res;} int main () {n=read (); M=read (); init (n); Rep (i,1,n) Add (I,a[i]=read ()); Rep (i,1,m) {int t=read (), X=read (); if (t==2) printf ("%d\n", query (x)); else {int v=read (); ADD (X,v-a[x]); A[x]=v;}} return 0;}
E Danganronpa
My approach is based on AC automata.
Consider first to put the testimony string and the word bomb string on an AC automaton, then a speech bomb on a testimony of the damage is the testimony of how many prefixes in the words and bullets corresponding to the subtree of the fail tree.
Consider each inquiry with the testimony appearing as the first keyword, the second keyword in the inquiry time, the third key word on the AC automaton, and then run directly on the tree to the MO team.
The time complexity is O (n^ (5/3) logn). but because the constants are small, you can run through them.
#include <cstdio> #include <cstring> #include <cmath> #include <cctype> #include <algorithm > #define REP (i,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) using namespace Std;inline int read () {int X=0,f=1;char c=getchar (); for (;! IsDigit (c); C=getchar ()) if (c== '-') f=-1; for (; IsDigit (c); C=getchar ()) x=x*10+c-' 0 '; return x*f;} typedef long LONG Ll;const int maxn=200010;int size,ch[maxn][26],pa[maxn],cnt;int Insert (int p,int c) {if (!ch[p][c]) ch[p ][c]=++cnt;pa[ch[p][c]]=p;return ch[p][c];} int f[maxn],que[maxn],first1[maxn],first2[maxn],e1,e2;struct Edge {int to,next;} Edges1[maxn],edges2[maxn];void AddEdge1 (int u,int v) {edges1[++e1]= (Edge) {v,first1[u]};first1[u]=e1;} void AddEdge2 (int u,int v) {edges2[++e2]= (Edge) {v,first2[u]};first2[u]=e2;} int dep[maxn],sta[maxn],cur[maxn],blo[maxn],top,tmp;void DFS1 (int x) {dep[x]=dep[pa[x]]+1;cur[x]=top;for (int i= First1[x];i;i=edges1[i].next) {int v=edges1[i].to;dfs1 (v), if (top-cur[x]>size) {tmp++;while (top>cur[x]) blo[sta[top--]]=tmp;} Sta[++top]=x;} int st[maxn],en[maxn];void DFS2 (int x) {st[x]=++tmp;for (int i=first2[x];i;i=edges2[i].next) DFS2 (edges2[i].to); En[x] =tmp;} void Getfail () {int L=1,r=0;rep (c,0,25) if (Ch[0][c]) que[++r]=ch[0][c];while (l<=r) {int X=que[l++],v;rep (c,0,25) if (V=ch[x][c]) {Que[++r]=v;int j=f[x];while (J&&!ch[j][c]) j=f[j];f[v]=ch[j][c];}} Rep (i,1,cnt) AddEdge1 (pa[i],i);d FS1 (0), while (top) blo[sta[top--]]=tmp;rep (i,1,cnt) AddEdge2 (f[i],i); TMP=0;DFS2 (0) ;} int Posa[maxn],tima[maxn],posb[maxn],ca,cb;int n,m,q,t[maxn],p[maxn],blt[maxn];struct Query {int b,t,x;bool operator < (const query& ths) const {if (Blo[x]!=blo[ths.x]) return blo[x]<blo[ths.x];if (BLT[T]!=BLT[THS.T]) return t <ths.t;return b<ths.b;}} q[maxn];struct Fenwich {int SUMV[MAXN]; Fenwich () {memset (sumv,0,sizeof (SUMV));} void Add (int x,int v) {for (; x<=cnt+1;x+=x&-x) sumv[x]+=v;} int sum (int x) {int res=0;for (; x;x-=x&-x) Res+=sumv[x];return res;}} T1,t2;ll Curans,ans[Maxn];int LCA (int u,int v) {while (u!=v) {if (Dep[u]<dep[v]) swap (U,V); u=pa[u];} return v;} void Move (int u,int v) {int C=lca (U,V); while (u!=c) {curans-=t1.sum (st[u]); T2.add (st[u],-1); u=pa[u];} while (v!=c) {curans+=t1.sum (st[v]); T2.add (st[v],1); v=pa[v];} void U (int x,int v) {if (!x) return; T1.add (ST[X],V); T1.add (EN[X]+1,-V); curans+= (T2.sum (en[x])-t2.sum (st[x]-1)) *v;} int main () {n=read (); SIZE=SQRT (N*15); Rep (i,1,n) blt[i]= (i-1)/size+1;rep (i,1,n) {Ans[i]=-1;char cmd[20],c[2];int x;scanf ("%s", cmd); if ( cmd[0]== ' I ') {scanf ("%s%d", c,&x);p Osa[++ca]=insert (posa[x],c[0]-' a ');} if (cmd[0]== ' a ') {scanf ("%s%d", c,&x);p Osb[++cb]=insert (posb[x],c[0]-' a '); tima[cb]=i;} if (cmd[0]== ' S ') T[++q]=i,p[q]=posa[read ()];if (cmd[0]== ' Q ') X=read (), q[++m]= (Query) {tima[x],i,posb[x]};} Getfail (); int cx=0,l=1,r=0;sort (Q+1,Q+M+1); Rep (i,1,m) {if (! Q[I].B) {ans[q[i].t]=0;continue;} while (t[l]<q[i].b) u (p[l++],-1), while (l&&t[l-1]>q[i].b) u (p[--l],1), while (R<q&&t[r+1] <q[i].t) U (p[++r],1); while (T[r]>q[i].t) U (p[r--],-1); Move (cx,q[i].x); Cx=q[i].x;ans[q[i].t]=curans;} Rep (i,1,n) if (ans[i]>=0) printf ("%lld\n", Ans[i]); return 0;}
51nod Algorithm Marathon 15