QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#407009 | #5100. 卡牌游戏 | Iratis | 20 | 1939ms | 466096kb | C++14 | 3.0kb | 2024-05-07 21:09:28 | 2024-05-07 21:09:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
bool ST;
const int N=500005,T=100;
int n,S,Type,Tid,B,a[N],Ans[N];
int P[N],Q[N],g[N][T],pos[T],gcd[710][710];vector<int>inc;int *f;
inline int lcm(int x,int y){if(x>y)swap(x,y);if(x<=B)return x*y/gcd[x][y%x];return x*y/__gcd(x,y);}
inline int w(int x,int y){int d=lcm(x,y);return (S/d)*d;}
inline void New(int j,int i,int v){f[i]=max(f[i],f[j]+v);}
inline void Calc(int *dp)
{
f=dp;inc.clear();for(int i=n;i>=1;i--)if(a[i]<=B)inc.push_back(i);int mx=1;
for(int i=1;i<=S;i++)for(int j=0;j<T;j++)g[i][j]=0;for(int j=0;j<T;j++)pos[j]=0;
for(int i=1;i<=n;i++)
{
f[i]=max(f[i],f[i-1]);while(mx<i-1&&f[mx]+S<=f[i])mx++;
if(i-mx<=20){for(int j=mx;j<i;j++)New(j,i,w(a[j],a[i]));}
else
{
for(int t=0;t<T;t++)if(pos[t])New(pos[t],i,w(a[pos[t]],a[i]));
if(a[i]>B){for(int j=a[i];j<=S;j+=a[i])for(int t=0;t<T;t++)if(g[j][t])New(g[j][t],i,j);}
}
if(a[i]<=B){for(int t=0;t<T-1;t++)pos[t]=pos[t+1];pos[T-1]=i;}
else
{
for(int j=a[i];j<=S;j+=a[i]){for(int t=0;t<T-1;t++)g[j][t]=g[j][t+1];g[j][T-1]=i;}
while(!inc.empty()&&inc.back()<=i)inc.pop_back();int s=inc.size();
for(int t=1;t<=T;t++)if(s>=t)New(i,inc[s-t],w(a[i],a[inc[s-t]]));
}
}
}
vector<int>dat[N];
inline void Ins(int l,int r,int w){w+=P[l]+Q[r];l++,r--;if(l>r||!w)return ;dat[l].push_back(w),dat[r+1].push_back(-w);}
inline void Cat_Tree()
{
// for(int i=1;i<=n;i++)cout<<P[i]<<' ';cout<<'\n';
// for(int i=1;i<=n;i++)cout<<Q[i]<<' ';cout<<'\n';
for(int i=1;i<=n;i++)Ans[i]=P[i-1]+Q[i+1];
inc.clear();for(int i=n;i>=1;i--)if(a[i]<=B)inc.push_back(i);
for(int i=1;i<=S;i++)for(int j=0;j<T;j++)g[i][j]=0;for(int j=0;j<T;j++)pos[j]=0;
for(int i=1;i<=n;i++)
{
// for(int j=1;j<i;j++)Ins(j,i,w(a[j],a[i]));
for(int t=0;t<T;t++)if(pos[t])Ins(pos[t],i,w(a[pos[t]],a[i]));
if(a[i]>B){for(int j=a[i];j<=S;j+=a[i])for(int t=0;t<T;t++)if(g[j][t])Ins(g[j][t],i,j);}
if(a[i]<=B){for(int t=0;t<T-1;t++)pos[t]=pos[t+1];pos[T-1]=i;}
else
{
for(int j=a[i];j<=S;j+=a[i]){for(int t=0;t<T-1;t++)g[j][t]=g[j][t+1];g[j][T-1]=i;}
while(!inc.empty()&&inc.back()<=i)inc.pop_back();int s=inc.size();
for(int t=1;t<=T;t++)if(s>=t)Ins(i,inc[s-t],w(a[i],a[inc[s-t]]));
}
}
multiset<int>s;
for(int i=1;i<=n;i++){for(int x:dat[i])if(x>0)s.insert(x);else s.erase(s.find(-x));if(!s.empty())Ans[i]=max(Ans[i],*s.rbegin());}
}
bool ED;
signed main()
{
// int time_st=clock();
cerr<<(&ST-&ED)/1024.0/1024<<endl;ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// file(card);
cin>>n>>S>>Type>>Tid;B=sqrt(S);for(int i=1;i<=n;i++)cin>>a[i];
for(int i=0;i<=B;i++)for(int j=0;j<=B;j++)if(i||j)gcd[i][j]=__gcd(i,j);
Calc(P);if(Type==0)return cout<<P[n],0;reverse(a+1,a+n+1),Calc(Q),reverse(a+1,a+n+1),reverse(Q+1,Q+n+1);
Cat_Tree();int sum=0;for(int i=1;i<=n;i++)sum^=(i*Ans[i]);cout<<P[n]<<' '<<sum<<'\n';
// cerr<<(clock()-time_st)/1e6<<endl;return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 5
Accepted
time: 35ms
memory: 104808kb
input:
1000 100000 1 1 69 99 297 63 277 271 109 268 209 181 100 195 282 137 211 270 87 10 247 294 138 108 33 258 152 265 304 154 201 66 269 189 5 162 134 276 144 187 107 170 16 135 253 67 156 138 299 165 70 258 158 239 186 168 277 261 86 173 153 14 35 226 158 258 129 152 295 235 271 31 192 92 153 236 142 1...
output:
91045064 83613761529
result:
ok 2 number(s): "91045064 83613761529"
Test #2:
score: 0
Time Limit Exceeded
input:
1000 100000 1 1 321 320 321 317 321 318 317 320 321 319 321 319 319 320 318 321 318 318 321 317 320 321 317 320 321 317 319 320 321 318 321 319 320 318 321 321 317 319 317 317 320 317 320 320 318 317 317 318 317 317 317 320 320 321 319 317 319 317 321 318 318 318 319 321 318 318 320 318 319 318 317 ...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #8:
score: 5
Accepted
time: 199ms
memory: 123204kb
input:
10000 100000 1 2 91 50 303 100 42 100 36 306 191 90 99 45 196 144 64 35 98 147 180 115 16 209 62 315 270 295 26 60 139 135 98 39 148 7 239 133 268 218 179 225 253 289 289 279 31 244 288 68 128 275 147 2 222 146 303 215 51 212 84 4 64 183 153 58 230 13 34 58 45 237 301 303 241 92 140 306 60 83 273 23...
output:
913775751 7945799038884
result:
ok 2 number(s): "913775751 7945799038884"
Test #9:
score: 0
Time Limit Exceeded
input:
10000 100000 1 2 318 318 319 317 321 319 317 317 321 317 321 317 318 317 318 321 317 319 320 318 319 321 319 318 321 321 320 317 319 318 318 321 320 319 321 321 319 317 319 318 318 321 318 320 319 318 319 317 319 317 321 318 318 320 320 321 319 321 320 320 319 319 319 320 318 319 320 319 321 320 318...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #15:
score: 0
Time Limit Exceeded
input:
100000 300000 1 3 274679 257449 79355 22007 205440 219549 7516 102115 226913 157081 9451 228050 8862 198356 270934 221218 162391 221194 235433 234134 70219 45552 211652 248648 164511 74601 168682 139466 189586 258255 264158 218369 21734 195969 71728 299881 104633 21390 36649 25670 121247 41503 20806...
output:
result:
Subtask #4:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 1939ms
memory: 466096kb
input:
100000 300000 1 4 22 98 92 49 86 56 11 69 100 65 99 79 39 97 40 88 47 28 79 43 75 13 43 41 69 56 62 47 21 28 69 95 1 92 92 60 78 15 3 20 96 15 95 82 38 9 80 26 64 21 19 48 17 27 79 7 25 66 100 70 94 16 21 61 13 57 42 60 66 18 99 97 69 63 89 20 73 22 64 41 19 9 9 45 64 97 4 71 41 93 65 49 81 23 4 52 ...
output:
29908227273 3183540118634089
result:
ok 2 number(s): "29908227273 3183540118634089"
Test #17:
score: 10
Accepted
time: 1092ms
memory: 463252kb
input:
100000 300000 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
29999700000 3893585367590912
result:
ok 2 number(s): "29999700000 3893585367590912"
Test #18:
score: 10
Accepted
time: 1078ms
memory: 462864kb
input:
100000 300000 1 4 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 10...
output:
29999700000 3893585367590912
result:
ok 2 number(s): "29999700000 3893585367590912"
Subtask #5:
score: 10
Accepted
Test #19:
score: 10
Accepted
time: 17ms
memory: 100604kb
input:
100000 100000 0 5 160 79 241 305 285 252 135 178 99 105 215 136 248 256 255 309 149 226 295 99 253 269 40 126 95 232 201 201 275 306 119 314 91 222 89 135 62 240 100 178 274 99 107 278 238 193 222 311 218 242 46 74 180 253 141 100 33 54 267 90 274 199 64 279 132 183 135 266 258 208 169 89 194 114 11...
output:
9112169164
result:
ok 1 number(s): "9112169164"
Test #20:
score: 10
Accepted
time: 676ms
memory: 103788kb
input:
100000 100000 0 5 321 321 321 318 320 318 317 321 319 320 317 318 321 317 317 318 319 321 321 319 319 317 319 321 318 319 318 317 321 320 317 321 318 317 319 319 318 319 321 321 319 317 321 319 317 321 318 318 317 317 320 317 319 319 317 321 317 319 317 320 321 317 319 318 317 321 320 317 319 319 32...
output:
4644520350
result:
ok 1 number(s): "4644520350"
Test #21:
score: 10
Accepted
time: 28ms
memory: 103668kb
input:
100000 100000 0 5 99741 99785 99945 99814 99716 99908 99993 99894 99992 99727 99769 99900 99825 99721 99912 99721 99888 99996 99842 99772 99841 99748 99895 99698 99839 99706 99883 99905 99751 99761 99711 99779 99864 99935 99927 99930 99715 99687 99987 99861 99830 99791 99929 99904 99687 99755 99802 ...
output:
461415122
result:
ok 1 number(s): "461415122"
Test #22:
score: 10
Accepted
time: 289ms
memory: 100620kb
input:
100000 100000 0 5 99994 321 174 99919 154 22327 319 99768 99776 251 167 26 136 204 238 94 318 99949 13887 320 317 99776 319 239 24 162 183 99805 321 270 93 321 63 32 117 320 317 99820 63 99877 193 99825 320 321 99753 99858 99911 318 319 99884 319 99800 93 99737 99740 60184 99885 99950 317 99939 320 ...
output:
4590723790
result:
ok 1 number(s): "4590723790"
Test #23:
score: 10
Accepted
time: 16ms
memory: 102812kb
input:
100000 100000 0 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
9999900000
result:
ok 1 number(s): "9999900000"
Test #24:
score: 10
Accepted
time: 258ms
memory: 102364kb
input:
100000 100000 0 5 87564 98687 95082 86046 59414 92993 1441 87994 42233 49845 91114 32159 31160 50038 67919 29885 82383 87674 3363 86912 54853 14045 25007 87793 44557 70863 70455 8631 19993 83876 70320 64268 29173 6914 73921 56750 67652 13938 49602 6379 43284 13161 12319 72250 50131 47821 87829 49558...
output:
128441922
result:
ok 1 number(s): "128441922"
Test #25:
score: 10
Accepted
time: 15ms
memory: 103620kb
input:
100000 100000 0 5 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
output:
9999900000
result:
ok 1 number(s): "9999900000"
Subtask #6:
score: 0
Time Limit Exceeded
Test #26:
score: 10
Accepted
time: 1864ms
memory: 310776kb
input:
100000 100000 1 6 99 254 235 123 310 237 248 278 100 34 213 275 66 242 297 120 272 185 140 149 276 165 163 162 119 142 79 6 66 163 134 296 176 12 45 96 152 200 59 127 279 249 67 111 208 49 161 121 153 72 280 164 310 266 228 23 101 197 88 245 32 23 51 140 206 112 207 164 207 40 262 245 224 258 167 15...
output:
9115701137 222488541689194
result:
ok 2 number(s): "9115701137 222488541689194"
Test #27:
score: 0
Time Limit Exceeded
input:
100000 100000 1 6 321 317 317 318 320 317 318 320 317 318 320 321 317 320 320 318 319 318 318 319 321 319 318 317 318 317 321 321 320 317 317 320 320 320 321 320 317 320 318 317 321 320 319 318 318 318 317 321 318 318 318 320 320 321 317 319 321 318 319 317 318 320 320 317 319 318 317 319 320 317 31...
output:
result:
Subtask #7:
score: 0
Time Limit Exceeded
Test #33:
score: 10
Accepted
time: 27ms
memory: 263184kb
input:
300000 300000 0 7 101 52 102 151 14 514 86 100 239 399 486 520 239 489 176 112 517 478 215 539 134 46 200 54 307 48 78 220 205 433 509 312 381 13 457 515 481 223 326 300 193 103 289 203 393 25 506 137 7 239 201 343 165 107 135 487 16 162 177 369 415 246 59 169 127 522 207 465 418 287 311 248 298 311...
output:
82066272311
result:
ok 1 number(s): "82066272311"
Test #34:
score: 0
Time Limit Exceeded
input:
300000 300000 0 7 548 549 551 548 548 551 552 548 548 549 552 549 548 551 549 549 552 550 551 548 549 549 550 551 551 550 550 550 548 550 548 549 549 550 549 548 549 548 552 548 548 549 550 552 552 548 549 551 550 551 549 551 552 552 550 550 552 552 552 551 548 552 549 548 551 548 551 549 550 552 55...
output:
result:
Subtask #8:
score: 0
Time Limit Exceeded
Test #40:
score: 0
Time Limit Exceeded
input:
300000 300000 1 8 404 482 307 14 397 186 112 173 197 389 278 419 417 196 138 264 161 330 395 465 84 516 235 507 515 247 222 268 105 119 435 328 514 337 356 246 204 370 364 174 512 538 129 135 203 348 247 58 430 238 165 397 203 145 175 435 158 297 443 446 467 3 493 294 394 375 157 405 385 449 116 361...
output:
result:
Subtask #9:
score: 0
Time Limit Exceeded
Test #47:
score: 15
Accepted
time: 63ms
memory: 423076kb
input:
500000 500000 0 9 464 653 212 650 549 203 500 292 366 468 464 660 240 393 279 587 405 403 148 638 438 251 441 92 302 270 56 271 559 639 474 193 644 310 48 548 559 289 163 439 372 425 121 459 620 636 282 610 133 283 215 317 451 166 431 21 139 229 261 260 9 112 71 468 287 312 680 330 95 140 92 44 238 ...
output:
227886764436
result:
ok 1 number(s): "227886764436"
Test #48:
score: 0
Time Limit Exceeded
input:
500000 500000 0 9 708 709 709 709 711 711 708 712 708 712 711 710 711 712 708 710 708 711 708 710 710 708 711 712 710 708 709 711 710 710 711 709 708 709 712 710 710 711 710 708 712 709 709 711 711 708 710 711 709 708 711 708 708 708 710 709 708 708 710 712 712 708 709 712 709 709 711 708 712 710 71...
output:
result:
Subtask #10:
score: 0
Time Limit Exceeded
Test #54:
score: 0
Time Limit Exceeded
input:
500000 500000 1 10 508 318 336 300 675 515 168 520 687 644 236 670 590 176 478 99 119 556 430 385 117 89 483 321 194 194 314 236 438 142 18 499 161 495 649 255 190 667 396 600 165 376 547 145 390 43 485 645 32 685 54 276 322 353 659 516 102 440 476 351 282 94 222 594 98 399 22 434 50 76 84 504 2 173...