Submission #493944

#TimeUsernameProblemLanguageResultExecution timeMemory
493944trumchepcodeBoat (APIO16_boat)C++14
9 / 100
512 ms524292 KiB
#include <bits/stdc++.h> using namespace std; const int N=501; const int mod=1e9+7; int n; long long a[N],b[N],st[4*N+1]; void update(int id,int l,int r,int x,int val) { if(l>r||r<x||l>x) return ; if(l==x&&r==x) { st[id]=val; return ; } int mid=(l+r)/2; if(mid>=x) update(id*2,l,mid,x,val); else update(id*2+1,mid+1,r,x,val); st[id]=(st[id*2+1]+st[id*2])%mod; } long long get(int id,int l,int r,int u,int v) { if(l>r||u>v||r<u||l>v) return 0; if(l>=u&&v>=r) return st[id]; int mid=(l+r)/2; return (get(id*2,l,mid,u,v)%mod+get(id*2+1,mid+1,r,u,v)%mod)%mod; } vector<int>v; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("dut03teams.inp","r",stdin); // freopen("dut03teams.out","w",stdout); cin >> n; for(int i=1;i<=n;i++) { cin >> a[i] >> b[i]; for(int j=a[i];j<=b[i];j++) { v.push_back(j); } } sort(v.begin(),v.end()); int id=1; map<int,int>mp; for(int i=0;i<v.size();i++) { if(i==0||v[i]!=v[i-1]) { mp[v[i]]=id++; } } for(int i=1;i<=n;i++) { a[i]=mp[a[i]]; b[i]=mp[b[i]]; } vector<long long>dp(id+1,0); dp[0]=1; update(1,0,n,0,1); for(int i=1;i<=n;i++) { for(int j=b[i];j>=a[i];j--) { dp[j]=(dp[j]+get(1,0,n,0,j-1))%mod; update(1,0,n,j,dp[j]); } } long long ans=0; for(int i=1;i<id;i++) { ans=(ans+dp[i])%mod; } cout << ans; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...