Ynoi(5/35)
luoguP5309 [Ynoi2012]D1T1
luoguP5310 [Ynoi2012]D1T2
luoguP5311 [Ynoi2012]D1T3
luoguP5312 [Ynoi2012]D2T1
luoguP5313 [Ynoi2012]D2T2
luoguP5314 [Ynoi2012]D2T3
luoguP5062 [Ynoi2014]在太阳西斜的这个世界里
luoguP5063 [Ynoi2014]置身天上之森
luoguP5064 [Ynoi2014]等这场战争结束之后
luoguP5065 [Ynoi2014]不归之人与望眼欲穿的人们
luoguP5066 [Ynoi2014]人人本着正义之名
luoguP5067 [Ynoi2014]长存不灭的过去,逐渐消逝的未来
luoguP5068 [Ynoi2015]我回来了
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 typedef unsigned long long ull; 5 const int N=1005,inf=1e9+7; 6 int n,m,q,x,dis[N][N]; 7 queue<int>Q;vector<int>g[N]; 8 bitset<N>ans,f[N][N]; 9 int main() 10 { 11 scanf("%d%d%d",&n,&m,&q); 12 for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dis[i][j]=inf; 13 for(int i=1;i<=m;i++){int a,b;scanf("%d%d",&a,&b);g[a].push_back(b);g[b].push_back(a);} 14 for(int i=1;i<=n;i++) 15 { 16 Q.push(i);dis[i][i]=0;x=i;f[i][0].set(i); 17 while(!Q.empty()) 18 { 19 int t=Q.front();Q.pop(); 20 for(int j=0;j<g[t].size();j++) 21 { 22 int v=g[t][j]; 23 if(dis[i][v]==inf){dis[i][v]=dis[i][t]+1;Q.push(v);f[i][dis[i][v]].set(v);} 24 } 25 } 26 for(int j=1;j<=n;j++)f[i][j]|=f[i][j-1]; 27 } 28 while(q--) 29 { 30 int t;scanf("%d",&t);ans.reset(); 31 while(t--){int a,b;scanf("%d%d",&a,&b);if(b>n)b=n;ans|=f[a][b];} 32 printf("%d\n",ans.count()); 33 } 34 return 0; 35 }
luoguP5069 [Ynoi2015]纵使日薄西山
luoguP5070 [Ynoi2015]即便看不到未来
luoguP5071 [Ynoi2015]此时此刻的光辉
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int N=100005,M=32005,K=150,P=19260817; 5 int n,m,res=1,cc,mx,W,lim,a[N],ans[N],bel[N],pr[N*2],cnt[N*2],inv[N*20],sum[N][155],vis[M]; 6 map<int,int>mp;vector<pair<int,int> >v[N]; 7 struct qq{int l,r,i;}q[N]; 8 inline bool cmp(qq a,qq b){return bel[a.l]==bel[b.l]?(bel[a.l]&1?a.r>b.r:a.r<b.r):a.l<b.l;} 9 inline void upd(int x,int p,int q){if(p<=K)sum[x][p]+=q;else v[x].push_back(make_pair(p,q));} 10 inline void pre(int a,int x) 11 { 12 for(int i=1;pr[i]*pr[i]<=a&&i<=pr[0];i++)if(a%pr[i]==0){int q=0;while(!(a%pr[i]))a/=pr[i],q++;upd(x,i,q);} 13 if(a!=1){int t=mp[a];if(!t)mp[a]=t=++cc,pr[cc]=a;upd(x,t,1);} 14 } 15 inline void add(int x,int o) 16 { 17 for(int i=0;i<v[x].size();i++) 18 { 19 int p=v[x][i].first,q=v[x][i].second; 20 res=1ll*res*inv[cnt[p]]%P;cnt[p]+=o*q;res=1ll*res*cnt[p]%P; 21 } 22 } 23 int main() 24 { 25 scanf("%d%d",&n,&m);W=n/sqrt(m*2.0/3); 26 for(int i=1;i<=n;i++){scanf("%d",&a[i]);mx=max(mx,a[i]);bel[i]=(i-1)/W;} 27 lim=sqrt(mx); 28 for(int i=2;i<=lim;i++) 29 { 30 if(!vis[i])pr[++pr[0]]=i,mp[i]=pr[0]; 31 for(int j=1;j<=pr[0]&&i*pr[j]<=lim;j++){vis[i*pr[j]]=1;if(i%pr[j]==0)break;} 32 } 33 cc=pr[0];mx=0; 34 for(int i=1;i<=n;i++){for(int j=1;j<=K;j++)sum[i][j]=sum[i-1][j];pre(a[i],i);} 35 inv[1]=1; 36 for(int i=2;i<=2000000;i++)inv[i]=1ll*(P-P/i)*inv[P%i]%P; 37 for(int i=1;i<=cc;i++)cnt[i]=1; 38 for(int i=1;i<=m;i++)scanf("%d%d",&q[i].l,&q[i].r),q[i].i=i; 39 sort(q+1,q+m+1,cmp);int L=1,R=0; 40 for(int i=1;i<=m;i++) 41 { 42 int ql=q[i].l,qr=q[i].r; 43 while(L>ql)add(--L,1); 44 while(R<qr)add(++R,1); 45 while(L<ql)add(L++,-1); 46 while(R>qr)add(R--,-1); 47 ans[q[i].i]=res; 48 for(int j=1;j<=K;j++)ans[q[i].i]=1ll*ans[q[i].i]*(sum[R][j]-sum[L-1][j]+1)%P; 49 } 50 for(int i=1;i<=m;i++)printf("%d\n",ans[i]); 51 return 0; 52 }
luoguP5072 [Ynoi2015]盼君勿忘
luoguP5073 [Ynoi2015]世上最幸福的女孩
luoguP4118 [Ynoi2016]炸脖龙I
1 #include<bits/stdc++.h>
2 using namespace std;
3 const int N=500005,M=20000005,inf=1e8;
4 #define ll long long
5 int cc,vis[M],pr[M/10],phi[M];
6 int n,m,a[N];ll c[N];
7 inline void init()
8 {
9 for(int i=2;i<M;i++)
10 {
11 if(!vis[i])pr[++cc]=i,phi[i]=i-1;
12 for(int j=1;j<=cc&&i*pr[j]<M;j++)
13 {
14 vis[i*pr[j]]=1;
15 if(i%pr[j]==0){phi[i*pr[j]]=phi[i]*pr[j];break;}
16 phi[i*pr[j]]=phi[i]*(pr[j]-1);
17 }
18 }
19 }
20 inline void upd(int x,int v){for(;x<=n;x+=x&-x)c[x]+=v;}
21 inline ll qry(int x){ll r=0;for(;x;x-=x&-x)r+=c[x];return r;}
22 inline ll pw(ll x,ll y,ll p)
23 {
24 ll r=1;int tx=0,tr=0;
25 for(;y;y>>=1)
26 {
27 if(y&1){r=r*x;tr|=tx;if(r>=p)r%=p,tr=1;}
28 if(x>=p)tx=1,x%=p;x=x*x;if(x>=p)tx=1,x%=p;
29 }
30 return r+(tr?p:0);
31 }
32 inline ll sol(int x,int r,ll p){if(p==1||x>r)return 1;ll w=qry(x)+a[x],y=sol(x+1,r,phi[p]);return pw(w,y,p);}
33 int main()
34 {
35 init();scanf("%d%d",&n,&m);
36 for(int i=1;i<=n;i++)scanf("%d",&a[i]);
37 for(int i=1;i<=m;i++)
38 {
39 int o,l,r,x;scanf("%d%d%d%d",&o,&l,&r,&x);
40 if(o==1)upd(l,x),upd(r+1,-x);else printf("%lld\n",sol(l,r,x)%x);
41 }
42 return 0;
43 }
luoguP4688 [Ynoi2016]掉进兔子洞
1 #include<bits/stdc++.h>
2 using namespace std;
3 const int N=100100,T=25000;
4 inline int rd()
5 {
6 int x=0;char c=getchar();while(!isdigit(c))c=getchar();
7 while(isdigit(c))x=x*10+c-48,c=getchar();return x;
8 }
9 int n,m,W,cc,a[N],b[N],l1[N],l2[N],l3[N],r1[N],r2[N],r3[N],bel[N],cnt[N],ans[N],vis[T+10];
10 bitset<N>f[T+10],tmp;
11 struct qq{int l,r,i,p;}q[N];
12 inline bool cmp(const qq a,const qq b){return a.p<b.p||(a.p==b.p&&a.r<b.r);}
13 inline void upd(int x,int o){x=a[x];if(o<0)tmp[x+cnt[x]-1]=0;else tmp[x+cnt[x]]=1;cnt[x]+=o;}
14 inline void sol(int x,int y)
15 {
16 memset(cnt,0,sizeof(cnt));memset(vis,0,sizeof(vis));cc=0;tmp.reset();int l=1,r=0;
17 for(int i=x;i<=y;i++)
18 {
19 q[++cc]=(qq){l1[i],r1[i],i,bel[l1[i]]};q[++cc]=(qq){l2[i],r2[i],i,bel[l2[i]]};
20 q[++cc]=(qq){l3[i],r3[i],i,bel[l3[i]]};ans[i]=r1[i]-l1[i]+r2[i]-l2[i]+r3[i]-l3[i]+3;
21 }
22 sort(q+1,q+cc+1,cmp);
23 for(int i=1;i<=cc;i++)
24 {
25 while(r<q[i].r)r++,upd(r,1);
26 while(l>q[i].l)l--,upd(l,1);
27 while(r>q[i].r)upd(r,-1),r--;
28 while(l<q[i].l)upd(l,-1),l++;
29 int t=q[i].i-x+1;if(!vis[t])vis[t]=1,f[t]=tmp;else f[t]&=tmp;
30 }
31 for(int i=x;i<=y;i++)ans[i]-=f[i-x+1].count()*3;
32 }
33 int main()
34 {
35 n=rd();m=rd();W=sqrt(n);
36 for(int i=1;i<=n;i++){a[i]=rd();b[i]=a[i];bel[i]=(i-1)/W+1;}
37 sort(b+1,b+n+1);
38 for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+n+1,a[i])-b;
39 for(int i=1;i<=m;i++){l1[i]=rd();r1[i]=rd();l2[i]=rd();r2[i]=rd();l3[i]=rd();r3[i]=rd();}
40 for(int i=1;i<=m;i+=T)sol(i,min(m,i+T-1));
41 for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
42 return 0;
43 }
luoguP4689 [Ynoi2016]这是我自己的发明
luoguP4690 [Ynoi2016]镜中的昆虫
luoguP4692 [Ynoi2016]谁的梦
luoguP4693 [Ynoi2016]炸脖龙II
luoguP5354 [Ynoi2017]由乃的OJ
luoguP5355 [Ynoi2017]由乃的玉米田
luoguP5356 [Ynoi2017]由乃打扑克
luoguP4680 [Ynoi2018]末日时在做什么?有没有空?可以来拯救吗?
luoguP4117 [Ynoi2018]五彩斑斓的世界
luoguP4119 [Ynoi2018]未来日记
luoguP5398 [Ynoi2018]GOSICK
1 #include<bits/stdc++.h>
2 using namespace std;
3 #define ll long long
4 #define pb push_back
5 const int N=100005,M=100000,W=500;
6 int n,m,a[N],b[N],c[N],ss[N],r1[N],r2[N],r3[N],r4[N];ll p1[N],p2[N],res[N<<1],ans[N];
7 struct st{int l,r,i;}q[N];vector<st>g[N];vector<int>V[N];
8 inline bool cmp(st a,st b){return a.l/W^b.l/W?a.l<b.l:a.r<b.r;}
9 inline void init()
10 {
11 for(int i=1;i<=M;i++)for(int j=i;j<=M;j+=i)V[j].pb(i);
12 for(int i=1;i<=M;i++)for(int j=1;j<=32;j++)if(i%j==0)ss[i]|=1<<j-1;
13 }
14 void ins(int x)
15 {
16 if(x<=32)
17 {
18 if(x<=8)for(int i=0;i<256;i++)r1[i]+=(i>>(x-1)&1);
19 else if(x<=16)for(int i=0;i<256;i++)r2[i]+=(i>>(x-9)&1);
20 else if(x<=24)for(int i=0;i<256;i++)r3[i]+=(i>>(x-17)&1);
21 else for(int i=0;i<256;i++)r4[i]+=(i>>(x-25)&1);
22 }
23 else for(int i=x;i<=M;i+=x)b[i]++;
24 }
25 inline int calc(int x){x=ss[x];return r1[x&255]+r2[x>>8&255]+r3[x>>16&255]+r4[x>>24&255];}
26 inline int sum(int x){return b[x]+c[x]+calc(x);}
27 int main()
28 {
29 scanf("%d%d",&n,&m);init();
30 for(int i=1;i<=n;i++)scanf("%d",&a[i]);
31 for(int i=1;i<=m;i++){scanf("%d%d",&q[i].l,&q[i].r);q[i].i=i;}
32 sort(q+1,q+m+1,cmp);int l=1,r=0;
33 for(int i=1;i<=m;i++)
34 {
35 if(l<q[i].l)g[r].pb((st){l,q[i].l-1,i<<1});else if(l>q[i].l)g[r].pb((st){q[i].l,l-1,i<<1});l=q[i].l;
36 if(r<q[i].r)g[l-1].pb((st){r+1,q[i].r,i<<1|1});else if(r>q[i].r)g[l-1].pb((st){q[i].r+1,r,i<<1|1});r=q[i].r;
37 }
38 for(int i=1;i<=n;i++)
39 {
40 p1[i]=p1[i-1]+sum(a[i]);
41 for(int j=0;j<V[a[i]].size();j++)c[V[a[i]][j]]++;
42 ins(a[i]);p2[i]=p2[i-1]+sum(a[i]);
43 for(int j=0;j<g[i].size();j++){st t=g[i][j];for(int k=t.l;k<=t.r;k++)res[t.i]+=sum(a[k]);}
44 }
45 l=1,r=0;ll s=0;
46 for(int i=1;i<=m;i++)
47 {
48 if(l<q[i].l)s+=p2[q[i].l-1]-p2[l-1]-res[i<<1];else if(l>q[i].l)s+=res[i<<1]+p2[q[i].l-1]-p2[l-1];l=q[i].l;
49 if(r<q[i].r)s+=p1[q[i].r]-p1[r]-res[i<<1|1];else if(r>q[i].r)s+=res[i<<1|1]-p1[r]+p1[q[i].r];r=q[i].r;ans[q[i].i]=s+r-l+1;
50 }
51 for(int i=1;i<=m;i++)printf("%lld\n",ans[i]);
52 return 0;
53 }
luoguP5399 [Ynoi2018]駄作
luoguP5046 [Ynoi2019模拟赛]Yuno loves sqrt technology I
luoguP5047 [Ynoi2019模拟赛]Yuno loves sqrt technology II
luoguP5048 [Ynoi2019模拟赛]Yuno loves sqrt technology III