| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 30067 | gs14004 | Untitled (POI11_rot) | C++14 | 169 ms | 8408 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;
const int MAXN = 200005;
int a[MAXN], n, cnt;
struct bit{
int tree[MAXN];
void add(int x, int v){
while(x <= n){
tree[x] += v;
x += x & -x;
}
}
int query(int x){
int ret = 0;
while(x) ret += tree[x], x -= x & -x;
return ret;
}
}bit;
lint solve(int s, int m, int e){
lint ans = 0;
if(e - m > m - s){
for(int j=s; j<m; j++) bit.add(a[j], -1);
for(int j=s; j<m; j++) ans += bit.query(a[j] - 1);
for(int j=s; j<m; j++) bit.add(a[j], 1);
}
else{
for(int j=m; j<e; j++) bit.add(a[j], -1);
for(int j=m; j<e; j++) ans += m - s - bit.query(a[j]);
for(int j=m; j<e; j++) bit.add(a[j], 1);
}
return ans;
}
lint solve(){
int x;
scanf("%d",&x);
lint ans = 0;
if(x == 0){
int s = cnt;
ans += solve();
int m = cnt;
ans += solve();
int e = cnt;
lint tmp = solve(s, m, e);
ans += min(tmp, 1ll * (e - m) * (m - s) - tmp);
}
else{
bit.add(x, 1);
a[cnt++] = x;
}
return ans;
}
int main(){
scanf("%d",&n);
printf("%lld\n", solve());
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
