# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
141598 |
2019-08-08T13:40:22 Z |
stefdasca |
Sails (IOI07_sails) |
C++14 |
|
104 ms |
2296 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);
for(int i = 1; i <= n; ++i)
{
int r = v[i].h;
int val = compute(r - v[i].ct + 1);
int st = 1;
int dr = r - v[i].ct;
int pz = r - v[i].ct + 1;
while(st <= dr)
{
int mid = (st + dr) / 2;
if(compute(mid) == val)
pz = mid, dr = mid - 1;
else
st = mid + 1;
}
st = r - v[i].ct + 2;
dr = r;
int anss = st;
while(st <= dr)
{
int mid = (st + dr) / 2;
if(compute(mid) == val)
anss = mid + 1, st = mid + 1;
else
dr = mid - 1;
}
update(anss, 1);
update(r+1, -1);
v[i].ct -= (r - anss + 1);
update(pz, 1);
update(pz + v[i].ct, -1);
/*
for(int j = 1; j <= r; ++j)
cout << compute(j) << " ";
cout << '\n';
*/
}
for(int i = 1; i <= 100000; ++i)
ans += gauss(compute(i));
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
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 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
248 KB |
Output is correct |
# |
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 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
504 KB |
Output is correct |
2 |
Correct |
25 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
1608 KB |
Output is correct |
2 |
Correct |
72 ms |
2268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
1400 KB |
Output is correct |
2 |
Correct |
58 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
1536 KB |
Output is correct |
2 |
Correct |
68 ms |
2296 KB |
Output is correct |