Submission #946408
Source Code Expand
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL fac[SIZE];
void ADD(LL& x,LL v){
x=(x+v)%MOD;
if(x<0)x+=MOD;
}
LL mypow(LL x,LL y){
x%=MOD;
LL res=1%MOD;
while(y){
if(y&1)res=res*x%MOD;
y>>=1;
x=x*x%MOD;
}
return res;
}
int p[SIZE];
int BIT[SIZE];
void ins(int x){
for(;x<SIZE;x+=x&-x)BIT[x]++;
}
int qq(int x){
int res=0;
for(;x;x-=x&-x)res+=BIT[x];
return res;
}
int BIT2[SIZE];
void ins2(int x){
for(;x<SIZE;x+=x&-x)BIT2[x]++;
}
int qq2(int x){
int res=0;
for(;x;x-=x&-x)res+=BIT2[x];
return res;
}
bool use[SIZE];
int main(){
fac[0]=1;
REPP(i,1,SIZE)fac[i]=fac[i-1]*i%MOD;
DRI(n);
LL zero=0;
REP(i,n){
RI(p[i+1]);
if(!p[i+1])zero++;
else use[p[i+1]]=1;
}
LL sum=0;
int it=0;
REPP(i,1,n+1)
if(!use[i]){
ins(i);
sum+=i-1-it;
it++;
}
sum%=MOD;
LL an=fac[zero];
LL emp=0;
LL inv_two=mypow(2,MOD-2);
REPP(i,1,n+1){
if(!p[i]){
ADD(an,sum*fac[zero-1]%MOD*fac[n-i]);
if(zero>1)ADD(an,fac[zero]*(zero-emp-1)%MOD*inv_two%MOD*fac[n-i]);
emp++;
}
else{
LL ll=qq(p[i]);
LL ll2=qq2(p[i]);
ADD(an,(p[i]-1-ll-ll2)*fac[zero]%MOD*fac[n-i]);
if(zero)ADD(an,ll*(zero-emp)%MOD*fac[zero-1]%MOD*fac[n-i]);
ADD(sum,-(zero-ll));
ins2(p[i]);
}
//printf("%d:%lld\n",i,an);
}
cout<<an<<endl;
return 0;
}
Submission Info
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:68:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
DRI(n);
^
./Main.cpp:71:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
RI(p[i+1]);
^
Judge Result
Set Name |
Sample |
Subtask |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
700 / 700 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt |
Subtask |
0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt |
All |
0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt, 2_051.txt, 2_052.txt, 2_053.txt, 2_054.txt, 2_055.txt, 2_056.txt, 2_057.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
AC |
15 ms |
8192 KB |
0_001.txt |
AC |
15 ms |
8064 KB |
0_002.txt |
AC |
15 ms |
8064 KB |
0_003.txt |
AC |
15 ms |
8064 KB |
0_004.txt |
AC |
15 ms |
8192 KB |
1_005.txt |
AC |
15 ms |
8192 KB |
1_006.txt |
AC |
15 ms |
8192 KB |
1_007.txt |
AC |
15 ms |
8192 KB |
1_008.txt |
AC |
15 ms |
8192 KB |
1_009.txt |
AC |
15 ms |
8192 KB |
1_010.txt |
AC |
15 ms |
8192 KB |
1_011.txt |
AC |
15 ms |
8192 KB |
1_012.txt |
AC |
15 ms |
8192 KB |
1_013.txt |
AC |
15 ms |
8192 KB |
1_014.txt |
AC |
15 ms |
8192 KB |
1_015.txt |
AC |
15 ms |
8192 KB |
1_016.txt |
AC |
15 ms |
8192 KB |
1_017.txt |
AC |
15 ms |
8064 KB |
1_018.txt |
AC |
15 ms |
8192 KB |
1_019.txt |
AC |
15 ms |
8192 KB |
1_020.txt |
AC |
15 ms |
8192 KB |
1_021.txt |
AC |
15 ms |
8192 KB |
1_022.txt |
AC |
16 ms |
8192 KB |
1_023.txt |
AC |
15 ms |
8192 KB |
1_024.txt |
AC |
15 ms |
8192 KB |
1_025.txt |
AC |
15 ms |
8192 KB |
1_026.txt |
AC |
15 ms |
8064 KB |
1_027.txt |
AC |
15 ms |
8064 KB |
1_028.txt |
AC |
15 ms |
8192 KB |
1_029.txt |
AC |
15 ms |
8192 KB |
1_030.txt |
AC |
15 ms |
8064 KB |
1_031.txt |
AC |
15 ms |
8064 KB |
1_032.txt |
AC |
15 ms |
8192 KB |
2_033.txt |
AC |
68 ms |
12032 KB |
2_034.txt |
AC |
42 ms |
10112 KB |
2_035.txt |
AC |
83 ms |
14464 KB |
2_036.txt |
AC |
77 ms |
13952 KB |
2_037.txt |
AC |
91 ms |
14464 KB |
2_038.txt |
AC |
82 ms |
13696 KB |
2_039.txt |
AC |
97 ms |
14464 KB |
2_040.txt |
AC |
53 ms |
11264 KB |
2_041.txt |
AC |
104 ms |
14464 KB |
2_042.txt |
AC |
30 ms |
9344 KB |
2_043.txt |
AC |
114 ms |
14464 KB |
2_044.txt |
AC |
73 ms |
12288 KB |
2_045.txt |
AC |
114 ms |
14464 KB |
2_046.txt |
AC |
109 ms |
14208 KB |
2_047.txt |
AC |
115 ms |
14464 KB |
2_048.txt |
AC |
54 ms |
10880 KB |
2_049.txt |
AC |
120 ms |
14464 KB |
2_050.txt |
AC |
77 ms |
12288 KB |
2_051.txt |
AC |
112 ms |
12416 KB |
2_052.txt |
AC |
101 ms |
12032 KB |
2_053.txt |
AC |
69 ms |
12032 KB |
2_054.txt |
AC |
120 ms |
12544 KB |
2_055.txt |
AC |
91 ms |
12544 KB |
2_056.txt |
AC |
91 ms |
12416 KB |
2_057.txt |
AC |
84 ms |
14464 KB |