# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
347383 |
2021-01-12T18:14:19 Z |
Keshi |
Sails (IOI07_sails) |
C++17 |
|
1000 ms |
27444 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[rc].ar == seg[lc].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);*/
pll p = Mp(a[i].F - a[i].S, a[i].F - a[i].S + 1);
while(p.F > 0 && b[p.F - 1] == b[p.F]) p.F--;
while(p.S < a[i].F && b[p.S - 1] == b[p.S]) p.S++;
for(ll j = p.S; j < a[i].F; j++){
b[j]++;
}
for(ll j = p.F; j < p.F + (a[i].S + p.S - a[i].F); j++){
b[j]++;
}
}
ll ans = 0;
for(ll i = 0; i < maxn; i++){
ans += b[i] * (b[i] - 1) / 2;
}
cout << ans;//cal(1, 0, maxn);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25452 KB |
Output is correct |
2 |
Correct |
15 ms |
25452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25452 KB |
Output is correct |
2 |
Correct |
16 ms |
25452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25452 KB |
Output is correct |
2 |
Correct |
16 ms |
25452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
25452 KB |
Output is correct |
2 |
Correct |
16 ms |
25452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
25452 KB |
Output is correct |
2 |
Correct |
32 ms |
26220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
25836 KB |
Output is correct |
2 |
Correct |
83 ms |
26220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
26092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
614 ms |
26732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
27372 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1048 ms |
27328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
27444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |