ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201187 | #3483. deque | Allen123456hello | 100 | 124ms | 1852kb | C++11 | 1.9kb | 2024-01-21 10:07:18 | 2024-01-21 12:05:52 |
answer
#include <bits/stdc++.h>
using namespace std;
char a[100005];
#define N 200005
template < typename T,typename C=vector<T> >
class round_deque{
public:
round_deque(){con.resize(N);cap=N;}
void push_back(T a){
++__size;
++tail;
if (__size>cap){throw(runtime_error("full"));}
while (head>=cap&&tail>=cap){
head-=cap;tail-=cap;
}
con[tail%cap]=a;
}
void push_front(T a){
++__size;
--head;
if (__size>cap){throw(runtime_error("full"));}
while (tail<0||head<0){
tail+=cap;head+=cap;
}
con[head%cap]=a;
}
void pop_back(){
if (!__size){throw(runtime_error("deque is null"));}
--__size;
--tail;
while (tail<0||head<0){
tail+=cap;head+=cap;
}
}
void pop_front(){
if (!__size){throw(runtime_error("deque is null"));}
--__size;
++head;
while(head>=cap&&tail>=cap){
head-=cap;tail-=cap;
}
}
T& operator[](long long vis){
if (vis>=__size){throw(runtime_error("out of range"));}
return con[(head+vis)%cap];
}
bool empty(){
return !__size;
}
long long size(){
return __size;
}
private:
C con;
long long __size=0,cap=1,head=1,tail=0;
};
round_deque<int> apple;
int main(){
int n;
scanf("%d",&n);
int tmp,T=n;
scanf("%d",&tmp);
apple.push_back(tmp);
while (--T){
scanf("%d",&tmp);
if (tmp>apple[0]){apple.push_back(tmp);}
else{apple.push_front(tmp);}
}
for (int i=0;i<n;i++){if (i){putchar(' ');}printf("%d",apple[i]);}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1852kb
input:
12 5 6 15 9 7 11 13 17 3 4 8 1 16 14 18 2 10
output:
1 3 5 6 15 9 7 11 13 17 4 8
result:
ok single line: '1 3 5 6 15 9 7 11 13 17 4 8'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1852kb
input:
13 4 2 5 18 12 17 9 15 8 11 10 14 7 3 19 16 1 6
output:
2 4 5 18 12 17 9 15 8 11 10 14 7
result:
ok single line: '2 4 5 18 12 17 9 15 8 11 10 14 7'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1852kb
input:
9 13 20 7 12 6 3 5 11 1 16 18 4 17 8 15 2 10 19 14
output:
1 3 6 7 13 20 12 5 11
result:
ok single line: '1 3 6 7 13 20 12 5 11'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1852kb
input:
296 1001 1481 242 1288 558 1768 1030 411 1654 1174 560 1586 774 80 1917 1944 1979 1325 641 1834 1364...
output:
8 11 30 62 80 242 1001 1481 1288 558 1768 1030 411 1654 1174 560 1586 774 1917 1944 1979 1325 641 18...
result:
ok single line: '8 11 30 62 80 242 1001 1481 12...1106 1644 312 809 1575 646 1052'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1848kb
input:
1856 1501 1453 363 450 1915 854 1597 1348 1916 1412 669 574 90 1974 1021 390 1284 1820 1388 1715 110...
output:
1 3 4 6 9 14 52 90 363 1453 1501 450 1915 854 1597 1348 1916 1412 669 574 1974 1021 390 1284 1820 13...
result:
ok single line: '1 3 4 6 9 14 52 90 363 1453 15...1 923 250 1945 1646 380 602 365'
Test #6:
score: 10
Accepted
time: 2ms
memory: 1852kb
input:
965 1911 248 1658 1241 991 1792 596 1123 1829 1709 1328 1358 445 1637 934 1400 1346 1571 995 1599 85...
output:
4 5 17 81 131 248 1911 1658 1241 991 1792 596 1123 1829 1709 1328 1358 445 1637 934 1400 1346 1571 9...
result:
ok single line: '4 5 17 81 131 248 1911 1658 12...998 1621 400 1887 20 46 328 110'
Test #7:
score: 10
Accepted
time: 0ms
memory: 1852kb
input:
253 1920 266 609 217 1653 64 1477 664 1915 1010 368 905 1337 1516 675 842 729 1141 202 555 1487 1468...
output:
8 52 64 217 266 1920 609 1653 1477 664 1915 1010 368 905 1337 1516 675 842 729 1141 202 555 1487 146...
result:
ok single line: '8 52 64 217 266 1920 609 1653 ... 993 197 716 273 1369 1569 1055'
Test #8:
score: 10
Accepted
time: 0ms
memory: 1852kb
input:
565 995 1768 950 1008 1825 1042 590 1482 1877 1253 805 750 369 629 1068 1916 230 1609 171 771 1537 1...
output:
6 15 18 19 125 171 230 369 590 950 995 1768 1008 1825 1042 1482 1877 1253 805 750 629 1068 1916 1609...
result:
ok single line: '6 15 18 19 125 171 230 369 590...8 233 1581 75 786 640 1094 1431'
Test #9:
score: 10
Accepted
time: 52ms
memory: 1848kb
input:
144742 177209 172172 84814 193683 199225 153842 187959 198438 153656 173678 198099 150049 153033 187...
output:
1 3 6 7 9 22 53 78 111 513 708 1479 62171 84814 172172 177209 193683 199225 153842 187959 198438 153...
result:
ok single line: '1 3 6 7 9 22 53 78 111 513 708...6007 100052 138169 99526 125689'
Test #10:
score: 10
Accepted
time: 70ms
memory: 1848kb
input:
184358 197379 186373 185190 178020 191800 193913 142834 196312 193864 184884 134703 187031 151062 12...
output:
1 6 7 19 53 56 81 311 585 14869 18003 19260 63790 74142 79363 125499 134703 142834 178020 185190 186...
result:
ok single line: '1 6 7 19 53 56 81 311 585 1486...706 122936 128655 118259 179510'