# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
141589 |
2019-08-08T13:17:28 Z |
stefdasca |
Sails (IOI07_sails) |
C++14 |
|
104 ms |
2680 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
using namespace std;
typedef long long ll;
struct hei
{
int h, ct;
};
hei v[100002];
bool cmp(hei a, hei b)
{
if(a.h == b.h)
return a.ct > b.ct;
return a.h > b.h;
}
int n, aib[100002];
ll ans = 0;
void update(int nod, int val)
{
for(; nod <= 100000; nod += (nod & (-nod)))
aib[nod] += val;
}
int compute(int nod)
{
int ans = 0;
for(; nod; nod -= (nod & (-nod)))
ans += aib[nod];
return ans;
}
ll gauss(int n)
{
return 1LL * n * (n-1) / 2;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> v[i].h >> v[i].ct;
sort(v+1, v+n+1, cmp);
int r = 100000;
for(int i = 1; i <= n; ++i)
{
while(v[i].h < r)
ans += gauss(compute(r)), --r;
int val = compute(v[i].ct);
int st = v[i].ct + 1;
int dr = r;
int lst = v[i].ct;
while(st <= dr)
{
int mid = (st + dr) / 2;
if(compute(mid) == val)
lst = mid, st = mid + 1;
else
dr = mid - 1;
}
int fi = v[i].ct - 1;
st = 1;
dr = v[i].ct - 1;
while(st <= dr)
{
int mid = (st + dr) / 2;
if(compute(mid) == val)
fi = mid - 1, dr = mid - 1;
else
st = mid + 1;
}
update(1, 1);
update(fi + 1, -1);
v[i].ct -= fi;
update(lst + 1, -1);
update(lst - v[i].ct + 1, 1);
}
while(r)
ans += gauss(compute(r)), --r;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
1016 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
1464 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
2168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
88 ms |
2524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |