# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
347384 |
2021-01-12T18:19:06 Z |
Keshi |
Sails (IOI07_sails) |
C++17 |
|
245 ms |
32108 KB |
//In the name of God
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define lc (id << 1)
#define rc (lc | 1)
struct node{
ll al, ar, sl, sr;
node(){
al = ar = sl = sr = 0;
}
};
ll n, lz[maxn << 2], b[maxn];
pll a[maxn];
node seg[maxn << 2];
void bld(ll id, ll s, ll e){
seg[id].sl = e;
seg[id].sr = s;
if(e - s == 1) return;
ll mid = (s + e) >> 1;
bld(lc, s, mid);
bld(rc, mid, e);
return;
}
void Do(ll id, ll x){
seg[id].al += x;
seg[id].ar += x;
lz[id] += x;
}
pll get(ll id, ll s, ll e, ll x){
if(e - s == 1){
return Mp(s, e);
}
ll mid = (s + e) >> 1;
Do(lc, lz[id]);
Do(rc, lz[id]);
lz[id] = 0;
if(x < mid){
pll p = get(lc, s, mid, x);
if(p.S == mid && seg[lc].ar == seg[rc].al){
p.S = seg[rc].sl;
}
return p;
}
pll p = get(rc, mid, e, x);
if(p.F == mid && seg[lc].ar == seg[rc].al){
p.F = seg[lc].sr;
}
return p;
}
void upd(ll id, ll s, ll e, ll l, ll r, ll x){
if(r <= s || e <= l) return;
if(l <= s && e <= r){
Do(id, x);
return;
}
ll mid = (s + e) >> 1;
Do(lc, lz[id]);
Do(rc, lz[id]);
lz[id] = 0;
upd(lc, s, mid, l, r, x);
upd(rc, mid, e, l, r, x);
seg[id].al = seg[lc].al;
seg[id].sl = seg[lc].sl;
seg[id].ar = seg[rc].ar;
seg[id].sr = seg[rc].sr;
if(seg[lc].ar == seg[rc].al){
if(seg[id].sl == mid) seg[id].sl = seg[rc].sl;
if(seg[id].sr == mid) seg[id].sr = seg[lc].sr;
}
return;
}
ll cal(ll id, ll s, ll e){
if(e - s == 1){
return seg[id].al * (seg[id].al - 1) / 2;
}
ll mid = (s + e) >> 1;
Do(lc, lz[id]);
Do(rc, lz[id]);
lz[id] = 0;
return cal(lc, s, mid) + cal(rc, mid, e);
}
int main(){
fast_io;
bld(1, 0, maxn);
cin >> n;
for(ll i = 0; i < n; i++){
cin >> a[i].F >> a[i].S;
}
sort(a, a + n);
for(ll i = 0; i < n; i++){
pll p = get(1, 0, maxn, a[i].F - a[i].S);
p.S = min(p.S, a[i].F);
upd(1, 0, maxn, p.S, a[i].F, 1);
upd(1, 0, maxn, p.F, p.F + (a[i].S + p.S - a[i].F), 1);
}
cout << cal(1, 0, maxn);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
29548 KB |
Output is correct |
2 |
Correct |
20 ms |
29548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
29548 KB |
Output is correct |
2 |
Correct |
20 ms |
29548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
29548 KB |
Output is correct |
2 |
Correct |
20 ms |
29548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
29548 KB |
Output is correct |
2 |
Correct |
21 ms |
29548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
29548 KB |
Output is correct |
2 |
Correct |
22 ms |
29548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
29676 KB |
Output is correct |
2 |
Correct |
63 ms |
29932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
29964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
30256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
30764 KB |
Output is correct |
2 |
Correct |
170 ms |
31596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
30956 KB |
Output is correct |
2 |
Correct |
120 ms |
31596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
31212 KB |
Output is correct |
2 |
Correct |
158 ms |
32108 KB |
Output is correct |