Codeforces 526 E transmitting levels
Test instructions
Given n number a1,a2,..., An, the n number of the end-to-end formation of a ring.
For example: 1 2 3
(2,3) (3,1) connected
Now give the Q a query, each query for a B, the number of the n is divided into connected m-segment, so that each paragraph and not more than B, to find the minimum value of M.
Limit:
2 <= N <= 1e6
1 <= q <= 50
1 <= ai <= 1e9
Max (AI) <= b <= 1e15
Ideas:
First, find a minimum segment, from the smallest segment of the lifting point, take the minimum value is the answer.
/*codeforces 526 E Test Instructions: gives the number of n a1,a2,..., An, the n number of the end-to-end formation of a ring. such as: 1 2 3 (2,3) (3,1) connected now give Q a query, each query for a B, the number of the n is divided into connected m-segment, so that each paragraph and not more than B, the minimum value of M. Limit: 2 <= n <= 1e6 1 <= q <= 1 <= ai <= 1e9 max (AI) <= b <= 1e15 idea: First find a minimum segment, lift the point from the smallest segment, Taking the minimum value is the answer. * * #include <iostream> #include <cstdio> #include <algorithm>using namespace std; #define LL __ int64const int n=1e6+5; LL A[n]; LL sum[2*n];int nxt[n];int Deal (int st,int N) {int cnt=0;int p=st;while (p<n) {++cnt;p=nxt[p%n];} while (p%n<st) {++cnt;p=nxt[p%n];} return CNT;} void Gao (LL b,int n) {int st=0,len=n;int p=0,q=0;while (p<n) {while (q<=2*n && sum[q]-sum[p]<=b) {++q;} if (q-p-1>n) {puts ("1"); return;} Else{nxt[p]=q-1;int tmp=q-p-1;if (Tmp<len) {len=tmp;st=p;}} ++p;} int ans=n;for (int i=st;i<=st+len;++i) {ans=min (Ans,deal (I%n,n));} printf ("%d\n", ans);} void in (int &x) {char c; x=0; C=getchar (); int sign=1;while (!) ( c>= ' 0 ' &&c<= ' 9 ' | | c== '-')) C=getchar (); if (c== '-') sign=-1,c=geTCHAR (); while (c>= ' 0 ' &&c<= ' 9 ') {x= (x<<3) + (x<<1) +c-' 0 '; C=getchar ();} X*=sign;} void in (LL &x) {char c; x=0; C=getchar (); int sign=1;while (!) ( c>= ' 0 ' &&c<= ' 9 ' | | c== '-')) C=getchar (), if (c== '-') Sign=-1,c=getchar (); while (c>= ' 0 ' &&c<= ' 9 ') {x= (x<<3) + (x< <1) +c-' 0 '; C=getchar ();} X*=sign;} int main () {int n,q;in (n), in (Q), for (int. i=0;i<n;++i) {in (A[i]);} sum[0]=0;for (int i=0;i<2*n;++i) {sum[i+1]=sum[i]+a[i%n];} LL b;for (int i=0;i<q;++i) {in (b); Gao (b,n);} return 0;}
Codeforces 526 E transmitting levels