//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD=1000000007;
ll qexp(ll b,ll p,int m){
ll res=1;
while (p){
if (p&1) res=(res*b)%m;
b=(b*b)%m;
p>>=1;
}
return res;
}
ll inv(ll i){
return qexp(i,MOD-2,MOD);
}
int n;
ii range[505];
vector<int> pos={0,1};
ll cnt[1005][505];
ll memo[1005][505];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
rep(x,0,n){
cin>>range[x].fi>>range[x].se;
pos.push_back(range[x].fi);
pos.push_back(range[x].se+1);
}
sort(all(pos));
pos.erase(unique(all(pos)),pos.end());
rep(x,0,sz(pos)-1){
int val=pos[x+1]-pos[x];
cnt[x][0]=val;
rep(y,1,min(val,505)){
cnt[x][y]=cnt[x][y-1]*(val-y)%MOD*inv(y+1)%MOD;
}
}
//for (auto &it:pos) cout<<it<<" ";cout<<endl;
memo[0][0]=1;
ll curr;
rep(z,0,n){
curr=0;
rep(x,0,sz(pos)-1){
ll temp=curr;
rep(y,0,505) curr=(curr+cnt[x][y]*memo[x][y])%MOD;
if (range[z].fi<=pos[x] && pos[x]<=range[z].se){
rep(y,505,1) memo[x][y]=(memo[x][y]+memo[x][y-1])%MOD;
memo[x][0]=(memo[x][0]+temp)%MOD;
}
//cout<<curr<<endl;
}
/*
rep(x,0,sz(pos)-1){
rep(y,0,4) cout<<memo[x][y]<<" ";
cout<<endl;
}
cout<<endl;
//*/
}
curr=0;
rep(x,1,sz(pos)-1){
rep(y,0,505) curr=(curr+cnt[x][y]*memo[x][y])%MOD;
}
cout<<curr<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1205 ms |
8412 KB |
Output is correct |
2 |
Correct |
1203 ms |
8440 KB |
Output is correct |
3 |
Correct |
1209 ms |
8412 KB |
Output is correct |
4 |
Correct |
1211 ms |
8304 KB |
Output is correct |
5 |
Correct |
1199 ms |
8204 KB |
Output is correct |
6 |
Correct |
1224 ms |
8312 KB |
Output is correct |
7 |
Correct |
1212 ms |
8312 KB |
Output is correct |
8 |
Correct |
1202 ms |
8440 KB |
Output is correct |
9 |
Correct |
1206 ms |
8420 KB |
Output is correct |
10 |
Correct |
1201 ms |
8392 KB |
Output is correct |
11 |
Correct |
1199 ms |
8440 KB |
Output is correct |
12 |
Correct |
1228 ms |
8416 KB |
Output is correct |
13 |
Correct |
1207 ms |
8428 KB |
Output is correct |
14 |
Correct |
1215 ms |
8428 KB |
Output is correct |
15 |
Correct |
1212 ms |
8376 KB |
Output is correct |
16 |
Correct |
211 ms |
1812 KB |
Output is correct |
17 |
Correct |
228 ms |
1912 KB |
Output is correct |
18 |
Correct |
219 ms |
1792 KB |
Output is correct |
19 |
Correct |
233 ms |
1912 KB |
Output is correct |
20 |
Correct |
222 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1205 ms |
8412 KB |
Output is correct |
2 |
Correct |
1203 ms |
8440 KB |
Output is correct |
3 |
Correct |
1209 ms |
8412 KB |
Output is correct |
4 |
Correct |
1211 ms |
8304 KB |
Output is correct |
5 |
Correct |
1199 ms |
8204 KB |
Output is correct |
6 |
Correct |
1224 ms |
8312 KB |
Output is correct |
7 |
Correct |
1212 ms |
8312 KB |
Output is correct |
8 |
Correct |
1202 ms |
8440 KB |
Output is correct |
9 |
Correct |
1206 ms |
8420 KB |
Output is correct |
10 |
Correct |
1201 ms |
8392 KB |
Output is correct |
11 |
Correct |
1199 ms |
8440 KB |
Output is correct |
12 |
Correct |
1228 ms |
8416 KB |
Output is correct |
13 |
Correct |
1207 ms |
8428 KB |
Output is correct |
14 |
Correct |
1215 ms |
8428 KB |
Output is correct |
15 |
Correct |
1212 ms |
8376 KB |
Output is correct |
16 |
Correct |
211 ms |
1812 KB |
Output is correct |
17 |
Correct |
228 ms |
1912 KB |
Output is correct |
18 |
Correct |
219 ms |
1792 KB |
Output is correct |
19 |
Correct |
233 ms |
1912 KB |
Output is correct |
20 |
Correct |
222 ms |
1912 KB |
Output is correct |
21 |
Correct |
1213 ms |
7608 KB |
Output is correct |
22 |
Correct |
1218 ms |
8100 KB |
Output is correct |
23 |
Correct |
1224 ms |
7672 KB |
Output is correct |
24 |
Correct |
1183 ms |
7416 KB |
Output is correct |
25 |
Correct |
1199 ms |
7672 KB |
Output is correct |
26 |
Correct |
1227 ms |
7476 KB |
Output is correct |
27 |
Correct |
1254 ms |
7544 KB |
Output is correct |
28 |
Correct |
1227 ms |
7264 KB |
Output is correct |
29 |
Correct |
1227 ms |
7224 KB |
Output is correct |
30 |
Correct |
1196 ms |
8372 KB |
Output is correct |
31 |
Correct |
1218 ms |
8404 KB |
Output is correct |
32 |
Correct |
1196 ms |
8312 KB |
Output is correct |
33 |
Correct |
1205 ms |
8440 KB |
Output is correct |
34 |
Correct |
1199 ms |
8348 KB |
Output is correct |
35 |
Correct |
1192 ms |
8312 KB |
Output is correct |
36 |
Correct |
1210 ms |
8368 KB |
Output is correct |
37 |
Correct |
1213 ms |
8276 KB |
Output is correct |
38 |
Correct |
1197 ms |
8484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
1920 KB |
Output is correct |
2 |
Correct |
69 ms |
2040 KB |
Output is correct |
3 |
Correct |
68 ms |
1920 KB |
Output is correct |
4 |
Correct |
70 ms |
2040 KB |
Output is correct |
5 |
Correct |
70 ms |
1920 KB |
Output is correct |
6 |
Correct |
72 ms |
2040 KB |
Output is correct |
7 |
Correct |
74 ms |
1920 KB |
Output is correct |
8 |
Correct |
71 ms |
1920 KB |
Output is correct |
9 |
Correct |
72 ms |
1912 KB |
Output is correct |
10 |
Correct |
72 ms |
1912 KB |
Output is correct |
11 |
Correct |
69 ms |
1912 KB |
Output is correct |
12 |
Correct |
68 ms |
1920 KB |
Output is correct |
13 |
Correct |
69 ms |
1920 KB |
Output is correct |
14 |
Correct |
69 ms |
1920 KB |
Output is correct |
15 |
Correct |
69 ms |
1912 KB |
Output is correct |
16 |
Correct |
38 ms |
1280 KB |
Output is correct |
17 |
Correct |
38 ms |
1280 KB |
Output is correct |
18 |
Correct |
38 ms |
1280 KB |
Output is correct |
19 |
Correct |
39 ms |
1280 KB |
Output is correct |
20 |
Correct |
37 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1205 ms |
8412 KB |
Output is correct |
2 |
Correct |
1203 ms |
8440 KB |
Output is correct |
3 |
Correct |
1209 ms |
8412 KB |
Output is correct |
4 |
Correct |
1211 ms |
8304 KB |
Output is correct |
5 |
Correct |
1199 ms |
8204 KB |
Output is correct |
6 |
Correct |
1224 ms |
8312 KB |
Output is correct |
7 |
Correct |
1212 ms |
8312 KB |
Output is correct |
8 |
Correct |
1202 ms |
8440 KB |
Output is correct |
9 |
Correct |
1206 ms |
8420 KB |
Output is correct |
10 |
Correct |
1201 ms |
8392 KB |
Output is correct |
11 |
Correct |
1199 ms |
8440 KB |
Output is correct |
12 |
Correct |
1228 ms |
8416 KB |
Output is correct |
13 |
Correct |
1207 ms |
8428 KB |
Output is correct |
14 |
Correct |
1215 ms |
8428 KB |
Output is correct |
15 |
Correct |
1212 ms |
8376 KB |
Output is correct |
16 |
Correct |
211 ms |
1812 KB |
Output is correct |
17 |
Correct |
228 ms |
1912 KB |
Output is correct |
18 |
Correct |
219 ms |
1792 KB |
Output is correct |
19 |
Correct |
233 ms |
1912 KB |
Output is correct |
20 |
Correct |
222 ms |
1912 KB |
Output is correct |
21 |
Correct |
1213 ms |
7608 KB |
Output is correct |
22 |
Correct |
1218 ms |
8100 KB |
Output is correct |
23 |
Correct |
1224 ms |
7672 KB |
Output is correct |
24 |
Correct |
1183 ms |
7416 KB |
Output is correct |
25 |
Correct |
1199 ms |
7672 KB |
Output is correct |
26 |
Correct |
1227 ms |
7476 KB |
Output is correct |
27 |
Correct |
1254 ms |
7544 KB |
Output is correct |
28 |
Correct |
1227 ms |
7264 KB |
Output is correct |
29 |
Correct |
1227 ms |
7224 KB |
Output is correct |
30 |
Correct |
1196 ms |
8372 KB |
Output is correct |
31 |
Correct |
1218 ms |
8404 KB |
Output is correct |
32 |
Correct |
1196 ms |
8312 KB |
Output is correct |
33 |
Correct |
1205 ms |
8440 KB |
Output is correct |
34 |
Correct |
1199 ms |
8348 KB |
Output is correct |
35 |
Correct |
1192 ms |
8312 KB |
Output is correct |
36 |
Correct |
1210 ms |
8368 KB |
Output is correct |
37 |
Correct |
1213 ms |
8276 KB |
Output is correct |
38 |
Correct |
1197 ms |
8484 KB |
Output is correct |
39 |
Correct |
69 ms |
1920 KB |
Output is correct |
40 |
Correct |
69 ms |
2040 KB |
Output is correct |
41 |
Correct |
68 ms |
1920 KB |
Output is correct |
42 |
Correct |
70 ms |
2040 KB |
Output is correct |
43 |
Correct |
70 ms |
1920 KB |
Output is correct |
44 |
Correct |
72 ms |
2040 KB |
Output is correct |
45 |
Correct |
74 ms |
1920 KB |
Output is correct |
46 |
Correct |
71 ms |
1920 KB |
Output is correct |
47 |
Correct |
72 ms |
1912 KB |
Output is correct |
48 |
Correct |
72 ms |
1912 KB |
Output is correct |
49 |
Correct |
69 ms |
1912 KB |
Output is correct |
50 |
Correct |
68 ms |
1920 KB |
Output is correct |
51 |
Correct |
69 ms |
1920 KB |
Output is correct |
52 |
Correct |
69 ms |
1920 KB |
Output is correct |
53 |
Correct |
69 ms |
1912 KB |
Output is correct |
54 |
Correct |
38 ms |
1280 KB |
Output is correct |
55 |
Correct |
38 ms |
1280 KB |
Output is correct |
56 |
Correct |
38 ms |
1280 KB |
Output is correct |
57 |
Correct |
39 ms |
1280 KB |
Output is correct |
58 |
Correct |
37 ms |
1280 KB |
Output is correct |
59 |
Correct |
1417 ms |
8324 KB |
Output is correct |
60 |
Correct |
1388 ms |
8312 KB |
Output is correct |
61 |
Correct |
1382 ms |
8312 KB |
Output is correct |
62 |
Correct |
1393 ms |
8312 KB |
Output is correct |
63 |
Correct |
1394 ms |
8320 KB |
Output is correct |
64 |
Correct |
1488 ms |
8264 KB |
Output is correct |
65 |
Correct |
1481 ms |
8520 KB |
Output is correct |
66 |
Correct |
1478 ms |
8576 KB |
Output is correct |
67 |
Correct |
1471 ms |
8360 KB |
Output is correct |
68 |
Correct |
1472 ms |
8292 KB |
Output is correct |
69 |
Correct |
1378 ms |
8352 KB |
Output is correct |
70 |
Correct |
1385 ms |
8328 KB |
Output is correct |
71 |
Correct |
1395 ms |
8452 KB |
Output is correct |
72 |
Correct |
1397 ms |
8576 KB |
Output is correct |
73 |
Correct |
1406 ms |
8440 KB |
Output is correct |
74 |
Correct |
247 ms |
1784 KB |
Output is correct |
75 |
Correct |
252 ms |
1792 KB |
Output is correct |
76 |
Correct |
250 ms |
1792 KB |
Output is correct |
77 |
Correct |
251 ms |
1792 KB |
Output is correct |
78 |
Correct |
248 ms |
1912 KB |
Output is correct |