This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
ll res = 1;
x = x; // % mod;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1) res = (res*x) ; // % mod;
y = y>>1;
x = (x*x) ; // % mod;
}
return res;
}
ll k = 1;
const int logn = 20;
ll seg[N*logn+N];
ll L[N*logn+N], R[N*logn+N];
ll a[N], b[N];
ll n,siz = 1;
void upd(ll node, ll in , ll val , ll lx = 0, ll rx = siz)
{
if(rx-lx==1) {seg[node] += val; return;}
ll mid = (lx+rx)/2;
if(L[node]==0) L[node] = k++, R[node] = k++;
if(in<mid) upd(L[node],in,val,lx,mid);
else upd(R[node],in,val,mid,rx);
seg[node] = seg[L[node]]+seg[R[node]];
}
ll get(ll node, ll l , ll r, ll lx = 0, ll rx = siz)
{
if(lx>=r||rx<=l) return 0;
if(lx>=l&&rx<=r) return seg[node];
ll mid = (lx+rx)/2;
if(L[node]==0) L[node] = k++, R[node] = k++;
return get(L[node],l,r,lx,mid) + get(R[node],l,r,mid,rx);
}
void solve()
{
cin >> n;
siz = 1e9;
for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
upd(0,0,1);
for(int i = 1; i <= n; i++)
{
for(int j = b[i]; j >= a[i]; j--)
{
ll ans = get(0,0,j);
upd(0,j,ans);
}
}
cout << get(0,0,siz)-1 << endl;
}
int main(){
//freopen("friday.in","r",stdin);
//freopen("friday.out","w",stdout);
fast;
while(TT--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |