據說是12省聯考,好刺激。html
看題ios
t1是個lydsy題我還寫過博客,t2不會,t3一臉神仙。優化
這個t3數據好大啊,看到好幾我的都用gedit打開大樣例...大家就不能用firefox嗎ui
1h寫完t1,沒什麼意思spa
先寫t2暴力吧,?我怎麼只會O(nm)和O(n^2m/32)啊,寫個不知道有沒有40分的暴力就放在那了。firefox
而後開t3code
1,2,3輸出19^x便可htm
4,我求了下全部數的最大值,發現是1145099,嚇尿了,盲猜1145140,wa了,改爲1145141,過了。blog
過後發現這仍是個質數。排序
5不會
6,這種我常常犯的錯我固然會,直接
for(puts("0"),x=1,n--;n--;)printf("%d\n",x=int(ll(x)*19)%p);
7不會
8看了很久才發現是區間質數。
9好像能夠處理根號之內的再去篩?不過很難寫啊。
我直接miller_rabin行不行啊qwq
寫完了,過了8,9,10,跑的挺快。
11.能夠看出來是\(\mu(n)\),直接寫了個rho,發現跑的很慢gg了,改爲線篩
後面都不會了
這個g我竟然沒看出來是原根...
t3到最後就這48分了
看t2,這是否是隻要把A連到B,再從B連到他做爲前綴的A上就好了?
寫了個暴力驗證,確實是這樣。
那而後..不就是sam子樹連邊嗎,想了一想,這個\(|A|<|B|\)還得對每一個節點開個線段樹...還有一個小時,就只打了\(80\)暴力
UPD:能夠直接排序以後前綴優化建圖https://www.cnblogs.com/suika/p/10666961.html。
臨結束的時候發現t2沒開\(long \ long\),嚇尿了,趕忙改回來。
出分了,是\(100+80+48=228\) 沒掛分還行。
不會數數,不會貪心,自閉了。
考前starria發的果凍很贊啊
看題,三題都不會
剛了三個小時終於寫出來t1的60和t2的60。
t1 k=0的狀況能夠發現c和d的限制互不影響,而後就能夠直接作了。
t2 寫了狀壓和鏈的暴力,而後寫了個從大到小貪心刪點的暴力,沒過第三個樣例,調都沒調就扔了。
t3好難啊,我只會L=n,K=1的分啊,再加上前面有一個最裸的暴力一共有16分..
\(60+60+16\),感受比昨天低好多啊..
出來一看你們都會t1\(O(nm^2)\)的暴力,t2好幾我的過,都說是noip級別貪心..
測完發現t3多了4分,去loj交一發發現奇妙地跑過了第15個點,出題人良心啊。
總分是\(368\),怎麼比noip分還高啊
day1考場代碼:
t1
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <queue> #include <vector> #include <iostream> using namespace std; typedef long long ll; typedef unsigned int un; #define N 500050 #define M 35000050 #define db(x) cerr<<#x<<" = "<<x<<endl char buf[100000],*p1,*p2; #define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++) un rd() { un x=0; char s=nc(); while(s<'0'||s>'9') s=nc(); while(s>='0'&&s<='9') x=(((x<<2)+x)<<1)+s-'0',s=nc(); return x; } int n,K,root[N],ch[M][2],siz[M],cnt,lv; un a[N],sum[N],V[N]; vector<int>pos[N]; struct A { int x,l,r,p; un s; A() {} A(int x_,int l_,int r_,int p_,un s_) {x=x_,l=l_,r=r_,p=p_,s=s_;} bool operator < (const A &u) const {return s<u.s;} }; priority_queue<A>q; void update(int &pp,int q,un x) { int i; pp=++cnt; int p=pp; for(i=31;i>=0;i--) { int k=(x>>i)&1; int t=++cnt; siz[t]=siz[ch[q][k]]; ch[p][k]=t; ch[p][!k]=ch[q][!k]; p=ch[p][k]; q=ch[q][k]; siz[p]++; } } un query(un x,int l,int r) { int p=root[r],q=root[l-1]; int i; un re=0; for(i=31;i>=0;i--) { int k=!((x>>i)&1); if(siz[ch[p][k]]-siz[ch[q][k]]>0) { re+=(1u<<i); p=ch[p][k], q=ch[q][k]; }else { p=ch[p][!k], q=ch[q][!k]; } } return re; } int find(un x,int p) { int k=lower_bound(V+1,V+lv+1,x)-V; int t=*lower_bound(pos[k].begin(),pos[k].end(),p); return t; } int main() { //freopen("xor.in","r",stdin); //freopen("xor.out","w",stdout); n=rd(),K=rd(); int i; ll ans=0; for(i=1;i<=n;i++) { a[i]=rd(); sum[i]=sum[i-1]^a[i]; update(root[i],root[i-1],sum[i]); V[i]=sum[i]; } sort(V+1,V+n+1); lv=unique(V+1,V+n+1)-V-1; for(i=1;i<=n;i++) { int u=lower_bound(V+1,V+lv+1,sum[i])-V; pos[u].push_back(i); } for(i=1;i<=n;i++) { A x; x.x=i; x.l=i,x.r=n; x.s=query(sum[i-1],x.l,x.r); x.p=find(x.s^sum[i-1],x.l); q.push(x); } for(i=1;i<=K;i++) { A g=q.top(); q.pop(); ans+=(ll)g.s; if(g.l<g.p) { A x; x.x=g.x; x.l=g.l; x.r=g.p-1; x.s=query(sum[x.x-1],x.l,x.r); x.p=find(x.s^sum[x.x-1],x.l); q.push(x); } if(g.r>g.p) { A x; x.x=g.x; x.l=g.p+1; x.r=g.r; x.s=query(sum[x.x-1],x.l,x.r); x.p=find(x.s^sum[x.x-1],x.l); q.push(x); } } printf("%lld\n",ans); return 0; }
t2
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <bitset> using namespace std; typedef long long ll; #define N 800050 #define M 5000050 char w[N]; int n,la,lb,al[N],ar[N],bl[N],br[N],m,xx[N],yy[N]; int head[N],to[M],nxt[M],cnt,Q[N],du[N],tot,rt; int ch[N][26],fa[N],len[N],uuz,pos[N],lst=1,f[21][N]; ll g[N]; inline void add(int u,int v) { to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt; du[v]++; } void insert(int x,int id) { int p=lst,np=++uuz,q,nq; len[np]=len[p]+1; lst=np; for(;p&&!ch[p][x];p=fa[p]) ch[p][x]=np; if(!p) fa[np]=rt; else { q=ch[p][x]; if(len[q]==len[p]+1) fa[np]=q; else { nq=++uuz; fa[nq]=fa[q]; len[nq]=len[p]+1; memcpy(ch[nq],ch[q],sizeof(ch[q])); fa[q]=fa[np]=nq; for(;p&&ch[p][x]==q;p=fa[p]) ch[p][x]=nq; } } } void dfs(int x) { int i; for(i=1;(1<<i)<=uuz;i++) f[i][x]=f[i-1][f[i-1][x]]; for(i=head[x];i;i=nxt[i]) { f[0][to[i]]=x; dfs(to[i]); } } int find(int l,int r) { int p=pos[r]; int i; for(i=20;i>=0;i--) if(f[i][p]&&len[f[i][p]]>=r-l+1) p=f[i][p]; return p; } void solve() { scanf("%s",w+1); n=strlen(w+1); reverse(w+1,w+n+1); int i; ll ans=0; scanf("%d",&la); for(i=1;i<=la;i++) scanf("%d%d",&al[i],&ar[i]); scanf("%d",&lb); for(i=1;i<=lb;i++) scanf("%d%d",&bl[i],&br[i]); scanf("%d",&m); tot=la+lb; for(i=1;i<=m;i++) { scanf("%d%d",&xx[i],&yy[i]); add(xx[i],yy[i]+la); } for(i=1;i<=la;i++) { al[i]=n-al[i]+1,ar[i]=n-ar[i]+1,swap(al[i],ar[i]); } for(i=1;i<=lb;i++) { bl[i]=n-bl[i]+1,br[i]=n-br[i]+1,swap(bl[i],br[i]); } rt=tot+1;lst=tot+1;uuz=tot+1; for(i=1;i<=n;i++) insert(w[i]-'a',i),pos[i]=lst; for(i=rt+1;i<=uuz;i++) add(fa[i],i); dfs(rt); for(i=1;i<=la;i++) { int p=find(al[i],ar[i]); add(p,i); } for(i=1;i<=lb;i++) { int p=find(bl[i],br[i]); add(i+la,p); } int l=0,r=0; for(i=1;i<=uuz;i++) if(!du[i]) Q[r++]=i; while(l<r) { int x=Q[l++]; g[x]+=(x<=la?(ar[x]-al[x]+1):0); ans=max(ans,g[x]); for(i=head[x];i;i=nxt[i]) { du[to[i]]--; g[to[i]]=max(g[to[i]],g[x]); if(!du[to[i]]) Q[r++]=to[i]; } } if(r!=uuz) { puts("-1"); }else { printf("%lld\n",ans); } cnt=0; for(i=1;i<=n;i++) pos[i]=0; for(i=1;i<=uuz;i++) { fa[i]=len[i]=head[i]=du[i]=g[i]=Q[i]=0; } int j; for(i=0;(1<<i)<=uuz;i++) for(j=rt;j<=uuz;j++) f[i][j]=0; for(i=rt;i<=uuz;i++) memset(ch[i],0,sizeof(ch[i])); return ; } int main() { //freopen("string.in","r",stdin); //freopen("string.out","w",stdout); int T; scanf("%d",&T); while(T--) solve(); return 0; }
t3
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> using namespace std; typedef long long ll; typedef unsigned long long llu; typedef long double f3; char opt[1050]; char qx[1050]; ll qp(ll x,ll y,ll p) { ll re=1;for(;y;y>>=1,x=x*x%p)if(y&1)re=re*x%p; return re; } namespace Case1 { const int N=100050; int n; int main() { scanf("%d",&n); int i,j; for(i=1;i<=n;i++) { scanf("%s",qx+1); int len=strlen(qx+1); ll num=0; for(j=1;j<=len;j++) num=(num*10+qx[j]-'0')%998244352; printf("%lld\n",qp(19,num,998244353)); } return 0; } } namespace Case2 { const int mod=1145141; int n; int getphi(int x) { int re=x,i; for(i=2;i*i<=x;i++) { if(x%i==0) { re=re/i*(i-1); while(x%i==0) x/=i; } } if(x!=1) re=re/x*(x-1); return re; } int main() { scanf("%d",&n); int i,j,phi=getphi(mod); for(i=1;i<=n;i++) { scanf("%s",qx+1); int len=strlen(qx+1); ll num=0; for(j=1;j<=len;j++) num=(num*10+qx[j]-'0')%phi; printf("%lld\n",qp(19,num,mod)); } return 0; } } llu qpp(llu x,llu y) { llu re=1; for(;y;y>>=1,x=x*x)if(y&1)re=re*x;return re; } namespace Case3 { int n; int main() { int i; ll x,ans=0; for(i=1;i<=10000;i++) { scanf("%lld",&x); ans=max(ans,x); } printf("%lld\n",ans); return 0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%lld",&x); printf("%llu\n",qpp(19,x)); } return 0; } } namespace Case4 { const int N=100050; int n,mod=998244353; int qpo(int x,ll y,int p) { int re=1; for(;y;y>>=1,x=x*x) if(y&1) re=ll(re)*x%p; return re%p; } int main() { scanf("%d",&n); if(n==100000) { int i,now=1; for(i=1;i<=n;i++) { printf("%d\n",now); now=int(ll(now)*19)%mod; } }else { int i; ll x; for(i=1;i<=n;i++) { scanf("%lld",&x); printf("%d\n",qpo(19,x,mod)); } } return 0; } } namespace Case5 { char w[1000050]; int pri[100005],cnt,n,isp[1000050]; ll ch(ll x,ll y,ll p) { x%=p,y%=p; return ((x*y-ll(f3(x)*y/p+0.5)*p)%p+p)%p; } ll qpp(ll x,ll y,ll p) { ll re=1;for(;y;y>>=1,x=ch(x,x,p))if(y&1)re=ch(re,x,p);return re; } bool check(ll n,ll r,ll s,ll x) { x=qpp(x,s,n); ll y=x; int i; for(i=1;i<=r;i++) { x=ch(x,x,n); if(x==1&&y!=1&&y!=n-1) return 0; y=x; }return x==1; } bool miller(ll n) { int i; for(i=1;i<=13;i++) { if(n==pri[i]) return 1; if(n%pri[i]==0) return 0; } ll r=0,s=n-1; while(!(s&1)) s>>=1,r++; for(i=1;i<=5;i++) if(!check(n,r,s,pri[i])) return 0; return 1; } void sieve(int n) { int i,j; for(i=2;i<=n;i++) { if(!isp[i]) pri[++cnt]=i; for(j=1;j<=cnt&&i*pri[j]<=n;j++) { isp[i*pri[j]]=1; if(i%pri[j]==0) break; } } } int main() { sieve(100000); ll i,l,r; scanf("%d",&n); while(n--) { scanf("%lld%lld",&l,&r); for(i=l;i<=r;i++) { if(miller(i)) printf("p"); else printf("."); } puts(""); } return 0; } } namespace Case6 { char w[1000050]; int pri[100005],cnt,n,isp[1000050],mu[1000050]; ll ch(ll x,ll y,ll p) { x%=p,y%=p; return ((x*y-ll(f3(x)*y/p+0.5)*p)%p+p)%p; } ll gcd(ll x,ll y) {return y?gcd(y,x%y):x;} ll qpp(ll x,ll y,ll p) { ll re=1;for(;y;y>>=1,x=ch(x,x,p))if(y&1)re=ch(re,x,p);return re; } ll R() { return rand()*(1ll<<45)+rand()*(1ll<<30)+(rand()<<15)+rand(); } bool check(ll n,ll r,ll s,ll x) { x=qpp(x,s,n); ll y=x; int i; for(i=1;i<=r;i++) { x=ch(x,x,n); if(x==1&&y!=1&&y!=n-1) return 0; y=x; }return x==1; } bool miller(ll n) { int i; for(i=1;i<=13;i++) { if(n==pri[i]) return 1; if(n%pri[i]==0) return 0; } ll r=0,s=n-1; while(!(s&1)) s>>=1,r++; for(i=1;i<=5;i++) if(!check(n,r,s,pri[i])) return 0; return 1; } ll PR(ll n,ll c) { ll x=c,y=c,p=n; for(;p==n;) { x=(ch(x,x,n)+c)%n; y=(ch(y,y,n)+c)%n; y=(ch(y,y,n)+c)%n; p=gcd(p,y>x?y-x:x-y); } return p; } int muu(ll x) { if(x==1) return 1; if(miller(x)) return -1; int i; for(i=1;i<=100;i++) { if(x==pri[i]) return -1; if(x%pri[i]==0) { ll t=x/pri[i]; if(t%pri[i]==0) return 0; return -muu(t); } } ll t=1; for(;t==1;t=PR(x,R()%x)); ll v=x/t; if(gcd(t,v)!=1) return 0; return muu(t)*muu(v); } void sieve(int n) { int i,j; for(i=2;i<=n;i++) { if(!isp[i]) pri[++cnt]=i,mu[i]=-1; for(j=1;j<=cnt&&i*pri[j]<=n;j++) { isp[i*pri[j]]=1; if(i%pri[j]==0) break; mu[i*pri[j]]=-mu[i]; } } } int main() { srand(2329); sieve(1000000); ll i,l,r; scanf("%d",&n); while(n--) { scanf("%lld%lld",&l,&r); for(i=l;i<=r;i++) { int t=mu[i]; if(t==1) printf("+"); else if(t==-1) printf("-"); else printf("0"); } puts(""); } return 0; } } namespace Case7 { char w[1000050]; int main() { scanf("%*s%*s%s",w+1); int n=strlen(w+1); int i; for(i=1;i<=n;i++) { if(w[i]=='g') printf("%d\n",i+1); } return 0; } } int main() { //freopen("software.in","r",stdin); //freopen("software.out","w",stdout); scanf("%s",opt+1); if(opt[1]=='1'&&opt[2]=='_') return Case1::main(); if(opt[1]=='1'&&opt[2]=='?'&&strlen(opt+1)==2) return Case2::main(); if(opt[1]=='1'&&opt[2]=='?') return Case3::main(); if(opt[1]=='1'&&opt[2]=='w') return Case4::main(); if(opt[1]=='2'&&opt[2]=='p') return Case5::main(); if(opt[1]=='2'&&opt[2]=='u') return Case6::main(); if(opt[1]=='2'&&opt[2]=='g') return Case7::main(); }
都好長啊md