#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int mod=1e9+7;
ii Seg[505];
int n,Count=0,res=0,a[505],b[505],f[505],c[1000005],tree[1000005];
int64_t sum=0;
vector<ii> V;
void Sub1()
{
for(int i=1; i<=n; i++)
{
f[i]=1;
for(int j=1; j<i; j++)
if(a[j]<a[i])
f[i]=(f[i]+f[j])%mod;
res=(res+f[i])%mod;
}
cout<<res;
}
void Update(int idx,int data)
{
while(idx<=sum)
{
tree[idx]=(tree[idx]+data)%mod;
idx+=idx&-idx;
}
}
int Query(int idx)
{
int rs=0;
while(idx>0)
{
rs=(rs+tree[idx])%mod;
idx-=idx&-idx;
}
return rs;
}
void Sub2()
{
int Count=0;
for(int i=1; i<=n; i++)
for(int j=b[i];j>=a[i];j--)
V.push_back(ii(j,++Count));
sort(V.begin(),V.end());
c[V[0].second]=1;
Count=1;
for(int i=1;i<V.size();i++)
if(V[i].first>V[i-1].first)
c[V[i].second]=++Count;
else
c[V[i].second]=Count;
for(int i=1; i<=sum; i++)
{
int tmp=(Query(c[i]-1)+1)%mod;
Update(c[i],tmp);
res=(res+tmp)%mod;
}
cout<<res;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("BOAT.INP","r",stdin);
cin>>n;
bool check=false;
for(int i=1; i<=n; i++)
{
cin>>a[i]>>b[i];
if(a[i]!=b[i])
check=true;
sum+=b[i]-a[i]+1;
}
if(check==false)
Sub1();
else if(sum<=1e6)
Sub2();
}
Compilation message
boat.cpp: In function 'void Sub2()':
boat.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<V.size();i++)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10000 KB |
Output is correct |
2 |
Correct |
0 ms |
10000 KB |
Output is correct |
3 |
Correct |
0 ms |
10000 KB |
Output is correct |
4 |
Correct |
0 ms |
10000 KB |
Output is correct |
5 |
Correct |
0 ms |
10000 KB |
Output is correct |
6 |
Correct |
0 ms |
10000 KB |
Output is correct |
7 |
Correct |
0 ms |
10000 KB |
Output is correct |
8 |
Correct |
0 ms |
10000 KB |
Output is correct |
9 |
Correct |
0 ms |
10000 KB |
Output is correct |
10 |
Correct |
0 ms |
10000 KB |
Output is correct |
11 |
Correct |
0 ms |
10000 KB |
Output is correct |
12 |
Correct |
0 ms |
10000 KB |
Output is correct |
13 |
Correct |
0 ms |
10000 KB |
Output is correct |
14 |
Correct |
0 ms |
10000 KB |
Output is correct |
15 |
Correct |
0 ms |
10000 KB |
Output is correct |
16 |
Correct |
0 ms |
10000 KB |
Output is correct |
17 |
Correct |
0 ms |
10000 KB |
Output is correct |
18 |
Correct |
0 ms |
10000 KB |
Output is correct |
19 |
Correct |
0 ms |
10000 KB |
Output is correct |
20 |
Correct |
0 ms |
10000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10000 KB |
Output is correct |
2 |
Correct |
0 ms |
10000 KB |
Output is correct |
3 |
Correct |
0 ms |
10000 KB |
Output is correct |
4 |
Correct |
0 ms |
10000 KB |
Output is correct |
5 |
Correct |
0 ms |
10000 KB |
Output is correct |
6 |
Correct |
0 ms |
10000 KB |
Output is correct |
7 |
Correct |
0 ms |
10000 KB |
Output is correct |
8 |
Correct |
0 ms |
10000 KB |
Output is correct |
9 |
Correct |
0 ms |
10000 KB |
Output is correct |
10 |
Correct |
0 ms |
10000 KB |
Output is correct |
11 |
Correct |
0 ms |
10000 KB |
Output is correct |
12 |
Correct |
0 ms |
10000 KB |
Output is correct |
13 |
Correct |
0 ms |
10000 KB |
Output is correct |
14 |
Correct |
0 ms |
10000 KB |
Output is correct |
15 |
Correct |
0 ms |
10000 KB |
Output is correct |
16 |
Correct |
0 ms |
10000 KB |
Output is correct |
17 |
Correct |
0 ms |
10000 KB |
Output is correct |
18 |
Correct |
0 ms |
10000 KB |
Output is correct |
19 |
Correct |
0 ms |
10000 KB |
Output is correct |
20 |
Correct |
0 ms |
10000 KB |
Output is correct |
21 |
Correct |
196 ms |
22328 KB |
Output is correct |
22 |
Correct |
196 ms |
22328 KB |
Output is correct |
23 |
Correct |
186 ms |
22328 KB |
Output is correct |
24 |
Correct |
189 ms |
22328 KB |
Output is correct |
25 |
Correct |
199 ms |
22328 KB |
Output is correct |
26 |
Correct |
209 ms |
22328 KB |
Output is correct |
27 |
Correct |
209 ms |
22328 KB |
Output is correct |
28 |
Correct |
209 ms |
22328 KB |
Output is correct |
29 |
Correct |
216 ms |
22328 KB |
Output is correct |
30 |
Correct |
209 ms |
22328 KB |
Output is correct |
31 |
Correct |
183 ms |
22328 KB |
Output is correct |
32 |
Correct |
186 ms |
22328 KB |
Output is correct |
33 |
Correct |
179 ms |
22328 KB |
Output is correct |
34 |
Correct |
193 ms |
22328 KB |
Output is correct |
35 |
Correct |
156 ms |
22328 KB |
Output is correct |
36 |
Correct |
163 ms |
22328 KB |
Output is correct |
37 |
Correct |
159 ms |
22328 KB |
Output is correct |
38 |
Correct |
149 ms |
22328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
10000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10000 KB |
Output is correct |
2 |
Correct |
0 ms |
10000 KB |
Output is correct |
3 |
Correct |
0 ms |
10000 KB |
Output is correct |
4 |
Correct |
0 ms |
10000 KB |
Output is correct |
5 |
Correct |
0 ms |
10000 KB |
Output is correct |
6 |
Correct |
0 ms |
10000 KB |
Output is correct |
7 |
Correct |
0 ms |
10000 KB |
Output is correct |
8 |
Correct |
0 ms |
10000 KB |
Output is correct |
9 |
Correct |
0 ms |
10000 KB |
Output is correct |
10 |
Correct |
0 ms |
10000 KB |
Output is correct |
11 |
Correct |
0 ms |
10000 KB |
Output is correct |
12 |
Correct |
0 ms |
10000 KB |
Output is correct |
13 |
Correct |
0 ms |
10000 KB |
Output is correct |
14 |
Correct |
0 ms |
10000 KB |
Output is correct |
15 |
Correct |
0 ms |
10000 KB |
Output is correct |
16 |
Correct |
0 ms |
10000 KB |
Output is correct |
17 |
Correct |
0 ms |
10000 KB |
Output is correct |
18 |
Correct |
0 ms |
10000 KB |
Output is correct |
19 |
Correct |
0 ms |
10000 KB |
Output is correct |
20 |
Correct |
0 ms |
10000 KB |
Output is correct |
21 |
Correct |
196 ms |
22328 KB |
Output is correct |
22 |
Correct |
196 ms |
22328 KB |
Output is correct |
23 |
Correct |
186 ms |
22328 KB |
Output is correct |
24 |
Correct |
189 ms |
22328 KB |
Output is correct |
25 |
Correct |
199 ms |
22328 KB |
Output is correct |
26 |
Correct |
209 ms |
22328 KB |
Output is correct |
27 |
Correct |
209 ms |
22328 KB |
Output is correct |
28 |
Correct |
209 ms |
22328 KB |
Output is correct |
29 |
Correct |
216 ms |
22328 KB |
Output is correct |
30 |
Correct |
209 ms |
22328 KB |
Output is correct |
31 |
Correct |
183 ms |
22328 KB |
Output is correct |
32 |
Correct |
186 ms |
22328 KB |
Output is correct |
33 |
Correct |
179 ms |
22328 KB |
Output is correct |
34 |
Correct |
193 ms |
22328 KB |
Output is correct |
35 |
Correct |
156 ms |
22328 KB |
Output is correct |
36 |
Correct |
163 ms |
22328 KB |
Output is correct |
37 |
Correct |
159 ms |
22328 KB |
Output is correct |
38 |
Correct |
149 ms |
22328 KB |
Output is correct |
39 |
Incorrect |
0 ms |
10000 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |