[] A solution to a problem is the (Euler's theorem BroadenGate + + search)

[] A solution to a problem is the (Euler's theorem BroadenGate + + search)

darkbzoj

This collection of set partitioning problem is then equal NP problem, the lower bound is exponential, so consider some properties.

We now consider only \ (v = 1000 \) situation. Since all of the sequence numbers \ (V \) film was obtained, so that when a query is considered greater than the length of the interval is equal to \ (v-1 \) , the problem must be a solution, either because at this time a number appears twice, either there has been \ (0 \) .

Consider the range and then narrow point, we know that \ (\ log_ {3} 1000 = 6.8 \) , so when the query interval greater than or equal $ 2 \ lceil 6.8 \ rceil = 7 \ (when is there must be solvable, so now only need consider \) case len \ le 13 $ of the.

Then \ (len \ le 13 \) case of two-way direct search. Complexity $ O (2n3 ^ {7} + n \ log n) $ modify the operation request corresponds to \ (^ X ^ {K}. 3 \) , directly Euler's theorem.

Do not read very simple solution to a problem that went to rush, to see the title ...

//@winlere
#include<tr1/unordered_map>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;  typedef long long ll;
using namespace std::tr1;
inline int qr(){
      register int ret=0,f=0;
      register char c=getchar();
      while(c<48||c>57)f|=c==45,c=getchar();
      while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
      return f?-ret:ret;
}

const int maxn=1e5+5;
int seg[maxn];
int data[maxn];
int f[21],F;
unordered_map<int,int> S;
int n,m,mod,phi,lit;

void dfs(const int&now,const int&s,const int&k){
      if(now>lit){
        if(S[s]==123) return;
        if(k==1){S[s]|=1;}
        if(k==2){S[s]|=2;}
        if(k==3){S[s]=123;}
        return;
      }
      dfs(now+1,s+f[now]+1,k|1);
      dfs(now+1,s-f[now]-1,k|2);
      dfs(now+1,s,k);
}

void dfs2(const int&now,const int&s,const int&k){
      if(now<=lit){
        if(S.find(-s)!=S.end()){
          int g=S[-s];
          if(g==123) F=1;
          if(k==3) F=1;
          if(k==1&&(g>>1&1)) F=1;
          if(k==2&&(g&1)) F=1;
        }
        return;
      }
      if(F)return;
      dfs2(now-1,s+f[now]+1,k|1);
      dfs2(now-1,s-f[now]-1,k|2);
      dfs2(now-1,s,k);
}

inline int getphi(int x){
      int temp=x,ret=x;
      for(int t=2;t*t<=temp;++t)
        if(temp%t==0){
          ret-=ret/t;
          while(temp%t==0) temp/=t;
        }
      if(temp>1) ret-=ret/temp;
      return ret;
}

inline void add(const int&pos,const int&tag){
      for(int t=pos;t<=n+1;t+=t&-t) seg[t]+=tag;
}

inline int que(const int&pos){
      int ret=0;
      for(int t=pos;t>0;t-=t&-t) ret+=seg[t];
      return ret;
}

inline int zhi(const int&base,const int&p){
      int g=phi;
      if(p*log(base)<=log(phi)) g=0;
      int ret=1;
      for(int t=p,b=base%phi;t;t>>=1,b=1ll*b*b%phi)
        if(t&1) ret=1ll*ret*b%phi;
      return ret+g;
}

inline int three(const int&base,const int&p){
      int ret=1;
      for(int t=zhi(3,p),b=base%mod;t;t>>=1,b=1ll*b*b%mod)
        if(t&1) ret=1ll*ret*b%mod;
      return ret;
}

int main(){
      n=qr();m=qr();mod=qr();
      phi=getphi(mod);
      for(int t=1;t<=n;++t) data[t]=qr();
      for(int t=1,t1,t2;t<=m;++t){
        if(qr()==1){
          t1=qr(); t2=qr();
          if(t2-t1+1>13) puts("Yuno");
          else{
            lit=(t2-t1+1)>>1;
            S.clear();
            for(int t=t1,g;t<=t2;++t) data[t]=f[t-t1+1]=three(data[t],g=que(t))%mod,add(t,-g),add(t+1,g);
            F=0;
            dfs(1,0,0);
            dfs2(t2-t1+1,0,0);
            if(F) puts("Yuno");
            else puts("Yuki");
          }
        }
        else{
          t1=qr(); t2=qr();
          add(t1,1); add(t2+1,-1);
        }
      }
      return 0;
}

Guess you like

Origin www.cnblogs.com/winlere/p/11604507.html