Submission #946360

#TimeUsernameProblemLanguageResultExecution timeMemory
946360simona1230Boat (APIO16_boat)C++17
9 / 100
178 ms8796 KiB
#include <bits/stdc++.h> using namespace std; long long n; struct school { int first,second,i; school(){} school(int _l,int _r,int _i) { first=_l; second=_r; i=_i; } }; school p[200001]; school a[200001]; bool cmp(school s1,school s2) { return s1.first<=s2.first; } bool cmp2(school s1,school s2) { return s1.i<s2.i; } int lim; void read() { cin>>n; for(long long i=1;i<=n;i++) { int x,y; cin>>x>>y; p[i]={x,y,i}; } sort(p+1,p+n+1,cmp); long long last=0; for(long long i=1;i<=n;i++) { a[i].i=p[i].i; long long len=p[i].second-p[i].first; a[i].first=a[i-1].second+1; if(p[i-1].second>=p[i].first) { long long same=p[i-1].second-p[i].first; a[i].first=a[i-1].second-same; } a[i].second=a[i].first+len; //cout<<a[i].first<<" "<<a[i].second<<endl; } lim=a[n].second; sort(a+1,a+n+1,cmp2); } const long long mod=1e9+7; long long t[4000001]; long long query(long long i,long long l,long long r,long long ql,long long qr) { if(ql>qr)return 0; if(l>=ql&&r<=qr) { //cout<<i<<" "<<l<<" "<<r<<" "<<t[i]<<" query"<<endl; return t[i]; } long long m=(l+r)/2; return (query(i*2,l,m,ql,min(qr,m))+query(i*2+1,m+1,r,max(ql,m+1),qr))%mod; } void update(long long i,long long l,long long r,long long idx,long long val) { if(l==r) { t[i]+=val; t[i]%=mod; return; } long long m=(l+r)/2; if(m>=idx)update(i*2,l,m,idx,val); else update(i*2+1,m+1,r,idx,val); t[i]=t[i*2]+t[i*2+1]; t[i]%=mod; //cout<<i<<" "<<l<<" "<<r<<" "<<t[i]<<endl; } void solve() { update(1,0,lim,0,1); for(long long i=1;i<=n;i++) { //cout<<a[i].first<<" "<<a[i].second<<endl; for(long long j=a[i].second;j>=a[i].first;j--) { long long help=query(1,0,lim,0,j-1); //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; update(1,0,lim,j,help); } } int fin=query(1,0,lim,1,lim); cout<<fin<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); solve(); return 0; } /* 3 4 10 7 15 1 4 */

Compilation message (stderr)

boat.cpp: In function 'void read()':
boat.cpp:34:19: warning: narrowing conversion of 'i' from 'long long int' to 'int' [-Wnarrowing]
   34 |         p[i]={x,y,i};
      |                   ^
boat.cpp:38:15: warning: unused variable 'last' [-Wunused-variable]
   38 |     long long last=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...