T1rank
Description
Input
The second row, a non-negative integer n, denotes the n student performance.
Output
Sample Input
5 3 1 1 2 2 3
Sample Output
1 1 2
Examination room ideas / positive solution
Title simply means that you want to sort it, but the range of available observational data, better use barrels row here, so gone.
Code
#include<cstdio> #include<algorithm> int n,k,v,sl,zx,cc; int book[100010]; int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { scanf("%d",&v); book[v]++; } for(int i=0;i<=100000;i++) { cc=sl; sl+=book[i]; if(sl>=k) { zx=i; break; } } for(int i=0;i<zx;i++) if(book[i]) for(int j=1;j<=book[i];j++) printf("%d ",i); for(int i=cc;i<k;i++) printf("%d ",zx); return 0; }
T2seek
Description
Input
Output
Sample Input
abcddabc
Sample Output
3 8
Examination room ideas / positive solution
Very bare KMP, needs no explanation. .
Code
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int len,k,num; int Next[400040],zx[400040]; char ch[400040]; int main() { scanf("%s",ch+1); len=strlen(ch+1); for(int i=2;i<=len;i++) { while(k>0 && ch[k+1]!=ch[i]) k=Next[k]; if(ch[k+1]==ch[i]) k++; Next[i]=k; } k=Next[len]; while(k>0) { zx[++num]=k; k=Next[k]; } for(int i=num;i>=1;i--) printf("%d ",zx[i]); printf("%d",len); return 0; }
T3pot
Description
Input
second row, the number n, the preference value for each potted.
Third row: m, the number of changes of
the m rows, each two numbers ki and di.
Output
Sample Input
5 3 -2 1 2 -5 4 2 -2 5 -5 2 -4 5 -1
Sample Output
4 4 3 5
Examination room ideas
Hit a 30 points during the examination of violence, okay, not necessarily hang up.
Correct
I later learned that positive solutions tears fall. Wow, more than a simple I thought. First, the maximum and minimum and maximum and actually the entire sub-segment and sub-segment by subtracting consecutive sub-segments in a continuous and takes a maximum value in the sub-ring segments. (This is what I do not know eh.) And then maintain it at a tree line just add, after finished, in 10 minutes directly to this topic A, and even compile all right, did not expect positive solution exams, pity .
Code
#include<cstdio> #include<algorithm> using namespace std; int n,m,zx,d; struct TREE { int l,r; int sum; int lmin,rmin,smin; int lmax,rmax,smax; }tree[100010*8]; void Update(int k) { tree[k].sum=tree[k*2].sum+tree[k*2+1].sum; tree[k].lmin=min(tree[k*2].lmin,tree[k*2].sum+tree[k*2+1].lmin); tree[k].rmin=min(tree[k*2+1].rmin,tree[k*2].rmin+tree[k*2+1].sum); tree[k].lmax=max(tree[k*2].lmax,tree[k*2].sum+tree[k*2+1].lmax); tree[k].rmax=max(tree[k*2+1].rmax,tree[k*2].rmax+tree[k*2+1].sum); tree[k].smin=min(tree[k*2].rmin+tree[k*2+1].lmin,min(tree[k*2].smin,tree[k*2+1].smin)); tree[k].smax=max(tree[k*2].rmax+tree[k*2+1].lmax,max(tree[k*2].smax,tree[k*2+1].smax)); } void Build(int L,int R,int k) { int Mid=(L+R)/2; tree[k].l=L;tree[k].r=R; if(L==R) { scanf("%d",&tree[k].sum); tree[k].lmin=tree[k].rmin=tree[k].smin=tree[k].lmax=tree[k].rmax=tree[k].smax=tree[k].sum; return; } Build(L,Mid,k*2); Build(Mid+1,R,k*2+1); Update(k); } void Work(int L,int R,int k) { int Mid=(L+R)/2; if(L==R) { tree[k].sum=tree[k].lmin=tree[k].rmin=tree[k].smin=tree[k].lmax=tree[k].rmax=tree[k].smax=d; return; } if(zx<=Mid) Work(L,Mid,k*2); if(Mid<zx) Work(Mid+1,R,k*2+1); Update(k); } int main() { scanf("%d",&n); Build(1,n,1); scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%d%d",&zx,&d); Work(1,n,1); printf("%d\n",max(tree[1].smax,tree[1].sum-tree[1].smin)); } return 0; }
T4 game show
Description
Input
Second row, n-integers, respectively, A [1], A [2 ], A [3] ... A [n].
Third row, n-integers, namely B [1], B [2 ], B [3] ... B [n].
Fourth row, n-integers, are C [1], C [2 ], C [3] ... C [n].
Output
Sample Input
3 2
1 1 2
1 1 1
1 1 1
Sample Output
3
[explain] Sample
program: Select program 1 and program 3.
Option II: Select program 2, and program 3.
Program III: Select program 1, program 2, program 3.
Data Constraint
Data for 100%, 2 <= n <= 34 , 1 <= k <= min (n, 7), 1 <= A [i], B [i], C [i] <= 10 ^ 9.
Examination room ideas
No Guannameduo exam, anyway, violence is the right thing.
Correct
This problem seems to be using the binary search is then maintained in an array plus a tree or tree line. (A bit sleepy, it is unknown that I believe that smart readers will be seen trekking in the code I wanted to say.)
Code
#include<cstdio> #include<algorithm> #define lowbit(x) x&-x #define LL long long #define NAME "show" using namespace std; LL n,kk,ans1,ans2,Count,t,zz; LL a[55],b[55],c[55],tot[2],sz[262160]; struct thm1 { LL x,y; }q[2][131080]; struct thm2 { LL x; LL xb; LL mark; }zx[262160]; void Open()<%freopen(NAME".in","r",stdin);freopen(NAME".out","w",stdout);%> void Dfs1(LL x,LL k,LL suma,LL sumb,LL sumc) { if(x==kk) return; if(suma>sumb && suma>sumc) ans2++; for(LL i=k;i<=n;i++) Dfs1(x+1,i+1,suma+a[i],sumb+b[i],sumc+c[i]); } void Dfs2(LL k,LL sumab,LL sumac,LL pd,LL end) { q[pd][++tot[pd]].x=sumab; q[pd][tot[pd]].y=sumac; for(LL i=k;i<=end;i++) Dfs2(i+1,sumab+(a[i]-b[i]),sumac+(a[i]-c[i]),pd,end); } void init() { scanf("%lld%lld",&n,&kk); for(LL i=1;i<=n;i++) scanf("%lld",&a[i]); for(LL i=1;i<=n;i++) scanf("%lld",&b[i]); for(LL i=1;i<=n;i++) scanf("%lld",&c[i]); } bool cmp1(thm2 a,thm2 b) <%return a.x<b.x;%> bool cmp2(thm1 a,thm1 b) <%return a.y<b.y;%> bool cmp3(thm1 a,thm1 b) <%return a.y>b.y;%> void Update(LL x) { while(x<=t) { sz[x]+=1; x+=lowbit(x); } } LL Sum(LL x) { LL sum=0; while(x>=1) { sum+=sz[x]; x-=lowbit(x); } return sum; } int main() { Open(); init(); Dfs1(0,1,0,0,0); Dfs2(1,0,0,0,n/2); Dfs2(n/2+1,0,0,1,n); for(LL i=1;i<=tot[0];i++) { zx[++Count].x=q[0][i].x; zx[Count].xb=i; zx[Count].mark=0; } for(LL i=1;i<=tot[1];i++) { zx[++Count].x=-q[1][i].x; zx[Count].xb=i; zx[Count].mark=1; } sort(zx+1,zx+1+Count,cmp1); zx[0].x=-1e18; for(LL i=1;i<=Count;i++) { if(zx[i].x!=zx[i-1].x) t++; q[zx[i].mark][zx[i].xb].x=t; } sort(q[0]+1,q[0]+1+tot[0],cmp2); sort(q[1]+1,q[1]+1+tot[1],cmp3); zz=1; for(LL i=1;i<=tot[0];i++) { while(zz<=tot[1] && q[0][i].y+q[1][zz].y>0) { Update(q[1][zz].x); zz++; } ans1+=Sum(q[0][i].x-1); } printf("%lld",ans1-ans2); return 0; }
to sum up
Today is not that bad of it, at least violence all right, tomorrow to continue filling it!
Left 87 days from NOIp2019 Festival