# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
519729 |
2022-01-27T07:42:35 Z |
XII |
Sails (IOI07_sails) |
C++17 |
|
183 ms |
3336 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "IOI07_sails"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 1e5 + 1;
int n;
using pi = pair<int, int>;
vector<pi> a;
ll bit[2][N];
void update(const int &t, int i, const ll &v){
while(i < N){
bit[t][i] += v;
i += i & -i;
}
}
ll getSum(const int &t, int i){
ll ans = 0;
while(1 <= i){
ans += bit[t][i];
i -= i & -i;
}
return ans;
}
void updRange(const int &i, const ll &v){
update(0, 1, v);
update(0, i + 1, -v);
update(1, i + 1, v * i);
}
void updRange(const int &l, const int &r, const ll &v){
updRange(l - 1, -v);
updRange(r, v);
}
ll query(const int &i){
return getSum(0, i) * i + getSum(1, i);
}
ll query(const int &l, const int &r){
return query(r) - query(l - 1);
}
int main(){
IOS;
Fi();
cin >> n; a.resize(n);
for(pi &x: a) cin >> x.fi >> x.se;
sort(ALL(a));
for(auto [H, K]: a){
int P = H - K + 1;
int l, r, A = P, B = P;
for(l = 2, r = P; l <= r; ){
int mid = (l + r) / 2;
if(query(mid, P) == 0){
A = mid - 1;
r = mid - 1;
} else l = mid + 1;
}
for(l = P + 1, r = H; l <= r; ){
int mid = (l + r) / 2;
if(query(P + 1, mid) == 0){
B = mid;
l = mid + 1;
} else r = mid - 1;
}
if(A == P){
updRange(A, A, 1);
updRange(H + 1, H + 1, -1);
} else{
updRange(B + 1, B + 1, 1);
updRange(H + 1, H + 1, -1);
updRange(A, A, 1);
updRange(B - P + A + 1, B - P + A + 1, -1);
}
}
ll ans = 0;
FORU(i, 1, a.back().fi){
ll tmp = query(i);
ans += tmp * (tmp - 1) / 2;
}
cout << ans;
return 0;
}
Compilation message
sails.cpp: In function 'void Fi()':
sails.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
844 KB |
Output is correct |
2 |
Correct |
44 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
1480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
2448 KB |
Output is correct |
2 |
Correct |
132 ms |
3336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
2572 KB |
Output is correct |
2 |
Correct |
115 ms |
3176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
2752 KB |
Output is correct |
2 |
Correct |
136 ms |
2640 KB |
Output is correct |