#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define N 100005
ll n,fix[N],ans,f[2*N];
pair< vector<ll>,ll > v1[N],v2[N];
void upd(ll u)
{
u++;
while (u<=2*n)
{
f[u]++;
u+=(u&(-u));
}
return;
}
ll get(ll u,ll v)
{
v++;
ll tans=0;
while (v>0)
{
tans+=f[v];
v-=(v&(-v));
}
while (u>0)
{
tans-=f[u];
u-=(u&(-u));
}
return tans;
}
ll count_swaps(vector<int> a)
{
n=a.size()/2;
for (int i=0; i<2*n; i++)
{
if (a[i]<0)
{
v1[-a[i]].F.pb(i);
if ( v2[-a[i]].F.size()-v2[-a[i]].S>0 )
{
//cout<<i<<" "<<(v2[-a[i]].F)[ v2[-a[i]].S ]<<endl;
fix[i]= (v2[-a[i]].F)[ v2[-a[i]].S ];
fix[ (v2[-a[i]].F)[ v2[-a[i]].S ] ]
=(v2[-a[i]].F)[ v2[-a[i]].S ];
v1[-a[i]].S++;
v2[-a[i]].S++;
}
}
else
{
v2[a[i]].F.pb(i);
if ( v1[a[i]].F.size()-v1[a[i]].S>0 )
{
//cout<<i<<" "<<(v1[a[i]].F)[ v1[a[i]].S ]<<endl;
fix[i]= (v1[a[i]].F)[ v1[a[i]].S ];
fix[ (v1[a[i]].F)[ v1[a[i]].S ] ]
=(v1[a[i]].F)[ v1[a[i]].S ];
v2[a[i]].S++;
v1[a[i]].S++;
}
}
}
for (int i=0; i<2*n; i++)
{
upd(fix[i]);
if (i==fix[i])
continue;
ans+=get(fix[i]+1,i);
if (a[i]<a[fix[i]])
ans++;
}
return ans;
//cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
3 |
Correct |
7 ms |
6648 KB |
Output is correct |
4 |
Correct |
8 ms |
6612 KB |
Output is correct |
5 |
Correct |
7 ms |
6648 KB |
Output is correct |
6 |
Correct |
8 ms |
6648 KB |
Output is correct |
7 |
Correct |
7 ms |
6520 KB |
Output is correct |
8 |
Correct |
7 ms |
6648 KB |
Output is correct |
9 |
Correct |
7 ms |
6648 KB |
Output is correct |
10 |
Correct |
8 ms |
6648 KB |
Output is correct |
11 |
Correct |
7 ms |
6520 KB |
Output is correct |
12 |
Correct |
7 ms |
6524 KB |
Output is correct |
13 |
Correct |
9 ms |
6648 KB |
Output is correct |
14 |
Correct |
7 ms |
6520 KB |
Output is correct |
15 |
Correct |
9 ms |
6648 KB |
Output is correct |
16 |
Correct |
7 ms |
6652 KB |
Output is correct |
17 |
Correct |
7 ms |
6520 KB |
Output is correct |
18 |
Correct |
7 ms |
6520 KB |
Output is correct |
19 |
Correct |
7 ms |
6520 KB |
Output is correct |
20 |
Correct |
8 ms |
6648 KB |
Output is correct |
21 |
Correct |
7 ms |
6648 KB |
Output is correct |
22 |
Correct |
7 ms |
6648 KB |
Output is correct |
23 |
Correct |
7 ms |
6520 KB |
Output is correct |
24 |
Correct |
7 ms |
6520 KB |
Output is correct |
25 |
Correct |
7 ms |
6648 KB |
Output is correct |
26 |
Correct |
7 ms |
6520 KB |
Output is correct |
27 |
Correct |
7 ms |
6648 KB |
Output is correct |
28 |
Correct |
8 ms |
6648 KB |
Output is correct |
29 |
Correct |
7 ms |
6520 KB |
Output is correct |
30 |
Correct |
7 ms |
6620 KB |
Output is correct |
31 |
Correct |
9 ms |
6520 KB |
Output is correct |
32 |
Correct |
7 ms |
6520 KB |
Output is correct |
33 |
Correct |
8 ms |
6520 KB |
Output is correct |
34 |
Correct |
9 ms |
6520 KB |
Output is correct |
35 |
Correct |
7 ms |
6648 KB |
Output is correct |
36 |
Correct |
7 ms |
6648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
3 |
Correct |
9 ms |
6620 KB |
Output is correct |
4 |
Correct |
8 ms |
6648 KB |
Output is correct |
5 |
Correct |
7 ms |
6520 KB |
Output is correct |
6 |
Correct |
7 ms |
6648 KB |
Output is correct |
7 |
Correct |
7 ms |
6520 KB |
Output is correct |
8 |
Correct |
7 ms |
6648 KB |
Output is correct |
9 |
Correct |
7 ms |
6652 KB |
Output is correct |
10 |
Correct |
7 ms |
6520 KB |
Output is correct |
11 |
Correct |
7 ms |
6520 KB |
Output is correct |
12 |
Correct |
9 ms |
6524 KB |
Output is correct |
13 |
Correct |
8 ms |
6648 KB |
Output is correct |
14 |
Correct |
7 ms |
6648 KB |
Output is correct |
15 |
Correct |
7 ms |
6648 KB |
Output is correct |
16 |
Correct |
7 ms |
6520 KB |
Output is correct |
17 |
Correct |
6 ms |
6648 KB |
Output is correct |
18 |
Correct |
8 ms |
6648 KB |
Output is correct |
19 |
Correct |
8 ms |
6648 KB |
Output is correct |
20 |
Correct |
12 ms |
7288 KB |
Output is correct |
21 |
Correct |
12 ms |
7360 KB |
Output is correct |
22 |
Runtime error |
49 ms |
19820 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6648 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
3 |
Correct |
7 ms |
6648 KB |
Output is correct |
4 |
Correct |
7 ms |
6520 KB |
Output is correct |
5 |
Incorrect |
56 ms |
11256 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
3 |
Correct |
7 ms |
6648 KB |
Output is correct |
4 |
Correct |
8 ms |
6612 KB |
Output is correct |
5 |
Correct |
7 ms |
6648 KB |
Output is correct |
6 |
Correct |
8 ms |
6648 KB |
Output is correct |
7 |
Correct |
7 ms |
6520 KB |
Output is correct |
8 |
Correct |
7 ms |
6648 KB |
Output is correct |
9 |
Correct |
7 ms |
6648 KB |
Output is correct |
10 |
Correct |
8 ms |
6648 KB |
Output is correct |
11 |
Correct |
7 ms |
6520 KB |
Output is correct |
12 |
Correct |
7 ms |
6524 KB |
Output is correct |
13 |
Correct |
9 ms |
6648 KB |
Output is correct |
14 |
Correct |
7 ms |
6520 KB |
Output is correct |
15 |
Correct |
9 ms |
6648 KB |
Output is correct |
16 |
Correct |
7 ms |
6652 KB |
Output is correct |
17 |
Correct |
7 ms |
6520 KB |
Output is correct |
18 |
Correct |
7 ms |
6520 KB |
Output is correct |
19 |
Correct |
7 ms |
6520 KB |
Output is correct |
20 |
Correct |
8 ms |
6648 KB |
Output is correct |
21 |
Correct |
7 ms |
6648 KB |
Output is correct |
22 |
Correct |
7 ms |
6648 KB |
Output is correct |
23 |
Correct |
7 ms |
6520 KB |
Output is correct |
24 |
Correct |
7 ms |
6520 KB |
Output is correct |
25 |
Correct |
7 ms |
6648 KB |
Output is correct |
26 |
Correct |
7 ms |
6520 KB |
Output is correct |
27 |
Correct |
7 ms |
6648 KB |
Output is correct |
28 |
Correct |
8 ms |
6648 KB |
Output is correct |
29 |
Correct |
7 ms |
6520 KB |
Output is correct |
30 |
Correct |
7 ms |
6620 KB |
Output is correct |
31 |
Correct |
9 ms |
6520 KB |
Output is correct |
32 |
Correct |
7 ms |
6520 KB |
Output is correct |
33 |
Correct |
8 ms |
6520 KB |
Output is correct |
34 |
Correct |
9 ms |
6520 KB |
Output is correct |
35 |
Correct |
7 ms |
6648 KB |
Output is correct |
36 |
Correct |
7 ms |
6648 KB |
Output is correct |
37 |
Correct |
7 ms |
6648 KB |
Output is correct |
38 |
Correct |
7 ms |
6520 KB |
Output is correct |
39 |
Correct |
8 ms |
6648 KB |
Output is correct |
40 |
Correct |
8 ms |
6648 KB |
Output is correct |
41 |
Correct |
8 ms |
6648 KB |
Output is correct |
42 |
Correct |
8 ms |
6648 KB |
Output is correct |
43 |
Correct |
8 ms |
6648 KB |
Output is correct |
44 |
Correct |
8 ms |
6652 KB |
Output is correct |
45 |
Correct |
8 ms |
6648 KB |
Output is correct |
46 |
Correct |
8 ms |
6652 KB |
Output is correct |
47 |
Correct |
8 ms |
6648 KB |
Output is correct |
48 |
Correct |
8 ms |
6648 KB |
Output is correct |
49 |
Correct |
8 ms |
6648 KB |
Output is correct |
50 |
Correct |
8 ms |
6648 KB |
Output is correct |
51 |
Correct |
8 ms |
6648 KB |
Output is correct |
52 |
Correct |
9 ms |
6648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
3 |
Correct |
7 ms |
6648 KB |
Output is correct |
4 |
Correct |
8 ms |
6612 KB |
Output is correct |
5 |
Correct |
7 ms |
6648 KB |
Output is correct |
6 |
Correct |
8 ms |
6648 KB |
Output is correct |
7 |
Correct |
7 ms |
6520 KB |
Output is correct |
8 |
Correct |
7 ms |
6648 KB |
Output is correct |
9 |
Correct |
7 ms |
6648 KB |
Output is correct |
10 |
Correct |
8 ms |
6648 KB |
Output is correct |
11 |
Correct |
7 ms |
6520 KB |
Output is correct |
12 |
Correct |
7 ms |
6524 KB |
Output is correct |
13 |
Correct |
9 ms |
6648 KB |
Output is correct |
14 |
Correct |
7 ms |
6520 KB |
Output is correct |
15 |
Correct |
9 ms |
6648 KB |
Output is correct |
16 |
Correct |
7 ms |
6652 KB |
Output is correct |
17 |
Correct |
7 ms |
6520 KB |
Output is correct |
18 |
Correct |
7 ms |
6520 KB |
Output is correct |
19 |
Correct |
7 ms |
6520 KB |
Output is correct |
20 |
Correct |
8 ms |
6648 KB |
Output is correct |
21 |
Correct |
7 ms |
6648 KB |
Output is correct |
22 |
Correct |
7 ms |
6648 KB |
Output is correct |
23 |
Correct |
7 ms |
6520 KB |
Output is correct |
24 |
Correct |
7 ms |
6520 KB |
Output is correct |
25 |
Correct |
7 ms |
6648 KB |
Output is correct |
26 |
Correct |
7 ms |
6520 KB |
Output is correct |
27 |
Correct |
7 ms |
6648 KB |
Output is correct |
28 |
Correct |
8 ms |
6648 KB |
Output is correct |
29 |
Correct |
7 ms |
6520 KB |
Output is correct |
30 |
Correct |
7 ms |
6620 KB |
Output is correct |
31 |
Correct |
9 ms |
6520 KB |
Output is correct |
32 |
Correct |
7 ms |
6520 KB |
Output is correct |
33 |
Correct |
8 ms |
6520 KB |
Output is correct |
34 |
Correct |
9 ms |
6520 KB |
Output is correct |
35 |
Correct |
7 ms |
6648 KB |
Output is correct |
36 |
Correct |
7 ms |
6648 KB |
Output is correct |
37 |
Correct |
9 ms |
6620 KB |
Output is correct |
38 |
Correct |
8 ms |
6648 KB |
Output is correct |
39 |
Correct |
7 ms |
6520 KB |
Output is correct |
40 |
Correct |
7 ms |
6648 KB |
Output is correct |
41 |
Correct |
7 ms |
6520 KB |
Output is correct |
42 |
Correct |
7 ms |
6648 KB |
Output is correct |
43 |
Correct |
7 ms |
6652 KB |
Output is correct |
44 |
Correct |
7 ms |
6520 KB |
Output is correct |
45 |
Correct |
7 ms |
6520 KB |
Output is correct |
46 |
Correct |
9 ms |
6524 KB |
Output is correct |
47 |
Correct |
8 ms |
6648 KB |
Output is correct |
48 |
Correct |
7 ms |
6648 KB |
Output is correct |
49 |
Correct |
7 ms |
6648 KB |
Output is correct |
50 |
Correct |
7 ms |
6520 KB |
Output is correct |
51 |
Correct |
6 ms |
6648 KB |
Output is correct |
52 |
Correct |
8 ms |
6648 KB |
Output is correct |
53 |
Correct |
8 ms |
6648 KB |
Output is correct |
54 |
Correct |
12 ms |
7288 KB |
Output is correct |
55 |
Correct |
12 ms |
7360 KB |
Output is correct |
56 |
Runtime error |
49 ms |
19820 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
57 |
Halted |
0 ms |
0 KB |
- |