JLOI2019游记

JLOI2019游记

DAY -???

听说是12省联考,好刺激。

DAY 1

看题

t1是个lydsy题我还写过博客,t2不会,t3一脸神仙。

这个t3数据好大啊,看到好几个人都用gedit打开大样例...你们就不能用firefox吗

1h写完t1,没什么意思

先写t2暴力吧,?我怎么只会O(nm)和O(n^2m/32)啊,写个不知道有没有40分的暴力就放在那了。

然后开t3

1,2,3输出19^x即可

4,我求了下所有数的最大值,发现是1145099,吓尿了,盲猜1145140,wa了,改成1145141,过了。

事后发现这还是个质数。

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\) 没挂分还行。

DAY 2

不会数数,不会贪心,自闭了。

考前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

posted @ 2019-04-08 15:34  fcwww  阅读(1107)  评论(8编辑  收藏  举报