QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#446328 | #8478. Count the Orders | Crysfly# | AC ✓ | 102ms | 35520kb | C++17 | 2.7kb | 2024-06-17 08:14:21 | 2024-06-17 08:14:21 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 2000005
#define inf 0x3f3f3f3f
int n,a[maxn];
signed main()
{
n=read();
For(i,1,n)a[i]=read();
sort(a+1,a+n+1);
int res1=0;
if(n%2==0){
For(i,1,n/2)res1-=a[i],res1+=a[i+n/2];
res1*=2;
}else{
For(i,1,n/2)res1-=a[i];
For(i,n/2+2,n) res1+=a[i];
res1*=2;
}
modint ans=2; initC (n+1);
if(n%2==0) ans*=fac[n/2]*fac[n/2];
else ans*=fac[n/2]*fac[n/2]*n;
cout<<res1<<" "<<ans.x;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 1 2 3
output:
4 6
result:
ok 2 number(s): "4 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
4 2 4 8 16
output:
36 8
result:
ok 2 number(s): "36 8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
3 5 4 0
output:
10 6
result:
ok 2 number(s): "10 6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
5 10 8 6 4 9
output:
18 40
result:
ok 2 number(s): "18 40"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2376 732066934 787542711 613501093 852473623 294446565 348122408 985289328 167507061 806658388 511121222 341853121 153515566 820156407 742092647 113223691 901598965 606847836 755274866 370445420 672512540 744829773 947466591 988254594 283996337 807278550 917042422 344327102 74159600 245925457 536756...
output:
1206878118958 227684311
result:
ok 2 number(s): "1206878118958 227684311"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
2377 935443973 282098110 209733886 994373215 912009508 876448128 794342915 637565822 984754099 595493904 205732238 973706007 854823592 591159508 506469482 156715511 435918789 201563114 304957195 408581821 274822218 989898695 270185305 109848364 368694635 958374896 162548084 343715789 815972256 63271...
output:
1172332713482 205603460
result:
ok 2 number(s): "1172332713482 205603460"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
8099 284731 400001 410350 591342 466151 982943 577756 127675 456050 248864 655241 701130 295551 153378 382573 448292 309384 119566 722747 698777 170131 296900 909362 662800 900549 272225 863670 557073 880109 615108 710467 175261 439958 615173 14262 563143 155779 911214 804822 56855 610827 604616 889...
output:
3997895838 950346386
result:
ok 2 number(s): "3997895838 950346386"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
8100 342844 622626 352193 612128 821195 978850 273042 709888 133046 968791 680954 122753 217230 793728 990436 60018 586075 659219 331060 845883 165053 26041 138436 735701 887259 440588 576223 193024 944758 381242 947197 418428 917120 833672 855776 686407 197479 98244 720120 616770 133695 305009 1390...
output:
3968639332 714839769
result:
ok 2 number(s): "3968639332 714839769"
Test #9:
score: 0
Accepted
time: 7ms
memory: 5236kb
input:
70000 517299912 781627191 277315750 154595966 705349441 157372384 742980103 973597394 724221526 286427220 902709358 535847733 913715560 635964309 526703281 258086995 726404338 991571511 522980315 975919435 682049977 633907155 158094409 430377285 106192659 911537112 617116386 915970341 675539766 7244...
output:
31433068564330 251682640
result:
ok 2 number(s): "31433068564330 251682640"
Test #10:
score: 0
Accepted
time: 7ms
memory: 5244kb
input:
70001 933908512 332481434 277587672 209990853 243123141 548498376 917704381 283009230 846466804 861207469 991069319 473411889 778332214 450366950 220818685 273687639 310771401 160889850 121544026 389317160 728698838 950642363 478297068 834555683 406488062 926057398 839599151 616643957 187485457 6462...
output:
31554480244590 36359314
result:
ok 2 number(s): "31554480244590 36359314"
Test #11:
score: 0
Accepted
time: 17ms
memory: 11456kb
input:
200001 218216268 190626852 879553956 919180462 337088089 408821918 567907115 710620605 692800304 761529778 851982084 563343220 782647938 713887404 543533549 565581548 425006358 257037083 185164137 919030279 768301007 247468599 616256184 206490667 949837207 216042172 607839745 957950610 623089023 985...
output:
89966512736670 224781302
result:
ok 2 number(s): "89966512736670 224781302"
Test #12:
score: 0
Accepted
time: 16ms
memory: 10444kb
input:
200002 928240202 436448387 879825877 681160016 979894499 104980619 947664103 803382357 815045581 641342735 245374753 999355417 852297301 323257336 149266328 874597526 214406130 121322713 683727848 244045379 609917160 769236517 936458842 112221023 350132609 142179834 536907177 658624226 135034713 702...
output:
90101732731778 116138171
result:
ok 2 number(s): "90101732731778 116138171"
Test #13:
score: 0
Accepted
time: 89ms
memory: 34748kb
input:
953547 1451866 842217196 890450923 285774195 693778568 182073139 430811616 563014436 946088298 331891428 479538820 350527184 261377935 874616760 99150192 825085544 799089973 248726848 663075263 445481090 11450166 13331555 809049505 221143016 164336514 680827572 62017374 961446558 215120832 577504413...
output:
476348290385774 235960272
result:
ok 2 number(s): "476348290385774 235960272"
Test #14:
score: 0
Accepted
time: 93ms
memory: 34264kb
input:
953546 208140244 757727213 294218128 143874602 2586697 653747420 916725321 387922967 473025295 583955236 320692410 825304036 595306970 394146118 705904402 569968996 970019020 802438600 802192416 414444517 481457721 307335940 453489865 690258281 307953137 344527805 875200173 396923077 645074034 77651...
output:
476784085046616 512221463
result:
ok 2 number(s): "476784085046616 512221463"
Test #15:
score: 0
Accepted
time: 89ms
memory: 35520kb
input:
999999 911863811 754863254 561033371 349559949 647200530 147936389 735339526 232833647 261253113 666188427 320354576 316174369 260512319 644956738 506288568 386063570 746112462 738491125 320204176 733919169 713557343 999901152 641114045 261567125 104784885 469461004 579504556 269470250 770564184 371...
output:
450385098741434 853894696
result:
ok 2 number(s): "450385098741434 853894696"
Test #16:
score: 0
Accepted
time: 102ms
memory: 35228kb
input:
1000000 236195468 824547497 979416770 180544348 300491503 601981326 978063651 471145636 238343154 779139993 609655092 582421539 506457663 599022777 728080175 302343293 223012711 495497029 501153863 130436763 442094943 920146502 625105113 854112855 187620401 312321272 533342176 496949914 731908631 13...
output:
450053775159532 335360022
result:
ok 2 number(s): "450053775159532 335360022"