# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
519721 |
2022-01-27T07:05:31 Z |
XII |
Sails (IOI07_sails) |
C++17 |
|
193 ms |
3776 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(P, P, 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 |
1 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 |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 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 |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
1972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
138 ms |
2884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
3396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
3776 KB |
Output is correct |
2 |
Correct |
147 ms |
2556 KB |
Output is correct |