Submission #3679490
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=1e5+5;
int n,m,a[N],b[N],tree[4*N],tree2[4*N],lazy[4*N];
ll ans;
void initseg(int nd,int l,int r)
{
if(l==r){ tree[nd]=b[l]; tree2[nd]=l; return; }
int m=(l+r)/2;
initseg(nd*2,l,m);
initseg(nd*2+1,m+1,r);
tree[nd]=tree[nd*2];
tree2[nd]=l;
}
void pushdown(int nd,int l,int r)
{
if(l!=r){
lazy[nd*2]+=lazy[nd];
lazy[nd*2+1]+=lazy[nd];
}
tree[nd]+=lazy[nd];
lazy[nd]=0;
}
P query(int nd,int l,int r,int s,int e)
{
if(r<s||e<l) return P(2e9,2e9);
pushdown(nd,l,r);
if(s<=l&&r<=e) return P(tree[nd],tree2[nd]);
int m=(l+r)/2;
P p1=query(nd*2,l,m,s,e);
P p2=query(nd*2+1,m+1,r,s,e);
if(p1.first>p2.first) return p2;
return p1;
}
void update(int nd,int l,int r,int s,int e)
{
if(r<s||e<l) return;
pushdown(nd,l,r);
if(s<=l&&r<=e){
lazy[nd]++;
pushdown(nd,l,r);
return;
}
int m=(l+r)/2;
update(nd*2,l,m,s,e);
update(nd*2+1,m+1,r,s,e);
if(tree[nd*2]>tree[nd*2+1]){
tree[nd]=tree[nd*2+1];
tree2[nd]=tree2[nd*2+1];
}
else{
tree[nd]=tree[nd*2];
tree2[nd]=tree2[nd*2];
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){ cin>>a[i]; b[i]=a[i]; }
sort(b+1,b+1+n);
m=unique(b+1,b+1+n)-b-1;
initseg(1,1,m);
for(int i=1;i<=n;i++){
P tp=query(1,1,m,lower_bound(b+1,b+1+m,a[i])-b,m);
ans+=(ll)tp.first-a[i];
if(tp.second==1) continue;
update(1,1,m,1,tp.second-1);
}
cout<<ans;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Increment and Swap |
User |
moonrabbit2 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1748 Byte |
Status |
RE |
Exec Time |
111 ms |
Memory |
4608 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 1500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, example0.txt, example1.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
WA |
12 ms |
3200 KB |
001.txt |
WA |
10 ms |
3072 KB |
002.txt |
WA |
59 ms |
4096 KB |
003.txt |
WA |
45 ms |
4096 KB |
004.txt |
WA |
33 ms |
4096 KB |
005.txt |
WA |
58 ms |
4096 KB |
006.txt |
WA |
52 ms |
4096 KB |
007.txt |
RE |
108 ms |
1024 KB |
008.txt |
RE |
110 ms |
1024 KB |
009.txt |
WA |
27 ms |
3584 KB |
010.txt |
WA |
11 ms |
3200 KB |
011.txt |
RE |
108 ms |
1024 KB |
012.txt |
RE |
108 ms |
1024 KB |
013.txt |
RE |
109 ms |
1024 KB |
014.txt |
RE |
111 ms |
1024 KB |
015.txt |
RE |
109 ms |
1024 KB |
016.txt |
RE |
108 ms |
1024 KB |
017.txt |
WA |
79 ms |
4608 KB |
018.txt |
WA |
29 ms |
3584 KB |
019.txt |
RE |
108 ms |
1024 KB |
020.txt |
RE |
108 ms |
1024 KB |
021.txt |
WA |
15 ms |
2688 KB |
022.txt |
WA |
15 ms |
3328 KB |
023.txt |
WA |
68 ms |
4096 KB |
024.txt |
WA |
26 ms |
3200 KB |
025.txt |
WA |
24 ms |
3584 KB |
026.txt |
WA |
17 ms |
2816 KB |
027.txt |
WA |
27 ms |
3584 KB |
028.txt |
WA |
58 ms |
3968 KB |
029.txt |
WA |
54 ms |
3968 KB |
030.txt |
WA |
56 ms |
3968 KB |
031.txt |
WA |
35 ms |
4096 KB |
032.txt |
WA |
72 ms |
4096 KB |
033.txt |
WA |
76 ms |
4608 KB |
034.txt |
WA |
26 ms |
3584 KB |
035.txt |
WA |
23 ms |
3072 KB |
036.txt |
RE |
108 ms |
1024 KB |
037.txt |
WA |
69 ms |
4608 KB |
038.txt |
WA |
29 ms |
3200 KB |
039.txt |
RE |
109 ms |
1024 KB |
040.txt |
WA |
76 ms |
4608 KB |
041.txt |
WA |
11 ms |
3072 KB |
042.txt |
AC |
57 ms |
4608 KB |
043.txt |
WA |
60 ms |
4608 KB |
044.txt |
WA |
36 ms |
4096 KB |
045.txt |
AC |
2 ms |
2304 KB |
046.txt |
WA |
8 ms |
3072 KB |
047.txt |
RE |
109 ms |
1024 KB |
048.txt |
RE |
109 ms |
1024 KB |
049.txt |
WA |
10 ms |
3072 KB |
050.txt |
RE |
107 ms |
1024 KB |
051.txt |
WA |
10 ms |
3072 KB |
052.txt |
RE |
108 ms |
1024 KB |
053.txt |
WA |
11 ms |
3072 KB |
054.txt |
RE |
110 ms |
1024 KB |
055.txt |
WA |
12 ms |
3072 KB |
056.txt |
WA |
12 ms |
3072 KB |
057.txt |
WA |
12 ms |
3072 KB |
058.txt |
WA |
12 ms |
3072 KB |
059.txt |
WA |
12 ms |
3072 KB |
060.txt |
WA |
14 ms |
3200 KB |
061.txt |
WA |
37 ms |
4096 KB |
062.txt |
AC |
55 ms |
4096 KB |
063.txt |
WA |
54 ms |
4096 KB |
example0.txt |
AC |
2 ms |
2304 KB |
example1.txt |
AC |
2 ms |
2304 KB |