Submission #946365

#TimeUsernameProblemLanguageResultExecution timeMemory
946365simona1230Boat (APIO16_boat)C++17
9 / 100
181 ms4696 KiB
#include <bits/stdc++.h> using namespace std; long long n; struct school { long long first,second,i; school(){} school(long long _l,long long _r,long long _i) { first=_l; second=_r; i=_i; } }; school p[512]; school a[512]; bool cmp(school s1,school s2) { return s1.first<=s2.first; } bool cmp2(school s1,school s2) { return s1.i<s2.i; } long long lim; void read() { cin>>n; for(long long i=1;i<=n;i++) { long long 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; lim=max(lim,a[i].second); //cout<<a[i].first<<" "<<a[i].second<<endl; } sort(a+1,a+n+1,cmp2); } const long long mod=1e9+7; long long t[5000001]; 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<<" "<<help<<endl; update(1,0,lim,j,help); } } long long 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 2 1 10 5 5 */

Compilation message (stderr)

boat.cpp: In function 'void read()':
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...