记录编号 598167 评测结果 AAAAAAAAAAAA
题目名称 [USACO20 Feb Gold]Help Yourself(Gold) 最终得分 100
用户昵称 Gravatarflyfree 是否通过 通过
代码语言 C++ 运行时间 0.306 s
提交时间 2025-01-18 14:44:03 内存使用 4.92 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200010
#define mod 1000000007
// By flyfreemrn
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
inline void write(ll x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
struct node_bit{
	ll s[MAXN],siz;
	ll lowbit(ll x){
		return x&(-x);
	}
	void add(ll pos,ll val){
		while(pos<=siz){
			s[pos]+=val;
			pos+=lowbit(pos);
		}
	}
	ll find(ll pos){
		ll res=0;
		while(pos>0){
			res+=s[pos];
			pos-=lowbit(pos);
		}
		return res;
	}
}bit;
ll n;
ll f[MAXN];
struct node_line{
	ll l,r;
}line[MAXN];
bool cmp(node_line a,node_line b){
	return a.l<b.l;
}
ll fpow(ll bas,ll ex){
	ll res=1;
	while(ex>0){
		if(ex&1)res=res*bas%mod;
		bas=bas*bas%mod;
		ex>>=1;
	}
	return res;
}
int main(){
	freopen("usaco_Feb_help.in","r",stdin);
	freopen("usaco_Feb_help.out","w",stdout);
	n=read();
	bit.siz=2*n;
	for(int i=1;i<=n;i++)line[i].l=read(),line[i].r=read();
	sort(line+1,line+1+n,cmp);
	for(int i=1;i<=n;i++){
		f[i]=(2*f[i-1]+fpow(2,bit.find(line[i].l-1)))%mod;
		bit.add(line[i].r,1);
//		cout<<i<<" "<<f[i]<<endl;
	}
	cout<<f[n];
	return 0;
}