好消息,坏消息

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=2e6+7;
 6 ll val[maxn],sum[2*maxn],q[maxn];
 7 ll n,minn,ans,head,tail;
 8 int main(){
 9   cin>>n;
10   minn=2147483647;head=1;tail=0;
11   for(ll i=1;i<=n;i++) cin>>val[i];
12   for(ll i=1;i<=n-1;i++) val[i+n]=val[i];
13   for(ll i=1;i<=2*n-1;i++) sum[i]=sum[i-1]+val[i];
14   for(ll i=1;i<=2*n-1;i++){
15     while(head<=tail&&max(i-n+1,(ll)1)>q[head]) head++;
16     while(head<=tail&&sum[i]<=sum[q[tail]]) tail--;
17     q[++tail]=i;
18     if(i-n+1>0&&sum[q[head]]-sum[i-n]>=0) ans++;
19   }
20   cout<<ans<<endl;
21   return 0;
22 }

错误的,不知道

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=1e6+7;
 6 ll val[maxn],sum[2*maxn],q[maxn];
 7 ll n,minn,ans,head,tail;
 8 int main(){
 9   cin>>n;
10   minn=2147483647;head=1;tail=0;
11   for(int i=1;i<=n;i++) cin>>val[i];
12   for(int i=1;i<=n;i++) {sum[i]=sum[i-1]+val[i];if(i!=n) sum[i+1]=sum[i];minn=min(minn,sum[i]);}
13   for(int i=1;i<=n;i++) cout<<sum[i]<<" "; cout<<endl;
14   q[++tail]=1;
15   for(int i=2;i<=n;i++){
16       while(sum[i]<=sum[q[tail]]&&head<tail) tail--;
17       q[++tail]=i;
18   }for(int i=head;i<=tail;i++) cout<<q[i]<<" "; cout<<endl;
19   for(int k=1;k<=n;k++){
20       while(q[head]<=k&&head<tail) head++;
21       if(sum[ k]<=sum[q[head]]) ans++;
22       while(sum[k]<=sum[q[tail]]&&head<= tail) tail--;
23       q[++tail]=k+n;
24       cout<<"q "<<head<<" "<<tail<<endl;
25       for(int i=head;i<=tail;i++) cout<<sum[q[i]]<<" "; cout<<endl;  
26   } 
27   cout<<ans<<endl;
28   return 0;
29 }

 

posted @ 2018-09-03 19:42  lcan  阅读(164)  评论(0编辑  收藏  举报