Submission #3679521
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=2e5+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 |
1750 Byte |
Status |
WA |
Exec Time |
171 ms |
Memory |
11264 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 |
147 ms |
10240 KB |
001.txt |
WA |
150 ms |
10240 KB |
002.txt |
WA |
150 ms |
10240 KB |
003.txt |
WA |
151 ms |
10240 KB |
004.txt |
WA |
154 ms |
10240 KB |
005.txt |
WA |
155 ms |
10240 KB |
006.txt |
WA |
157 ms |
10240 KB |
007.txt |
WA |
158 ms |
10240 KB |
008.txt |
WA |
158 ms |
10240 KB |
009.txt |
WA |
159 ms |
10240 KB |
010.txt |
WA |
159 ms |
10240 KB |
011.txt |
WA |
160 ms |
11136 KB |
012.txt |
WA |
162 ms |
11136 KB |
013.txt |
WA |
162 ms |
11136 KB |
014.txt |
WA |
163 ms |
11136 KB |
015.txt |
WA |
164 ms |
11264 KB |
016.txt |
WA |
165 ms |
11136 KB |
017.txt |
WA |
166 ms |
11136 KB |
018.txt |
WA |
165 ms |
11264 KB |
019.txt |
WA |
166 ms |
11136 KB |
020.txt |
WA |
166 ms |
11264 KB |
021.txt |
WA |
15 ms |
6528 KB |
022.txt |
WA |
140 ms |
10112 KB |
023.txt |
WA |
68 ms |
7168 KB |
024.txt |
WA |
27 ms |
6784 KB |
025.txt |
WA |
89 ms |
7296 KB |
026.txt |
WA |
18 ms |
6528 KB |
027.txt |
WA |
114 ms |
9984 KB |
028.txt |
WA |
57 ms |
7168 KB |
029.txt |
WA |
55 ms |
7168 KB |
030.txt |
WA |
57 ms |
7168 KB |
031.txt |
WA |
118 ms |
9984 KB |
032.txt |
WA |
73 ms |
7296 KB |
033.txt |
WA |
74 ms |
9856 KB |
034.txt |
WA |
128 ms |
9984 KB |
035.txt |
WA |
23 ms |
6784 KB |
036.txt |
WA |
145 ms |
11136 KB |
037.txt |
WA |
114 ms |
9984 KB |
038.txt |
WA |
30 ms |
6784 KB |
039.txt |
WA |
85 ms |
9856 KB |
040.txt |
WA |
79 ms |
9728 KB |
041.txt |
WA |
146 ms |
11136 KB |
042.txt |
AC |
120 ms |
11264 KB |
043.txt |
AC |
129 ms |
11264 KB |
044.txt |
WA |
171 ms |
11136 KB |
045.txt |
AC |
2 ms |
6400 KB |
046.txt |
WA |
36 ms |
7168 KB |
047.txt |
WA |
170 ms |
11136 KB |
048.txt |
AC |
27 ms |
7168 KB |
049.txt |
WA |
34 ms |
7168 KB |
050.txt |
WA |
47 ms |
7168 KB |
051.txt |
WA |
72 ms |
7168 KB |
052.txt |
WA |
100 ms |
7168 KB |
053.txt |
WA |
130 ms |
7424 KB |
054.txt |
WA |
162 ms |
10240 KB |
055.txt |
AC |
24 ms |
7168 KB |
056.txt |
AC |
30 ms |
7168 KB |
057.txt |
WA |
45 ms |
7168 KB |
058.txt |
WA |
65 ms |
7168 KB |
059.txt |
WA |
95 ms |
7168 KB |
060.txt |
WA |
125 ms |
7424 KB |
061.txt |
WA |
154 ms |
10240 KB |
062.txt |
AC |
115 ms |
10240 KB |
063.txt |
AC |
104 ms |
10240 KB |
example0.txt |
AC |
2 ms |
6400 KB |
example1.txt |
AC |
2 ms |
6400 KB |