# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
963741 |
2024-04-15T15:08:49 Z |
Icelast |
Sails (IOI07_sails) |
C++17 |
|
1000 ms |
3756 KB |
#include <iostream>
#include <bits/stdc++.h>
#define ll int
using namespace std;
const ll maxn = 1e5+5, INF = 4e18+9;
ll n;
struct mast{
ll h, k;
};
mast a[maxn];
bool cmp(mast a, mast b){
return a.h < b.h;
}
void inp(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].h >> a[i].k;
}
}
ll N, T[4*maxn], lz[4*maxn];
void build_segtree(){
N = 1;
while(N < 1e5){
N*=2;
}
}
void down(int node, int len){
for(int child = node*2; child <= node*2+1; child++){
if(child >= 2*N) continue;
lz[child] += lz[node];
}
T[node]+=lz[node]*len;
lz[node] = 0;
}
void upd(int node, int low, int high, int l, int r, ll x){
if(r < l) return;
down(node, high-low+1);
if(low > r || l > high){
return;
}
if(low >= l && r >= high){
lz[node] += x;
down(node, high-low+1);
return;
}
int mid = (low+high)/2;
upd(node*2, low, mid, l, r, x);
upd(node*2+1, mid+1, high, l, r, x);
T[node] = T[node*2]+T[node*2+1];
}
ll get_sum(int node, int low, int high, int l, int r){
if(r < l) r = l;
down(node, high-low+1);
if(low > r || l > high){
return 0;
}
if(low >= l && r >= high){
return T[node];
}
int mid = (low+high)/2;
return get_sum(node*2, low, mid, l, r)+get_sum(node*2+1, mid+1, high, l, r);
}
int get_pos(ll k, ll M){
ll l = 1, r = M, mid;
while(l <= r){
mid = (l+r)/2;
if(get_sum(1, 1, N, mid, N)-get_sum(1, 1, N, mid+1, N) >= k){
l = mid+1;
}else{
r = mid-1;
}
}
return l-1;
}
void solve(){
sort(a+1, a+1+n, cmp);
build_segtree();
ll M, k;
for(int i = 1; i <= n; i++){
M = a[i].h; k = a[i].k;
ll x = get_sum(1, 1, N, M-k+1, M-k+1);
int u = get_pos(x, M);
int d = get_pos(x+1, M)+1;
upd(1, 1, N, u+1, M, 1);
upd(1, 1, N, d, d+u-(M-k+1), 1);
}
ll ans = 0;
for(int i = 1; i <= M; i++){
ll x = get_sum(1, 1, N, i, i);
ans += x*(x-1)/2;
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
inp();
solve();
}
Compilation message
sails.cpp:5:34: warning: overflow in conversion from 'double' to 'int' changes value from '4.0e+18' to '2147483647' [-Woverflow]
5 | const ll maxn = 1e5+5, INF = 4e18+9;
| ~~~~^~
sails.cpp: In function 'void solve()':
sails.cpp:90:22: warning: 'M' may be used uninitialized in this function [-Wmaybe-uninitialized]
90 | for(int i = 1; i <= M; i++){
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
80 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
265 ms |
2784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
542 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1002 ms |
3712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1018 ms |
3756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
3660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |