# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631365 |
2022-08-18T03:47:34 Z |
Spade1 |
Sails (IOI07_sails) |
C++14 |
|
96 ms |
1860 KB |
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;
const int N = 1e5 + 10;
pii s[N];
ll fw[N];
ll get(int i) {
ll ret = 0;
for (; i > 0; i -= i&-i) {
ret += fw[i];
}
return ret;
}
void add(int i, int val) {
for (; i < N; i += i&-i) {
fw[i] += val;
}
}
int findl(int x) {
int l = 1, r = x;
ll target = get(x);
while (l < r) {
int mid = (l+r)/2;
if (get(mid) == target) r = mid;
else l = mid + 1;
}
return l;
}
int findr(int x, int fr) {
int l = x, r = fr;
ll target = get(x);
while (l < r) {
int mid = ceil(1.0*(l+r)/2);
if (get(mid) == target) l = mid;
else r = mid - 1;
}
return l;
}
void solve() {
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i].st >> s[i].nd;
}
sort(s+1, s+n+1);
for (int i = 1; i <= n; ++i) {
int l = s[i].st - s[i].nd + 1, r = s[i].st;
int lb = findl(l);
int rb = findr(l, r);
if (l == lb) {
add(l, 1);
add(r+1, -1);
}
else {
add(rb+1, 1);
add(r+1, -1);
add(lb, 1);
add(lb + (s[i].nd - (r - rb)), -1);
}
}
ll sum = 0;
for (int i = 1; i <= n; ++i) {
ll cur = get(i);
sum += cur*(cur-1)/2;
}
cout << sum << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
1636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
1760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
1860 KB |
Output is correct |
2 |
Correct |
59 ms |
1320 KB |
Output is correct |