Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
G++TLE C++AC这是为什么 有人帮忙解答下吗#include<stdio.h> #include<string.h> const int maxn = 1000005; int a[maxn],q[maxn]; int n,k; void Monotonequeue(int op) { memset(q,0,sizeof(q)); bool first = true; int head = 1,tail = 0; for (int i = 1; i <= n; i++) { while (head <= tail && ((!op && a[i] <= a[q[tail]]) || (op && a[i] >= a[q[tail]]))) tail--; q[++tail] = i; while (head <= tail && q[tail] - q[head] >= k) head++; if (i >= k) first?printf("%d",a[q[head]]):printf(" %d",a[q[head]]),first = false; } printf("\n"); } int main() { scanf("%d%d",&n,&k); for (int i = 1; i <= n; i++) { scanf("%d",&a[i]); } Monotonequeue(0); Monotonequeue(1); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator