# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
433758 |
2021-06-20T10:28:01 Z |
someone |
Boat (APIO16_boat) |
C++14 |
|
1 ms |
332 KB |
#include <bits/stdc++.h>
using namespace std;
struct Val {
int i, val;
};
struct Node {
int deb, fin, sum;
};
const int T = 9, M = 1 << T, N = 2*M;
Node node[N];
int a[N], b[N];
int getSum(int i) {
if(i == 1)
return 0;
int sum = getSum(i/2);
if(i % 2 == 1)
sum += node[i-1].sum;
return sum;
}
void add(int i, int val) {
if(i == 0)
return;
node[i].sum += val;
add(i/2, val);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i = 0; i < M; i++) {
node[i + M].deb = i;
node[i + M].fin = i + 1;
}
for(int i = M-1; i > -1; i--) {
node[i].deb = node[i*2].deb;
node[i].fin = node[i*2+1].fin;
}
int n;
cin >> n;
vector<Val> v;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
v.push_back({i, a[i]});
}
sort(v.begin(), v.end(),
[](Val v1, Val v2) {
return v1.val < v2.val;
});
int pre = v[0].val;
v[0].val = 1;
for(int i = 1; i < n; i++) {
bool eq = (pre != v[i].val);
pre = v[i].val;
v[i].val = v[i-1].val + eq;
}
sort(v.begin(), v.end(),
[](Val v1, Val v2) {
return v1.i < v2.i;
});
int sum = 0;
for(int i = 0; i < n; i++) {
int val = getSum(v[i].val + M);
val++;
sum += val;
add(v[i].val + M, val);
}
cout << sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |