/*input
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<'('<<P.F<<','<<P.S<<')';
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
return out;
}
#define version 20190814
//}}}
const ll maxn=100005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
int n;
vector<pii> p;
vector<int> sz[maxn+maxn];
int pt[maxn+maxn];
int BIT[maxn+maxn];
int low(int i){
return i&-i;
}
void mdf(int n,int d){
for(int i=n;i<maxn+maxn;i+=low(i+1)){
BIT[i]+=d;
}
}
int query(int n){
int ret=0;
for(int i=n;i>=0;i-=low(i+1)){
ret+=BIT[i];
}
return ret;
}
int query(int l,int r){
return query(r-1)-query(l-1);
}
ll count_swaps(vector<int> a){
ll ans=0;
n=SZ(a)/2;
REP(i,n+n){
int cur=a[i];
if(pt[-cur+maxn]==SZ(sz[-cur+maxn])){
sz[cur+maxn].pb(i);
}
else{
p.eb(sz[maxn-cur][pt[maxn-cur]],i);
if(cur<0) ans++;
pt[maxn-cur]++;
}
}
sort(ALL(p));
for(auto i:p){
ans+=2*query(i.S,n+n+1)+query(i.F,i.S);
mdf(i.S,1);
}
return ans;
}
// int main(){
// cout<<count_swaps(vector<int>{1,1,1,1,-1,-1,-1,-1})<<'\n';
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5116 KB |
Output is correct |
10 |
Correct |
6 ms |
4984 KB |
Output is correct |
11 |
Correct |
7 ms |
4988 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5048 KB |
Output is correct |
17 |
Correct |
7 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
7 ms |
5112 KB |
Output is correct |
21 |
Correct |
6 ms |
5112 KB |
Output is correct |
22 |
Correct |
7 ms |
4988 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
4984 KB |
Output is correct |
25 |
Correct |
8 ms |
5112 KB |
Output is correct |
26 |
Correct |
6 ms |
4984 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
6 ms |
4984 KB |
Output is correct |
29 |
Correct |
7 ms |
4984 KB |
Output is correct |
30 |
Correct |
7 ms |
4984 KB |
Output is correct |
31 |
Correct |
7 ms |
4984 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
6 ms |
4984 KB |
Output is correct |
34 |
Correct |
6 ms |
4988 KB |
Output is correct |
35 |
Correct |
6 ms |
4984 KB |
Output is correct |
36 |
Correct |
6 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
8 ms |
5240 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
4984 KB |
Output is correct |
11 |
Correct |
6 ms |
4984 KB |
Output is correct |
12 |
Correct |
8 ms |
4984 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
7 ms |
5112 KB |
Output is correct |
15 |
Correct |
7 ms |
5112 KB |
Output is correct |
16 |
Correct |
7 ms |
4984 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
8 ms |
5112 KB |
Output is correct |
20 |
Correct |
11 ms |
5624 KB |
Output is correct |
21 |
Correct |
12 ms |
5628 KB |
Output is correct |
22 |
Correct |
49 ms |
10092 KB |
Output is correct |
23 |
Correct |
44 ms |
10088 KB |
Output is correct |
24 |
Correct |
48 ms |
10348 KB |
Output is correct |
25 |
Correct |
42 ms |
9408 KB |
Output is correct |
26 |
Correct |
48 ms |
10088 KB |
Output is correct |
27 |
Correct |
42 ms |
9832 KB |
Output is correct |
28 |
Correct |
43 ms |
9580 KB |
Output is correct |
29 |
Correct |
43 ms |
9576 KB |
Output is correct |
30 |
Correct |
43 ms |
9580 KB |
Output is correct |
31 |
Correct |
48 ms |
10348 KB |
Output is correct |
32 |
Correct |
45 ms |
9708 KB |
Output is correct |
33 |
Correct |
43 ms |
9428 KB |
Output is correct |
34 |
Correct |
44 ms |
9580 KB |
Output is correct |
35 |
Correct |
6 ms |
4984 KB |
Output is correct |
36 |
Correct |
6 ms |
4984 KB |
Output is correct |
37 |
Correct |
45 ms |
9560 KB |
Output is correct |
38 |
Correct |
44 ms |
9532 KB |
Output is correct |
39 |
Correct |
44 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
68 ms |
12272 KB |
Output is correct |
6 |
Correct |
57 ms |
10408 KB |
Output is correct |
7 |
Correct |
71 ms |
12648 KB |
Output is correct |
8 |
Correct |
49 ms |
9616 KB |
Output is correct |
9 |
Correct |
66 ms |
12624 KB |
Output is correct |
10 |
Correct |
63 ms |
11116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5116 KB |
Output is correct |
10 |
Correct |
6 ms |
4984 KB |
Output is correct |
11 |
Correct |
7 ms |
4988 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5048 KB |
Output is correct |
17 |
Correct |
7 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
7 ms |
5112 KB |
Output is correct |
21 |
Correct |
6 ms |
5112 KB |
Output is correct |
22 |
Correct |
7 ms |
4988 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
4984 KB |
Output is correct |
25 |
Correct |
8 ms |
5112 KB |
Output is correct |
26 |
Correct |
6 ms |
4984 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
6 ms |
4984 KB |
Output is correct |
29 |
Correct |
7 ms |
4984 KB |
Output is correct |
30 |
Correct |
7 ms |
4984 KB |
Output is correct |
31 |
Correct |
7 ms |
4984 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
6 ms |
4984 KB |
Output is correct |
34 |
Correct |
6 ms |
4988 KB |
Output is correct |
35 |
Correct |
6 ms |
4984 KB |
Output is correct |
36 |
Correct |
6 ms |
4984 KB |
Output is correct |
37 |
Correct |
6 ms |
5112 KB |
Output is correct |
38 |
Correct |
6 ms |
4984 KB |
Output is correct |
39 |
Correct |
6 ms |
4984 KB |
Output is correct |
40 |
Correct |
6 ms |
5112 KB |
Output is correct |
41 |
Correct |
7 ms |
5112 KB |
Output is correct |
42 |
Correct |
7 ms |
5112 KB |
Output is correct |
43 |
Correct |
7 ms |
5112 KB |
Output is correct |
44 |
Correct |
7 ms |
5112 KB |
Output is correct |
45 |
Correct |
7 ms |
5112 KB |
Output is correct |
46 |
Correct |
7 ms |
5112 KB |
Output is correct |
47 |
Correct |
7 ms |
5084 KB |
Output is correct |
48 |
Correct |
7 ms |
5084 KB |
Output is correct |
49 |
Correct |
7 ms |
5112 KB |
Output is correct |
50 |
Correct |
7 ms |
5116 KB |
Output is correct |
51 |
Correct |
7 ms |
5112 KB |
Output is correct |
52 |
Correct |
7 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5116 KB |
Output is correct |
10 |
Correct |
6 ms |
4984 KB |
Output is correct |
11 |
Correct |
7 ms |
4988 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
4984 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5048 KB |
Output is correct |
17 |
Correct |
7 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
7 ms |
5112 KB |
Output is correct |
21 |
Correct |
6 ms |
5112 KB |
Output is correct |
22 |
Correct |
7 ms |
4988 KB |
Output is correct |
23 |
Correct |
6 ms |
4984 KB |
Output is correct |
24 |
Correct |
6 ms |
4984 KB |
Output is correct |
25 |
Correct |
8 ms |
5112 KB |
Output is correct |
26 |
Correct |
6 ms |
4984 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
6 ms |
4984 KB |
Output is correct |
29 |
Correct |
7 ms |
4984 KB |
Output is correct |
30 |
Correct |
7 ms |
4984 KB |
Output is correct |
31 |
Correct |
7 ms |
4984 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
6 ms |
4984 KB |
Output is correct |
34 |
Correct |
6 ms |
4988 KB |
Output is correct |
35 |
Correct |
6 ms |
4984 KB |
Output is correct |
36 |
Correct |
6 ms |
4984 KB |
Output is correct |
37 |
Correct |
6 ms |
4984 KB |
Output is correct |
38 |
Correct |
8 ms |
5240 KB |
Output is correct |
39 |
Correct |
6 ms |
4984 KB |
Output is correct |
40 |
Correct |
6 ms |
4984 KB |
Output is correct |
41 |
Correct |
6 ms |
4984 KB |
Output is correct |
42 |
Correct |
7 ms |
5112 KB |
Output is correct |
43 |
Correct |
7 ms |
5112 KB |
Output is correct |
44 |
Correct |
6 ms |
4984 KB |
Output is correct |
45 |
Correct |
6 ms |
4984 KB |
Output is correct |
46 |
Correct |
8 ms |
4984 KB |
Output is correct |
47 |
Correct |
6 ms |
4984 KB |
Output is correct |
48 |
Correct |
7 ms |
5112 KB |
Output is correct |
49 |
Correct |
7 ms |
5112 KB |
Output is correct |
50 |
Correct |
7 ms |
4984 KB |
Output is correct |
51 |
Correct |
6 ms |
5112 KB |
Output is correct |
52 |
Correct |
6 ms |
5112 KB |
Output is correct |
53 |
Correct |
8 ms |
5112 KB |
Output is correct |
54 |
Correct |
11 ms |
5624 KB |
Output is correct |
55 |
Correct |
12 ms |
5628 KB |
Output is correct |
56 |
Correct |
49 ms |
10092 KB |
Output is correct |
57 |
Correct |
44 ms |
10088 KB |
Output is correct |
58 |
Correct |
48 ms |
10348 KB |
Output is correct |
59 |
Correct |
42 ms |
9408 KB |
Output is correct |
60 |
Correct |
48 ms |
10088 KB |
Output is correct |
61 |
Correct |
42 ms |
9832 KB |
Output is correct |
62 |
Correct |
43 ms |
9580 KB |
Output is correct |
63 |
Correct |
43 ms |
9576 KB |
Output is correct |
64 |
Correct |
43 ms |
9580 KB |
Output is correct |
65 |
Correct |
48 ms |
10348 KB |
Output is correct |
66 |
Correct |
45 ms |
9708 KB |
Output is correct |
67 |
Correct |
43 ms |
9428 KB |
Output is correct |
68 |
Correct |
44 ms |
9580 KB |
Output is correct |
69 |
Correct |
6 ms |
4984 KB |
Output is correct |
70 |
Correct |
6 ms |
4984 KB |
Output is correct |
71 |
Correct |
45 ms |
9560 KB |
Output is correct |
72 |
Correct |
44 ms |
9532 KB |
Output is correct |
73 |
Correct |
44 ms |
9580 KB |
Output is correct |
74 |
Correct |
6 ms |
4984 KB |
Output is correct |
75 |
Correct |
6 ms |
4984 KB |
Output is correct |
76 |
Correct |
7 ms |
4984 KB |
Output is correct |
77 |
Correct |
6 ms |
4984 KB |
Output is correct |
78 |
Correct |
68 ms |
12272 KB |
Output is correct |
79 |
Correct |
57 ms |
10408 KB |
Output is correct |
80 |
Correct |
71 ms |
12648 KB |
Output is correct |
81 |
Correct |
49 ms |
9616 KB |
Output is correct |
82 |
Correct |
66 ms |
12624 KB |
Output is correct |
83 |
Correct |
63 ms |
11116 KB |
Output is correct |
84 |
Correct |
6 ms |
5112 KB |
Output is correct |
85 |
Correct |
6 ms |
4984 KB |
Output is correct |
86 |
Correct |
6 ms |
4984 KB |
Output is correct |
87 |
Correct |
6 ms |
5112 KB |
Output is correct |
88 |
Correct |
7 ms |
5112 KB |
Output is correct |
89 |
Correct |
7 ms |
5112 KB |
Output is correct |
90 |
Correct |
7 ms |
5112 KB |
Output is correct |
91 |
Correct |
7 ms |
5112 KB |
Output is correct |
92 |
Correct |
7 ms |
5112 KB |
Output is correct |
93 |
Correct |
7 ms |
5112 KB |
Output is correct |
94 |
Correct |
7 ms |
5084 KB |
Output is correct |
95 |
Correct |
7 ms |
5084 KB |
Output is correct |
96 |
Correct |
7 ms |
5112 KB |
Output is correct |
97 |
Correct |
7 ms |
5116 KB |
Output is correct |
98 |
Correct |
7 ms |
5112 KB |
Output is correct |
99 |
Correct |
7 ms |
5112 KB |
Output is correct |
100 |
Correct |
7 ms |
5112 KB |
Output is correct |
101 |
Correct |
13 ms |
5856 KB |
Output is correct |
102 |
Correct |
13 ms |
5724 KB |
Output is correct |
103 |
Correct |
85 ms |
13252 KB |
Output is correct |
104 |
Correct |
76 ms |
13036 KB |
Output is correct |
105 |
Correct |
76 ms |
12524 KB |
Output is correct |
106 |
Correct |
74 ms |
12756 KB |
Output is correct |
107 |
Correct |
72 ms |
10604 KB |
Output is correct |
108 |
Correct |
60 ms |
10852 KB |
Output is correct |
109 |
Correct |
48 ms |
9924 KB |
Output is correct |
110 |
Correct |
43 ms |
9580 KB |
Output is correct |
111 |
Correct |
69 ms |
12392 KB |
Output is correct |
112 |
Correct |
80 ms |
12612 KB |
Output is correct |
113 |
Correct |
66 ms |
10348 KB |
Output is correct |
114 |
Correct |
65 ms |
12656 KB |
Output is correct |
115 |
Correct |
65 ms |
12656 KB |
Output is correct |