# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
400524 |
2021-05-08T09:02:15 Z |
A_D |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
336872 KB |
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=1e3+1;
const int M=1e6+100;
const int MOD=1e9+7;
int a[N];
int b[N];
map<int,int> mp;
set<int> st;
int seg[4*M];
void update(int p,int s,int e,int i,int v)
{
if(s==e){
seg[p]+=v;
seg[p]%=MOD;
return;
}
int mid=(s+e)/2;
if(i<=mid){
update(p*2,s,mid,i,v);
}
else{
update(p*2+1,mid+1,e,i,v);
}
seg[p]=(seg[p*2]+seg[p*2+1])%MOD;
}
int get(int p,int s,int e,int a,int b)
{
if(a<=s&&e<=b){
return seg[p];
}
if(s>b||e<a){
return 0;
}
int mid=(s+e)/2;
return (get(p*2,s,mid,a,b)+get(p*2+1,mid+1,e,a,b))%MOD;
}
void solve()
{
int n,ans=0,mn=1e9;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
for(int j=a[i];j<=b[i];j++){
st.insert(j);
}
}
int cnt=2;
for(auto x:st)mp[x]=cnt++;
for(int i=1;i<=n;i++){
for(int j=b[i];j>=a[i];j--){
int v=get(1,1,M,1,j-1)+1;
ans+=v;
ans%=MOD;
update(1,1,M,j,v);
}
}
cout<<ans<<endl;
}
main()
{
int t=1;
// cin>>t;
while(t--)solve();
}
Compilation message
boat.cpp: In function 'void solve()':
boat.cpp:45:17: warning: unused variable 'mn' [-Wunused-variable]
45 | int n,ans=0,mn=1e9;
| ^~
boat.cpp: At global scope:
boat.cpp:65:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
65 | main()
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2092 ms |
336872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |