# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
587023 |
2022-07-01T08:15:18 Z |
Do_you_copy |
Sails (IOI07_sails) |
C++14 |
|
82 ms |
2892 KB |
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
const ll Mod = 1000000007;
const int maxN = 1e5 + 1;
int n;
pii a[maxN];
ll bit[maxN];
void update(int x, int val){
for (int i = x; i < maxN; i += (i & -i)){
bit[i] += val;
}
}
ll get(int x){
ll tem = 0;
for (int i = x; i > 0; i -= (i & -i)){
tem += bit[i];
}
return tem;
}
int find_left(int x, int val){
int l = 1, r = x;
while (l <= r){
int m = (l + r) / 2;
int tem = get(m);
if (val != tem) l = m + 1;
else r = m - 1;
}
return r + 1;
}
int find_right(int l, int val, int r){
while (l <= r){
int m = (l + r) / 2;
int tem = get(m);
if (val != tem) r = m - 1;
else l = m + 1;
}
return r;
}
void Init(){
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1,[](const auto &i, const auto &j){
return i.fi < j.fi;
});
for (int i = 1; i <= n; ++i){
int x = a[i].fi - a[i].se + 1;
int val = get(x);
int l = find_left(x, val);
int r = find_right(x, val, a[i].fi);
if (r != a[i].fi){
update(r + 1, 1);
update(a[i].fi + 1, -1);
}
update(l, 1);
update(l + a[i].se - (a[i].fi - r), -1);
}
ll ans = 0;
for (int i = 1; i < maxN; ++i){
ll x = get(i);
ans += x * (x - 1) / 2;
}
cout << ans << "\n";
}
int main(){
if (fopen(taskname".txt", "r")){
freopen(taskname".txt", "r", stdin);
}
faster
//freopen(taskname.inp, "r", stdin)
//freopen(taskname.out, "w", stdout)
Init();
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(taskname".txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
1172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
724 KB |
Output is correct |
2 |
Correct |
20 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
2540 KB |
Output is correct |
2 |
Correct |
57 ms |
2476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
2780 KB |
Output is correct |
2 |
Correct |
42 ms |
2324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
2892 KB |
Output is correct |
2 |
Correct |
55 ms |
2272 KB |
Output is correct |