标签:problems nim ssi std otto 左右 several ems recommend
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7390 Accepted Submission(s): 2498
1 #include "bits/stdc++.h" 2 using namespace std; 3 typedef long long LL; 4 const int MAX=1e5+5; 5 int n,m,k; 6 int a[MAX]; 7 deque <int> q1,q2; 8 inline int read(){ 9 int an=0,x=1;char c=getchar(); 10 while (c<‘0‘ || c>‘9‘) {if (c==‘-‘) x=-1;c=getchar();} 11 while (c>=‘0‘ && c<=‘9‘) {an=an*10+c-‘0‘;c=getchar();} 12 return an*x; 13 } 14 int main(){ 15 freopen ("subsequence.in","r",stdin); 16 freopen ("subsequence.out","w",stdout); 17 int i,j; 18 while (~scanf("%d%d%d",&n,&m,&k)){ 19 int ans=0,last=0; 20 for (i=1;i<=n;i++) a[i]=read(); 21 while (q1.size()) q1.pop_back(); while (q2.size()) q2.pop_back(); 22 for (i=1;i<=n;i++){ 23 while (q1.size() && a[i]>a[q1.back()]) q1.pop_back(); 24 while (q2.size() && a[i]<a[q2.back()]) q2.pop_back(); 25 q1.push_back(i),q2.push_back(i); 26 while (q1.size() && q2.size() && (a[q1.front()]-a[q2.front()])>k){ 27 if (q1.front()<q2.front()){ 28 last=q1.front(),q1.pop_front(); 29 } 30 else if (q1.front()>q2.front()){ 31 last=q2.front(),q2.pop_front(); 32 } 33 else{ 34 last=q1.front(),q1.pop_front(),q2.pop_front(); 35 } 36 } 37 if (q1.size() && q2.size() && (a[q1.front()]-a[q2.front()])>=m){ 38 ans=max(ans,i-last); 39 } 40 } 41 printf("%d\n",ans); 42 } 43 return 0; 44 }
标签:problems nim ssi std otto 左右 several ems recommend
原文地址:http://www.cnblogs.com/keximeiruguo/p/7680281.html