Skip to content

Instantly share code, notes, and snippets.

@samyravitoria
Last active May 1, 2019 18:16
Show Gist options
  • Save samyravitoria/fe81b84beb670f8a03180fc50c1c9a07 to your computer and use it in GitHub Desktop.
Save samyravitoria/fe81b84beb670f8a03180fc50c1c9a07 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10, mod = 1e9+7;
int n, m, bit[maxn], quantidade[maxn];
struct point{
int x, y;
bool operator<(const point& o) const{
if(x != o.x) return x < o.x;
return y < o.y;
}
} p[maxn];
void add(int i, int v){
while(i)
{
bit[i] = (bit[i]%mod + v)%mod;
i-=(i&-i);
}
}
int sum(int i)
{
int soma = 0;
for(; i <= m ; i += (i&-i))
{
soma = (soma%mod +bit[i])%mod;
}
return soma;
}
int main()
{
cin >> n;
for(int i = 1 ; i <= n ; ++i)
{
cin >> p[i].x >> p[i].y;
m = max(m, p[i].y);
}
sort(p + 1, p + n + 1);
int resp = 0;
for(int i = 1 ; i <= n ; ++i)
{
quantidade[i] = (sum(p[i].y + 1)%mod + 1)%mod;
add(p[i].y, quantidade[i]);
resp = (resp%mod + quantidade[i])%mod;
}
cout << resp << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment