# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1068467 |
2024-08-21T10:03:12 Z |
beaconmc |
Sails (IOI07_sails) |
C++14 |
|
1000 ms |
9980 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
const ll maxn = 200005;
ll tree[maxn*4];
ll lazy[maxn*4];
ll calc(ll k, ll x, ll y){
return tree[k] + lazy[k] * (y-x+1);
}
void push(ll k, ll x, ll y){
lazy[k*2] += lazy[k];
lazy[k*2+1] += lazy[k];
tree[k] += lazy[k] * (y-x+1);
lazy[k] = 0;
}
void update(ll a, ll b, ll val, ll k=1, ll x=0, ll y = maxn-1){
if (y<a || x>b) return;
if (a<=x && y<=b){
lazy[k] += val;
return;
}
push(k,x,y);
ll mid = (x+y)/2;
update(a, b, val, k*2, x, mid);
update(a, b, val, k*2+1, mid+1, y);
tree[k] = calc(k*2, x, mid) + calc(k*2+1, mid+1, y);
}
ll query(ll a, ll b, ll k=1, ll x=0, ll y=maxn-1){
if (y<a || x>b) return 0;
if (a<=x && y<=b){
return calc(k,x,y);
}
push(k,x,y);
ll mid = (x+y)/2;
return query(a,b,k*2,x,mid) + query(a,b,k*2+1,mid+1,y);
}
int main(){
ll n;
cin >> n;
vector<vector<ll>> stuff;
FOR(i,0,n){
ll h,k;
cin >> h >> k;
stuff.push_back({h,k});
}
sort(stuff.begin(), stuff.end());
for (auto&i : stuff){
ll num = i[1];
num--;
ll pos = n-i[0];
ll val = query(pos+num, pos+num);
ll lo = pos, hi = n-1;
while (lo < hi){
ll mid = (lo+hi+1)/2;
ll temp = query(mid, mid);
if (temp <= val) lo = mid;
else hi = mid-1;
}
ll lasts = lo;
lo = pos, hi = n;
while (lo < hi){
ll mid = (lo+hi)/2;
ll temp = query(mid, mid);
if (temp >= val) hi = mid;
else lo = mid+1;
}
ll firsts = lo;
update(pos, firsts-1, 1);
ll overlap = pos+num - firsts;
update(lasts-overlap, lasts, 1);
}
ll ans = 0;
FOR(i,0,n){
ll temp = query(i,i);
ans += temp * (temp-1)/2;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1071 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
5384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
241 ms |
5124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
7696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
526 ms |
9216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
620 ms |
9980 KB |
Output is correct |
2 |
Correct |
401 ms |
9932 KB |
Output is correct |