Escapism, is a short-lived relief.
10/0/0/0
The first question title is wrong, skip.
1536. seek (Standard IO)
This question made me pick up a string algorithms Xu Jiumei move.
Nothing to say, it is more a hash value.
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef unsigned long long ull; 4 const int N=4e5+10; 5 char c[N]; 6 ull h[N],g[N]; 7 void hash(){ 8 g[0]=1; 9 for(int i=1;c[i];i++){ 10 h[i]=h[i-1]*131+c[i]; 11 g[i]=g[i-1]*131; 12 } 13 } 14 int main(){ 15 scanf("%s",c+1); 16 hash(); 17 ull len=strlen(c+1); 18 for(ull i=1;i<=len;i++){ 19 ull tt=h[len]-h[len-i]*g[i]; 20 if(tt==h[i]) printf("%lld ",i); 21 } 22 return 0; 23 }
1537. pot (Standard IO)
This is a cool title, sub-segments and take dp problems that have been written, before we know today but also with tree line.
Maintenance of the following:
- Maximum prefix and
- And maximum suffix
- And the largest sub-segment
- And the smallest prefix
- The minimum and suffixes
- And a minimal segment
- Intervals and
(Really cancer)
But the update is very simple (maximum prefix maximum prefix largest range of + left subtree and right subtree and left subtree and) such that the maximum prefixes and max, other similar.
The answer is max (maximum and sub-segment, and the interval - and a minimal segment).
1 #include<bits/stdc++.h> 2 #define f(i,a,b) for(int i=a;i<=b;i++) 3 #define as a[o].sum 4 #define abp a[o].big_pre_sum 5 #define abl a[o].big_las_sum 6 #define asp a[o].small_pre_sum 7 #define asl a[o].small_las_sum 8 #define bs a[o].big_sum; 9 #define ss a[o].small_sum; 10 using namespace std; 11 typedef long long ll; 12 const ll N=2e5+10; 13 ll idx[N],pre[N],las[N]; 14 ll n,m,maxans; 15 struct tree{ 16 ll sum; 17 ll big_pre_sum; 18 ll big_las_sum; 19 ll small_pre_sum; 20 ll small_las_sum; 21 ll big_sum; 22 ll small_sum; 23 }a[N<<2]; 24 ll ls(ll o){return o<<1;} 25 ll rs(ll o){return o<<1|1;} 26 void pushup(ll o){ 27 as=a[ls(o)].sum+a[rs(o)].sum; 28 abp=max(a[ls(o)].sum+a[rs(o)].big_pre_sum,a[ls(o)].big_pre_sum); 29 asp=min(a[ls(o)].sum+a[rs(o)].small_pre_sum,a[ls(o)].small_pre_sum); 30 abl=max(a[ls(o)].big_las_sum+a[rs(o)].sum,a[rs(o)].big_las_sum); 31 asl=min(a[ls(o)].small_las_sum+a[rs(o)].sum,a[rs(o)].small_las_sum); 32 a[o].big_sum=max(max(a[ls(o)].big_sum,a[rs(o)].big_sum),a[ls(o)].big_las_sum+a[rs(o)].big_pre_sum); 33 a[o].small_sum=min(min(a[ls(o)].small_sum,a[rs(o)].small_sum),a[ls(o)].small_las_sum+a[rs(o)].small_pre_sum); 34 } 35 void build(ll o,ll l,ll r){ 36 if(l==r){ 37 as=abp=asp=abl=asl=a[o].big_sum=a[o].small_sum=idx[l]; 38 return; 39 } 40 ll mid=(l+r)>>1; 41 build(ls(o),l,mid); 42 build(rs(o),mid+1,r); 43 pushup(o); 44 } 45 void change(ll o,ll l,ll r,ll x,ll y){ 46 if(l>x||r<x) return; 47 if(l==r&&l==x){ 48 as=abp=asp=abl=asl=a[o].big_sum=a[o].small_sum=y; 49 return; 50 } 51 ll mid=(l+r)>>1; 52 if(x<=mid) change(ls(o),l,mid,x,y); 53 else change(rs(o),mid+1,r,x,y); 54 pushup(o); 55 } 56 //tree query(ll o,ll l,ll r,ll x,ll y){ 57 // if(l>=x&&r<=y){ 58 // return a[o]; 59 // } 60 // ll mid=(l+r)>>1; 61 // if(y<=mid) return query(ls(o),l,mid,x,y); 62 // if(x>mid) return query(rs(o),mid+1,r,x,y); 63 // else{ 64 // tree ans,l_,r_; 65 // l_=query(ls(o),l,mid,x,y),r_=query(rs(o),mid+1,r,x,y); 66 // ans.sum=l_.sum+r_.sum; 67 // ans.big_pre_sum=max(l_.big_pre_sum,l_.sum+r_.big_pre_sum); 68 // ans.big_las_sum=max(r_.big_las_sum,l_.big_las_sum+r_.sum); 69 // ans.small_las_sum=min(r_.small_las_sum,l_.small_las_sum+r_.sum); 70 // ans.small_pre_sum=min(l_.small_pre_sum,l_.sum+r_.small_pre_sum); 71 // ans.big_sum=max(max(l_.big_sum,r_.big_sum),l_.big_las_sum+r_.big_pre_sum); 72 // ans.small_sum=min(min(l_.small_sum,r_.small_sum),l_.small_las_sum+r_.small_pre_sum); 73 // return ans; 74 // } 75 //}//------------------------------------------------------------------------后来才发现不用打这个 76 int main(){ 77 // freopen("data.in","r",stdin); 78 scanf("%lld",&n); 79 f(i,1,n) scanf("%lld",&idx[i]); 80 build(1,1,n); 81 scanf("%lld",&m); 82 ll akai,hatto; 83 f(i,1,m){ 84 scanf("%lld%lld",&akai,&hatto);//乱入一个心心 85 change(1,1,n,akai,hatto); 86 tree tmp=a[1]; 87 maxans=max(tmp.big_sum,tmp.sum-tmp.small_sum); 88 printf("%lld\n",maxans); 89 } 90 return 0; 91 }
3512. Game show (Show)
(File IO): the INPUT: show.in the Output: show.out
This question can be considered 40% dfs + pruning, or like pressure dp
For 100%, using a binary search CDQ partition.
In computer science, a binary search (English: half-interval search), also known as binary search (English: binary search), logarithmic search (English: logarithmic search), is a find a particular element in an ordered array the search algorithm. --Baidu Encyclopedia
1. observations, n <= 34, and used like a conventional pressure dp fly search will obviously T, then we will search for content in half, up to the number 17 on each side, each answer search statistics.
2. We use a tuple indicates that the search, and found , is not like a two-dimensional partial order problem?
3. After 34 evaluates, we processing section k is, the answer can be obtained when a <= k enumerate, so the final answer is ans [n] -ans [k].
4. The program is not completed, do not transfer.
1 #include<bits/stdc++.h> 2 //#pragma GCC optimize(3) 3 using namespace std; 4 const int inf=1e9; 5 #define f(i,a,b) for(int i=a;i<=b;i++) 6 const int N=40; 7 const int M=2e5+10; 8 int sum[1<<8]; 9 int n,cnt,root,k,ans2; 10 struct point{ 11 int a,b,c; 12 }p[M]; 13 bool cmp(point t1,point t2){ 14 return t1.a==t2.a?t1.b<t2.b:t1.a<t2.a; 15 } 16 bool cmp2(point t1,point t2){ 17 return t1.b==t2.b?t1.a<t2.a:t1.b<t2.b; 18 } 19 struct peo{ 20 int a,b,c; 21 }e[N]; 22 void dfs1(int st,int nd,int sum1,int sum2,int sum3){ 23 if(st>nd){ 24 p[++cnt].a=sum2-sum1; 25 p[cnt].b=sum3-sum1; 26 p[cnt].c=0; 27 return; 28 } 29 dfs1(st+1,nd,sum1+e[st].a,sum2+e[st].b,sum3+e[st].c); 30 dfs1(st+1,nd,sum1,sum2,sum3); 31 } 32 void dfs2(int st,int nd,int sum1,int sum2,int sum3){ 33 if(st>nd){ 34 p[++cnt].a=sum1-sum2; 35 p[cnt].b=sum1-sum3; 36 p[cnt].c=1; 37 return; 38 } 39 dfs2(st+1,nd,sum1+e[st].a,sum2+e[st].b,sum3+e[st].c); 40 dfs2(st+1,nd,sum1,sum2,sum3); 41 } 42 void dfs3(int x,int num,int sum1,int sum2){ 43 if(num>=k) return; 44 if(x>n){ 45 if(sum1>0&&sum2>0) ans2++; 46 return; 47 } 48 dfs3(x+1,num+1,sum1+e[x].a-e[x].b,sum2+e[x].a-e[x].c); 49 dfs3(x+1,num,sum1,sum2); 50 } 51 struct array{ 52 int a[M],kk; 53 int lb(int x){return x&-x;} 54 int query(int x){int ans=0;for(;x;x-=lb(x))ans+=a[x];return ans;} 55 void add(int x,int y){for(;x<=kk;x+=lb(x))a[x]+=y;} 56 }pp,qq; 57 int main(){ 58 // freopen("show.in","r",stdin); 59 // freopen("show.out","w",stdout); 60 scanf("%d%d",&n,&k); 61 f(i,1,n) scanf("%d",&e[i].a); 62 f(i,1,n) scanf("%d",&e[i].b); 63 f(i,1,n) scanf("%d",&e[i].c); 64 int mid=(1+n)>>1; 65 dfs1(1,mid,0,0,0); 66 dfs2(mid+1,n,0,0,0); 67 sort(p+1,p+cnt+1,cmp2); 68 int nn=-inf,cc=0,ans=0; 69 f(i,1,cnt){ 70 if(p[i].b>nn){ 71 p[i].b=++cc; 72 nn=p[i].b; 73 } 74 else p[i].b=nn; 75 } 76 pp.kk=cnt; 77 sort(p+1,p+cnt+1,cmp); 78 f(i,1,cnt){ 79 if(!p[i].c) pp.add(p[i].b,1); 80 } 81 f(i,1,cnt) if(p[i].c) ans+=pp.a[i]; 82 // f(i,1,cnt) printf("%d %d %d\n",p[i].a,p[i].b,p[i].c); 83 dfs3(1,0,0,0); 84 printf("%d",ans-ans2); 85 return 0; 86 }
adjust your mindset.