Submission #68571

#TimeUsernameProblemLanguageResultExecution timeMemory
68571KLPPBoat (APIO16_boat)C++14
31 / 100
2073 ms525312 KiB
#include<iostream> #include<stdio.h> #include<vector> using namespace std; typedef long long int lld; #define MOD 1000000007 struct node{ int l,r; lld val; node *left,*right; }; void build(node *n,int l, int r){ n->val=0; n->l=l; n->r=r; } void extend(node *n){ if(n->left!=NULL)return; int mid=(n->l+n->r)/2; n->left=new node(); n->right=new node(); build(n->left,n->l,mid); build(n->right,mid+1,n->r); } void update(int pos, lld val,node *n){ if(pos<n->l || pos>n->r)return; n->val+=val; n->val%=MOD; if(n->l!=n->r){ extend(n); update(pos,val,n->left); update(pos,val,n->right); } } lld prefixo(int index, node *n){ if(n->r<=index)return n->val; if(n->l>index || n->val==0) return 0; lld ans=prefixo(index,n->left); ans+=prefixo(index,n->right); return ans%MOD; } int main(){ int n; cin>>n; pair<lld,lld> arr[n]; for(int i=0;i<n;i++)cin>>arr[i].first>>arr[i].second; vector<lld> DP[n]; lld responde=0; node *segtree=new node(); build(segtree,1,1000000000); for(int i=0;i<n;i++){ for(int j=arr[i].first;j<=arr[i].second;j++){ DP[i].push_back((prefixo(j-1,segtree)+1)%MOD); } for(int j=arr[i].first;j<=arr[i].second;j++){ update(j,DP[i][j-arr[i].first],segtree); } } /*for(int i=0;i<n;i++){ for(int j=arr[i].first;j<=arr[i].second;j++){ cout<<DP[i][j-arr[i].first]<<" "; }cout<<endl; }*/ for(int i=0;i<n;i++){ for(int j=arr[i].first;j<=arr[i].second;j++){ responde+=DP[i][j-arr[i].first]; responde%=MOD; } } cout<<responde<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...