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++ 6s,用stl乱搞的In Reply To:一样的代码C++能过,G++TLE Posted by:biran007 at 2009-08-10 01:09:51 struct small { int id, num; small(int ii, int n) { id = ii; num = n; } bool operator < (const small & other)const { return num < other.num; } }; struct big { int id, num; big(int ii, int n) { id = ii; num = n; } bool operator < (const big & other)const { return num > other.num; } }; int a[1000005]; priority_queue<small> s; priority_queue<big> b; int main() { // small ss; // big bb; int n, k; scanf("%d%d", &n, &k); REP(i, n) { scanf("%d", a + i); } REP(i, k) { s.push(small(i, a[i])); b.push(big(i, a[i])); } FOR(i, k, n - 1) { while (b.top().id < (i - k)) { b.pop(); } printf("%d ", b.top().num); //s.pop(); b.push(big(i, a[i])); } while (b.top().id < (n - k)) { b.pop(); } printf("%d\n", b.top().num); FOR(i, k, n - 1) { while (s.top().id < (i - k)) { s.pop(); } printf("%d ", s.top().num); //s.pop(); s.push(small(i, a[i])); } while (s.top().id < (n - k)) { s.pop(); } printf("%d\n", s.top().num); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator