QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#243581 | #2016. 贪吃蛇 | LYT0122 | 100 ✓ | 62ms | 15968kb | C++14 | 2.8kb | 2023-11-08 14:35:42 | 2023-11-08 14:35:42 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long int ll;
const int N=1e6+9,INF=1e9;
const double eps=1e-5;
typedef pair <int,int> PII;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
return x*f;
}
inline ll readll()
{
ll x=0,f=1;char c=getchar();
while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
return x*f;
}
int n,a[N],ans;
deque <PII> q1,q2;
int main()
{
// #define FILEIO
#ifdef FILEIO
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
int T=read();
for(int t=1;t<=T;t++)
{
if(t==1)
{
n=read();
for(int i=1;i<=n;i++) a[i]=read();
}
else
{
int k=read();
for(int i=1;i<=k;i++)
{
int x=read(),y=read();
a[x]=y;
}
}
q1.clear(),q2.clear();
for(int i=1;i<=n;i++) q1.push_back({a[i],i});
while(true)
{
if(q1.size()+q2.size()==2)
{
ans=1;
break;
}
int x=q1.front().first,y,id;
q1.pop_front();
if(q2.empty() || (q1.empty()==false && q1.back()>q2.back()))
y=q1.back().first,id=q1.back().second,q1.pop_back();
else y=q2.back().first,id=q2.back().second,q2.pop_back();
PII p={y-x,id};
if(q1.empty() || q1.front()>p)
{
ans=q1.size()+q2.size()+2;
int sum=0;
while(true)
{
sum++;
if(q1.size()+q2.size()==1)
{
if(sum%2==0) ans--;
break;
}
if(q2.empty() || (q1.empty()==false && q1.back()>q2.back()))
y=q1.back().first,id=q1.back().second,q1.pop_back();
else y=q2.back().first,id=q2.back().second,q2.pop_back();
p={y-p.first,id};
if((q1.empty() || p<q1.front()) && (q2.empty() || p<q2.front()));
else
{
if(sum%2==0) ans--;
break;
}
}
break;
}
else q2.push_front(p);
}
cout<<ans<<'\n';
}
cerr<<endl<<1e3*clock()/CLOCKS_PER_SEC<<"ms";
return 0;
}
詳細信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 3864kb
input:
10 3 29 46 67 3 1 15 2 34 3 114 3 1 120 2 168 3 224 3 1 65 2 132 3 293 3 1 79 2 192 3 474 3 1 24 2 64 3 562 3 1 396 2 458 3 595 3 1 44 2 317 3 592 3 1 138 2 145 3 572 3 1 602 2 726 3 831
output:
3 1 3 1 1 1 3 1 1 3
result:
ok 10 lines
Test #2:
score: 5
Accepted
time: 0ms
memory: 3932kb
input:
10 3 21 73 85 3 1 53 2 69 3 126 3 1 90 2 244 3 259 3 1 67 2 288 3 320 3 1 247 2 351 3 445 3 1 150 2 483 3 568 3 1 534 2 583 3 590 3 1 114 2 226 3 745 3 1 199 2 436 3 513 3 1 147 2 324 3 555
output:
3 1 3 3 3 3 3 1 3 1
result:
ok 10 lines
Test #3:
score: 5
Accepted
time: 0ms
memory: 3932kb
input:
10 3 31 64 74 3 1 68 2 83 3 98 3 1 1 2 81 3 102 3 1 98 2 140 3 247 3 1 20 2 76 3 276 3 1 276 2 384 3 592 3 1 25 2 275 3 361 3 1 597 2 632 3 764 3 1 72 2 151 3 455 3 1 224 2 546 3 834
output:
3 3 1 1 1 3 1 3 1 1
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 0ms
memory: 3884kb
input:
10 3 24 62 82 3 1 19 2 28 3 145 3 1 98 2 198 3 278 3 1 25 2 67 3 278 3 1 20 2 254 3 262 3 1 110 2 175 3 585 3 1 87 2 369 3 584 3 1 222 2 524 3 604 3 1 11 2 27 3 420 3 1 241 2 495 3 838
output:
3 1 3 1 3 1 1 3 1 1
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 0ms
memory: 4056kb
input:
10 10 3 9 37 42 43 55 55 67 69 95 10 1 10 2 15 3 75 4 121 5 129 6 140 7 157 8 158 9 165 10 172 10 1 2 2 34 3 44 4 48 5 129 6 166 7 169 8 170 9 253 10 295 10 1 29 2 65 3 147 4 177 5 208 6 267 7 295 8 306 9 360 10 386 10 1 64 2 131 3 133 4 151 5 186 6 245 7 259 8 324 9 347 10 422 10 1 32 2 52 3 101 4 ...
output:
7 7 5 7 7 5 7 7 5 7
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 0ms
memory: 3988kb
input:
10 10 1 11 17 21 40 51 54 75 83 91 10 1 27 2 44 3 46 4 52 5 72 6 81 7 125 8 130 9 167 10 175 10 1 14 2 56 3 66 4 68 5 95 6 133 7 164 8 269 9 271 10 274 10 1 60 2 64 3 78 4 111 5 123 6 176 7 210 8 311 9 353 10 354 10 1 25 2 89 3 149 4 172 5 281 6 283 7 338 8 437 9 463 10 470 10 1 129 2 168 3 201 4 34...
output:
5 5 5 5 7 7 5 7 7 5
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 0ms
memory: 3864kb
input:
10 10 4 13 20 58 62 67 74 77 93 93 10 1 10 2 34 3 58 4 67 5 81 6 87 7 98 8 143 9 152 10 193 10 1 35 2 80 3 100 4 106 5 171 6 173 7 184 8 240 9 278 10 297 10 1 17 2 46 3 48 4 317 5 328 6 364 7 378 8 383 9 384 10 399 10 1 22 2 34 3 58 4 96 5 99 6 100 7 156 8 190 9 414 10 443 10 1 57 2 63 3 78 4 170 5 ...
output:
7 5 7 7 3 7 7 7 7 7
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 0ms
memory: 3888kb
input:
10 10 4 18 36 41 50 58 59 78 84 92 10 1 42 2 43 3 54 4 54 5 67 6 152 7 153 8 161 9 182 10 190 10 1 9 2 49 3 58 4 64 5 82 6 185 7 258 8 272 9 277 10 286 10 1 10 2 141 3 151 4 169 5 198 6 240 7 282 8 284 9 353 10 387 10 1 3 2 73 3 158 4 196 5 245 6 265 7 311 8 324 9 378 10 448 10 1 26 2 45 3 156 4 157...
output:
7 5 5 7 7 5 5 7 3 5
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 1ms
memory: 4088kb
input:
10 2000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 ...
output:
1226 1222 1227 1231 1245 1189 1237 1219 1224 1255
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 1ms
memory: 3888kb
input:
10 2000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 ...
output:
1231 1239 1228 1233 1213 1233 1242 1255 1223 1261
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 1ms
memory: 3952kb
input:
10 2000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 ...
output:
1236 1236 1201 1213 1232 1235 1214 1243 1257 1229
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 12ms
memory: 4484kb
input:
10 50000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30512 30779 30949 30796 30946 30847 30807 30937 30867 30808
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 13ms
memory: 4488kb
input:
10 50000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30619 30660 30793 30727 30877 30771 30846 30589 30800 30975
result:
ok 10 lines
Test #14:
score: 5
Accepted
time: 12ms
memory: 4524kb
input:
10 50000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30435 30814 30682 30922 30855 30868 30851 31023 30968 30951
result:
ok 10 lines
Test #15:
score: 5
Accepted
time: 55ms
memory: 15580kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
609762 609762 609762 613003 613003 613003 613003 613003 613003 609165
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 60ms
memory: 15444kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
609891 609892 609892 609892 609892 609892 609892 618092 618092 618092
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 55ms
memory: 15968kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
609983 609983 609983 609984 609984 609984 609984 609070 609070 609071
result:
ok 10 lines
Test #18:
score: 5
Accepted
time: 59ms
memory: 15676kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
610259 610259 610259 613586 613586 613586 613586 616676 616676 616677
result:
ok 10 lines
Test #19:
score: 5
Accepted
time: 62ms
memory: 15508kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
610386 610386 610386 613680 613680 613680 613680 618492 618492 618493
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 60ms
memory: 15764kb
input:
10 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
610138 610138 610138 613036 613036 613036 613036 613036 613036 609198
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed