QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#562488 | #5163. 喵了个喵 | oceans_of_stars | 0 | 0ms | 0kb | C++14 | 3.7kb | 2024-09-13 17:54:53 | 2024-09-13 17:54:58 |
answer
#include<bits/stdc++.h>
const int maxn=2e6+10;
using namespace std;
int T,n,m,k,a[maxn],cnt,pos[301],st,num[601];
deque<int>q[301];
struct lsx
{
int id,x,y;
}ans[maxn<<1];
bool s1[601];
int get_pos(int x)
{
return x?pos[x]:pos[n-1];
}
int main()
{
freopen("meow.in","r",stdin);
freopen("meow.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--)
{
cnt=0;
cin>>n>>m>>k;
for(int i=1;i<=n-1;i++) pos[i]=i;st=n;
memset(s1,0,sizeof s1);
for(int i=1;i<=m;i++) cin>>a[i];
if(k==2*n-2)
{
for(int i=1;i<=m;i++)
{
int d=get_pos(a[i]%(n-1));
if(q[d].size())
{
if(q[d].front()==a[i])
{
ans[++cnt]={1,d,0};
q[d].pop_front();
}
else if(q[d].back()==a[i])
{
ans[++cnt]={1,n,0};
ans[++cnt]={2,d,n};
q[d].pop_back();
}
else
{
ans[++cnt]={1,d,0};
q[d].push_front(a[i]);
}
}
else
{
ans[++cnt]={1,d,0};
q[d].push_front(a[i]);
}
}
}
else
{
for(int i=1;i<=m;i++)
{
int d=get_pos(a[i]%(n-1));
if(q[d].size())
{
if(q[d].front()==a[i])
{
ans[++cnt]={1,d,0};
q[d].pop_front();
if(!q[d].size())s1[a[i]]=0;
}
else if(q[d].back()==a[i])
{
ans[++cnt]={1,st,0};
ans[++cnt]={2,d,st};
q[d].pop_back();
s1[a[i]]=0;
}
else
{
int ss=cnt,sss=0;cnt++;
bool flag=0;
fill(num+1,num+601,0);
for(int j=i+1;j<=m;j++)
{
if(s1[a[j]])
{
if(!sss)
{
int d=get_pos(a[j]%(n-1));
int dd=a[j]%(n-1);
if(!dd)dd=n-1;
if(q[d].size()>1&&num[q[d].front()]%2==0)
{
ans[++ss]={1,st,0};
flag=1;
ans[++cnt]={2,d,st};
q[d].pop_back();
s1[a[j]]=0;
s1[q[d].back()]=1;
i=j+1;
break;
}
else
{
ans[++ss]={1,st,0};
flag=1;
ans[++cnt]={1,d,0};
q[st].push_front(a[i]);
swap(st,pos[dd]);
s1[q[d].front()]=0;
q[d].pop_front();
s1[a[j]]=1;
i=j+1;
break;
}
}
else
{
int d=get_pos(a[j]%(n-1));
sss=get_pos(sss);
ans[++ss]={1,sss,0};
flag=1;
ans[++cnt]={1,st,0};
ans[++cnt]={2,d,st};
q[d].pop_back();
if(q[d].size())s1[q[d].back()]=1;
s1[a[j]]=0;
i=j+1;
break;
}
}
else if(a[j]==a[i])
{
ans[++ss]={1,st,0};
flag=1;
ans[++cnt]={1,st,0};
break;
}
else
{
int d=get_pos(a[j]%(n-1));
num[a[i]]++;
if(num[a[i]]%2==0)sss=a[i];
ans[++cnt]={1,d,0};
if(q[d].size()&&q[d].front()==a[j])q[d].pop_front();
else q[d].push_front(a[j]);
}
}
}
}
else
{
ans[++cnt]={1,d,0};
q[d].push_front(a[i]);
s1[a[i]]=1;
}
}
}
for(int i=1;i<n;i++)
{
if(!q[i].size())continue;
for(int j=i+1;j<=n;j++)
{
if(!q[j].size())continue;
if(q[i].back()==q[j].back())
{
ans[++cnt]={2,i,j};
q[i].pop_back();
q[j].pop_back();
}
}
}
int sum=0;
for(int i=1;i<=cnt;i++) if(ans[i].id==0)sum++;
cout<<cnt-sum<<'\n';
for(int i=1;i<=cnt;i++)
{
if(ans[i].id==0)continue;
cout<<ans[i].id<<" ";
if(ans[i].id==1) cout<<ans[i].x<<'\n';
else cout<<ans[i].x<<" "<<ans[i].y<<'\n';
}
}
return 0;
}
/*
1
3 10 5
1 2 3 4 5 2 3 4 5 1
*/
详细
Pretests
Final Tests
Test #1:
score: 0
Dangerous Syscalls
input:
1001 300 1814 598 483 60 555 101 51 354 9 252 396 527 380 573 243 98 143 305 16 355 479 117 594 369 522 368 133 534 598 353 475 161 68 250 4 119 137 12 370 532 72 152 40 314 249 182 397 71 164 513 198 539 283 121 440 548 56 439 434 64 336 132 514 339 52 350 21 421 304 156 268 87 338 419 540 583 139 ...
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
1001 300 99724 598 345 381 76 48 555 574 99 55 233 363 511 21 268 552 390 442 284 356 291 572 132 251 185 123 247 436 410 254 74 507 567 418 421 44 597 510 151 229 98 516 591 10 70 392 562 592 236 379 349 60 485 480 71 136 222 40 546 476 113 586 444 64 540 195 583 304 423 214 221 548 224 422 341 319...
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
1001 300 1870 598 232 396 237 207 403 576 164 510 388 568 180 574 321 589 140 209 129 420 555 124 575 552 415 486 143 85 275 421 267 408 55 64 46 393 598 155 556 542 60 91 52 455 543 42 153 303 548 241 426 59 194 243 78 469 459 352 291 128 161 477 323 339 272 493 361 366 569 456 22 409 532 195 537 8...
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
1002 2 100000 3 2 3 1 2 1 1 2 2 1 2 1 3 2 3 1 2 1 1 2 1 2 1 3 3 1 2 1 2 2 3 2 1 3 3 2 1 2 1 3 2 1 3 2 3 1 1 3 1 2 1 3 1 2 2 2 2 1 1 2 1 2 1 1 1 2 3 1 2 2 1 3 2 3 3 2 3 3 2 2 1 3 2 1 2 3 2 3 1 3 2 1 2 3 3 2 1 2 3 2 3 1 2 2 3 1 2 1 2 3 1 2 3 3 1 2 1 2 2 1 1 2 1 3 3 2 2 2 2 1 3 3 1 2 1 1 1 1 2 2 3 3 1 ...
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
1002 2 1994 3 3 1 2 1 1 3 2 1 3 2 1 1 3 1 2 3 3 2 1 3 3 2 3 2 1 3 1 1 3 1 3 1 3 3 1 3 1 2 2 3 2 3 3 2 2 1 1 2 3 2 3 1 3 2 1 3 2 1 1 2 3 1 2 1 2 3 1 1 3 2 1 2 2 3 2 3 1 1 2 2 1 1 2 3 2 3 1 2 1 3 1 2 3 2 2 2 1 3 1 3 2 1 3 1 3 3 3 3 3 2 1 3 3 2 1 2 1 2 1 1 2 3 1 3 2 2 1 3 2 1 3 1 2 3 2 1 3 1 3 3 1 2 3 ...
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
1002 2 99998 3 2 3 1 3 3 1 3 1 3 1 3 3 1 1 2 2 1 1 2 1 1 1 3 3 3 3 2 1 3 1 3 1 1 3 3 1 1 2 2 1 1 2 2 1 3 3 1 1 1 2 2 3 3 1 2 1 1 1 3 2 1 1 3 3 3 1 3 3 2 1 3 1 2 3 3 3 3 1 1 2 3 2 2 2 1 3 3 2 2 2 2 2 2 2 3 2 2 2 3 3 2 3 2 3 3 2 1 1 2 2 3 2 3 1 2 2 1 2 3 1 2 1 2 2 3 3 1 1 2 3 3 3 3 1 3 2 3 1 2 1 1 2 2...
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
3 3 14 5 1 2 3 4 5 1 5 5 4 3 5 4 2 4 3 14 5 1 2 3 4 5 2 5 3 5 1 1 4 5 1 3 14 5 1 2 3 4 5 1 4 1 4 1 5 4 2 3
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
3 3 14 5 1 2 3 4 5 4 1 1 3 2 4 1 4 5 3 14 5 1 2 3 4 5 4 3 5 3 5 1 2 3 5 3 14 5 1 2 3 4 5 5 3 2 5 5 1 2 2 4
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
3 3 14 5 1 2 3 4 5 3 4 1 2 4 1 1 4 5 3 14 5 1 2 3 4 5 3 2 2 3 5 4 2 3 1 3 14 5 1 2 3 4 5 4 3 2 5 1 1 1 5 5
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
3 3 14 5 1 2 3 4 5 5 2 3 1 5 3 3 5 4 3 14 5 1 2 3 4 5 4 5 2 5 5 5 5 1 3 3 14 5 1 2 3 4 5 5 5 4 5 4 4 2 3 1
output:
result:
Test #11:
score: 0
Dangerous Syscalls
input:
1004 3 1992 5 4 5 2 3 1 5 5 1 4 3 5 1 4 5 3 5 3 1 4 4 5 3 1 2 2 1 3 2 5 2 5 3 1 4 5 5 3 5 4 2 1 3 2 5 1 1 4 5 5 4 1 4 2 2 4 4 2 3 3 2 4 2 1 5 1 3 4 3 2 4 5 2 3 3 5 1 3 5 2 3 1 4 1 4 4 5 2 2 4 1 5 2 2 4 1 3 1 3 4 4 4 2 5 3 5 4 1 2 1 4 3 3 3 3 3 3 3 2 4 2 4 1 1 5 2 1 2 2 1 5 4 3 1 4 1 3 2 3 1 4 1 2 1 ...
output:
result:
Test #12:
score: 0
Dangerous Syscalls
input:
1004 3 100000 5 3 5 2 4 1 5 3 2 1 5 3 2 1 5 3 2 4 5 3 2 4 5 3 1 2 5 3 1 2 5 3 1 2 5 3 1 2 5 3 4 2 5 3 4 2 5 1 3 4 5 1 3 4 2 1 3 4 2 1 5 3 4 1 5 2 3 1 5 2 3 1 5 2 3 1 4 5 3 2 4 5 1 2 4 5 1 2 4 5 3 1 4 5 3 2 1 4 5 2 1 4 3 2 1 4 3 2 1 5 3 4 1 5 3 4 2 5 1 3 2 5 1 3 4 2 5 1 4 2 5 1 4 3 2 5 4 3 2 5 4 1 3 ...
output:
result:
Test #13:
score: 0
Dangerous Syscalls
input:
1004 3 1990 5 1 2 4 5 3 3 1 5 4 4 5 3 1 5 2 5 4 4 2 1 2 1 1 3 4 4 2 3 1 3 1 4 5 3 5 4 1 2 2 2 5 3 5 5 4 3 5 4 2 2 5 5 5 1 4 5 2 4 1 3 1 2 4 1 2 3 4 1 3 3 4 2 2 4 1 4 5 2 2 4 5 4 2 2 5 4 4 4 5 1 2 1 4 2 2 4 4 2 5 5 4 3 4 4 5 3 1 3 2 3 5 2 1 1 1 4 5 3 5 3 4 1 4 1 4 2 4 4 4 5 1 5 1 2 4 4 4 3 3 1 3 1 2 ...
output:
result:
Test #14:
score: 0
Dangerous Syscalls
input:
1004 3 99998 5 2 1 3 4 5 2 1 3 4 2 1 3 4 2 1 5 3 2 1 5 3 4 2 5 1 4 2 5 1 3 4 5 1 3 4 5 1 3 4 5 2 3 4 5 1 2 4 5 1 2 3 4 5 2 3 4 1 5 2 4 1 5 2 4 1 3 2 4 1 3 2 5 4 1 3 5 4 1 3 2 4 1 3 2 4 1 3 2 4 5 1 3 4 5 2 1 3 4 5 1 2 4 5 1 2 3 5 1 4 3 5 1 4 2 3 1 4 2 3 1 4 2 5 1 3 2 5 1 3 4 2 1 3 4 2 1 3 5 4 1 3 5 2...
output:
result:
Test #15:
score: 0
Dangerous Syscalls
input:
1005 300 1908 599 161 199 80 536 40 121 528 569 337 568 8 547 86 424 333 220 439 500 210 515 593 5 75 466 537 352 372 513 451 87 554 209 261 482 415 597 450 422 182 535 484 580 506 563 200 582 101 409 135 95 51 198 587 561 514 359 112 429 435 383 418 96 266 233 331 116 293 150 289 414 130 432 377 56...
output:
result:
Test #16:
score: 0
Dangerous Syscalls
input:
1005 300 99936 599 512 185 499 176 447 476 341 332 298 68 191 231 198 536 252 220 259 113 265 438 579 284 418 212 179 467 498 105 361 170 205 273 354 104 87 201 217 427 171 152 494 382 329 535 34 186 194 146 88 32 362 372 449 573 550 553 109 292 315 278 496 225 270 237 311 470 453 375 242 269 40 24 ...
output:
result:
Test #17:
score: 0
Dangerous Syscalls
input:
1005 300 1886 599 451 344 162 305 593 146 549 590 299 495 258 419 77 45 171 220 48 246 124 560 317 321 131 588 500 395 207 460 34 240 123 583 194 427 215 339 377 205 275 509 101 95 585 145 502 442 193 148 566 390 464 524 520 90 62 315 296 521 535 553 108 157 147 371 213 398 458 313 492 81 394 523 28...
output:
result:
Test #18:
score: 0
Dangerous Syscalls
input:
1005 300 99736 599 497 195 73 245 116 464 389 581 366 205 272 386 586 471 22 590 112 345 138 236 219 243 524 392 302 306 62 157 465 399 380 1 593 452 346 317 35 327 83 476 237 106 462 127 91 456 110 228 329 328 470 491 121 409 434 419 565 300 455 86 435 182 431 453 396 109 330 270 214 429 15 578 519...
output:
result:
Test #19:
score: 0
Dangerous Syscalls
input:
1005 300 1966 599 291 319 439 495 23 192 348 560 588 454 219 46 564 99 322 503 272 246 350 41 284 337 335 168 573 491 50 94 59 96 413 497 590 435 327 576 33 552 68 252 597 587 557 488 128 229 135 477 506 56 451 241 224 62 370 273 466 463 332 562 513 190 585 430 403 19 382 471 507 18 141 494 574 29 2...
output:
result:
Test #20:
score: 0
Dangerous Syscalls
input:
1005 300 1997946 599 492 539 331 519 105 510 521 334 251 416 147 16 528 224 469 253 309 53 57 567 60 502 151 533 522 283 599 355 197 484 531 527 41 274 76 561 166 47 449 219 194 465 417 571 38 126 25 94 84 596 119 18 156 402 254 148 394 88 270 326 252 310 237 327 509 374 358 259 205 460 405 22 432 4...