#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define inp1(a) scanf("%d",&a)
#define inp2(a,b) scanf("%d%d",&a,&b)
#define inp3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inp4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define inp5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)z
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vector<int> > vvi;
typedef pair<int,pair<int,int> > piii;
typedef vector<piii> viii;
const int MOD = 1000000007;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 102;
struct Range{
int l,r;
bool operator<(Range& rhs){
return l<rhs.l;
}
};
int N,M,a,b,E;
Range ranges[200003];
ll dp[1610003];
int lz[1610003];
ll poww[300000];
ll pow2(ll x, int n){
if(!n) return 1;
if(n%2) {
ll& cache = poww[(n-1)/2];
if(cache==-1) cache = pow2(x,(n-1)/2);
return x*cache%MOD*cache%MOD;
}
ll& cache = poww[n/2];
if(cache==-1) cache = pow2(x,n/2);
return cache*cache%MOD;
}
unordered_set<int> us;
ll query(int nl, int nr, int l, int r, int nd){
if(lz[nd]) (dp[nd]*=poww[lz[nd]])%=MOD,(nl!=nr?lz[2*nd]+=lz[nd],lz[2*nd+1]+=lz[nd]:0),lz[nd]=0;
if(l<=nl&&nr<=r) return dp[nd];
if(r<nl||nr<l) return 0;
return (query(nl,(nl+nr)/2,l,r,2*nd)+query((nl+nr)/2+1,nr,l,r,2*nd+1))%MOD;
} ll query(int l, int r){return query(0,E,l,r,1);}
void update(int nl, int nr, int l, int r, int nd){
if(lz[nd]) (dp[nd]*=poww[lz[nd]])%=MOD,(nl!=nr?lz[2*nd]+=lz[nd],lz[2*nd+1]+=lz[nd]:0),lz[nd]=0;
if(l<=nl&&nr<=r) {(dp[nd]*=2)%=MOD,(nl!=nr?lz[2*nd]++,lz[2*nd+1]++:0);return;}
if(r<nl||nr<l) return;
update(nl,(nl+nr)/2,l,r,2*nd),update((nl+nr)/2+1,nr,l,r,2*nd+1),dp[nd]=(dp[2*nd]+dp[2*nd+1])%MOD;
} void update(int l, int r){update(0,E,l,r,1);}
void pUpdate(int nl, int nr, int nd, int pos, ll val){
if(lz[nd]) (dp[nd]*=poww[lz[nd]])%=MOD,(nl!=nr?lz[2*nd]+=lz[nd],lz[2*nd+1]+=lz[nd]:0),lz[nd]=0;
if(nl==nr&&nl==pos) {dp[nd]=val;return;}
if(nr<pos||pos<nl) return;
pUpdate(nl,(nl+nr)/2,2*nd,pos,val),pUpdate((nl+nr)/2+1,nr,2*nd+1,pos,val),dp[nd]=(dp[2*nd]+dp[2*nd+1])%MOD;
} void pUpdate(int pos, ll val){pUpdate(0,E,1,pos,val);}
int main() {
vi sorted;
inp2(N,M);
us.insert(1),sorted.pb(1);
us.insert(N),sorted.pb(N);
FOR(i,M){
inp2(a,b);
ranges[i]=Range{a,b};
if(!us.count(a)) us.insert(a),sorted.pb(a);
if(!us.count(b)) us.insert(b),sorted.pb(b);
}
sort(all(sorted));
E=sz(sorted)-1;
FOR(i,M) {
ranges[i].l=lower_bound(all(sorted),ranges[i].l)-sorted.begin();
ranges[i].r=lower_bound(all(sorted),ranges[i].r)-sorted.begin();
}
sort(ranges,ranges+M);
// 좌표압축 + 정렬까지 완료
memset(poww,-1,sizeof(poww));
FOR(i,200100) if(poww[i]==-1) poww[i]=pow2(2,i);
pUpdate(0,1);
FOR(i,M){
pUpdate(ranges[i].r,(query(ranges[i].l,ranges[i].r)+query(ranges[i].r,ranges[i].r))%MOD);
update(ranges[i].r+1,E);
}
printf("%lld",query(E,E));
return 0;
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:74:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
inp2(N,M);
^
rail.cpp:78:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
inp2(a,b);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24804 KB |
Output is correct |
2 |
Correct |
0 ms |
24804 KB |
Output is correct |
3 |
Correct |
0 ms |
24804 KB |
Output is correct |
4 |
Correct |
0 ms |
24804 KB |
Output is correct |
5 |
Correct |
0 ms |
24804 KB |
Output is correct |
6 |
Correct |
0 ms |
24804 KB |
Output is correct |
7 |
Correct |
3 ms |
24804 KB |
Output is correct |
8 |
Correct |
0 ms |
24804 KB |
Output is correct |
9 |
Correct |
3 ms |
24804 KB |
Output is correct |
10 |
Correct |
3 ms |
24804 KB |
Output is correct |
11 |
Correct |
0 ms |
24804 KB |
Output is correct |
12 |
Correct |
3 ms |
24804 KB |
Output is correct |
13 |
Correct |
0 ms |
24804 KB |
Output is correct |
14 |
Correct |
3 ms |
24804 KB |
Output is correct |
15 |
Correct |
3 ms |
24804 KB |
Output is correct |
16 |
Correct |
3 ms |
24804 KB |
Output is correct |
17 |
Correct |
3 ms |
24804 KB |
Output is correct |
18 |
Correct |
3 ms |
24804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24804 KB |
Output is correct |
2 |
Correct |
0 ms |
24804 KB |
Output is correct |
3 |
Correct |
0 ms |
24804 KB |
Output is correct |
4 |
Correct |
0 ms |
24804 KB |
Output is correct |
5 |
Correct |
0 ms |
24804 KB |
Output is correct |
6 |
Correct |
0 ms |
24804 KB |
Output is correct |
7 |
Correct |
3 ms |
24804 KB |
Output is correct |
8 |
Correct |
0 ms |
24804 KB |
Output is correct |
9 |
Correct |
3 ms |
24804 KB |
Output is correct |
10 |
Correct |
3 ms |
24804 KB |
Output is correct |
11 |
Correct |
0 ms |
24804 KB |
Output is correct |
12 |
Correct |
3 ms |
24804 KB |
Output is correct |
13 |
Correct |
0 ms |
24804 KB |
Output is correct |
14 |
Correct |
3 ms |
24804 KB |
Output is correct |
15 |
Correct |
3 ms |
24804 KB |
Output is correct |
16 |
Correct |
3 ms |
24804 KB |
Output is correct |
17 |
Correct |
3 ms |
24804 KB |
Output is correct |
18 |
Correct |
3 ms |
24804 KB |
Output is correct |
19 |
Correct |
0 ms |
24804 KB |
Output is correct |
20 |
Correct |
3 ms |
24804 KB |
Output is correct |
21 |
Correct |
3 ms |
24804 KB |
Output is correct |
22 |
Correct |
0 ms |
24804 KB |
Output is correct |
23 |
Correct |
3 ms |
24804 KB |
Output is correct |
24 |
Correct |
3 ms |
24804 KB |
Output is correct |
25 |
Correct |
0 ms |
24804 KB |
Output is correct |
26 |
Correct |
3 ms |
24804 KB |
Output is correct |
27 |
Correct |
0 ms |
24804 KB |
Output is correct |
28 |
Correct |
0 ms |
24804 KB |
Output is correct |
29 |
Correct |
0 ms |
24804 KB |
Output is correct |
30 |
Correct |
0 ms |
24804 KB |
Output is correct |
31 |
Correct |
3 ms |
24804 KB |
Output is correct |
32 |
Correct |
3 ms |
24804 KB |
Output is correct |
33 |
Correct |
0 ms |
24804 KB |
Output is correct |
34 |
Correct |
0 ms |
24804 KB |
Output is correct |
35 |
Correct |
3 ms |
24804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24804 KB |
Output is correct |
2 |
Correct |
3 ms |
24804 KB |
Output is correct |
3 |
Correct |
3 ms |
24804 KB |
Output is correct |
4 |
Correct |
9 ms |
24940 KB |
Output is correct |
5 |
Correct |
299 ms |
27260 KB |
Output is correct |
6 |
Correct |
616 ms |
42400 KB |
Output is correct |
7 |
Correct |
556 ms |
42268 KB |
Output is correct |
8 |
Correct |
3 ms |
24804 KB |
Output is correct |
9 |
Correct |
559 ms |
41476 KB |
Output is correct |
10 |
Correct |
613 ms |
42136 KB |
Output is correct |
11 |
Correct |
186 ms |
26732 KB |
Output is correct |
12 |
Correct |
633 ms |
42400 KB |
Output is correct |
13 |
Correct |
606 ms |
42136 KB |
Output is correct |
14 |
Correct |
79 ms |
24804 KB |
Output is correct |
15 |
Correct |
536 ms |
34164 KB |
Output is correct |
16 |
Correct |
79 ms |
24804 KB |
Output is correct |
17 |
Correct |
629 ms |
42400 KB |
Output is correct |
18 |
Correct |
619 ms |
42400 KB |
Output is correct |
19 |
Correct |
596 ms |
40816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24804 KB |
Output is correct |
2 |
Correct |
0 ms |
24804 KB |
Output is correct |
3 |
Correct |
0 ms |
24804 KB |
Output is correct |
4 |
Correct |
0 ms |
24804 KB |
Output is correct |
5 |
Correct |
0 ms |
24804 KB |
Output is correct |
6 |
Correct |
0 ms |
24804 KB |
Output is correct |
7 |
Correct |
3 ms |
24804 KB |
Output is correct |
8 |
Correct |
0 ms |
24804 KB |
Output is correct |
9 |
Correct |
3 ms |
24804 KB |
Output is correct |
10 |
Correct |
3 ms |
24804 KB |
Output is correct |
11 |
Correct |
0 ms |
24804 KB |
Output is correct |
12 |
Correct |
3 ms |
24804 KB |
Output is correct |
13 |
Correct |
0 ms |
24804 KB |
Output is correct |
14 |
Correct |
3 ms |
24804 KB |
Output is correct |
15 |
Correct |
3 ms |
24804 KB |
Output is correct |
16 |
Correct |
3 ms |
24804 KB |
Output is correct |
17 |
Correct |
3 ms |
24804 KB |
Output is correct |
18 |
Correct |
3 ms |
24804 KB |
Output is correct |
19 |
Correct |
0 ms |
24804 KB |
Output is correct |
20 |
Correct |
3 ms |
24804 KB |
Output is correct |
21 |
Correct |
3 ms |
24804 KB |
Output is correct |
22 |
Correct |
0 ms |
24804 KB |
Output is correct |
23 |
Correct |
3 ms |
24804 KB |
Output is correct |
24 |
Correct |
3 ms |
24804 KB |
Output is correct |
25 |
Correct |
0 ms |
24804 KB |
Output is correct |
26 |
Correct |
3 ms |
24804 KB |
Output is correct |
27 |
Correct |
0 ms |
24804 KB |
Output is correct |
28 |
Correct |
0 ms |
24804 KB |
Output is correct |
29 |
Correct |
0 ms |
24804 KB |
Output is correct |
30 |
Correct |
0 ms |
24804 KB |
Output is correct |
31 |
Correct |
3 ms |
24804 KB |
Output is correct |
32 |
Correct |
3 ms |
24804 KB |
Output is correct |
33 |
Correct |
0 ms |
24804 KB |
Output is correct |
34 |
Correct |
0 ms |
24804 KB |
Output is correct |
35 |
Correct |
3 ms |
24804 KB |
Output is correct |
36 |
Correct |
13 ms |
25324 KB |
Output is correct |
37 |
Correct |
9 ms |
25324 KB |
Output is correct |
38 |
Correct |
9 ms |
24940 KB |
Output is correct |
39 |
Correct |
3 ms |
24804 KB |
Output is correct |
40 |
Correct |
6 ms |
25100 KB |
Output is correct |
41 |
Correct |
13 ms |
25324 KB |
Output is correct |
42 |
Correct |
13 ms |
25324 KB |
Output is correct |
43 |
Correct |
3 ms |
24804 KB |
Output is correct |
44 |
Correct |
13 ms |
25100 KB |
Output is correct |
45 |
Correct |
0 ms |
24804 KB |
Output is correct |
46 |
Correct |
9 ms |
25100 KB |
Output is correct |
47 |
Correct |
9 ms |
25100 KB |
Output is correct |
48 |
Correct |
9 ms |
25100 KB |
Output is correct |
49 |
Correct |
6 ms |
24804 KB |
Output is correct |
50 |
Correct |
6 ms |
24804 KB |
Output is correct |
51 |
Correct |
3 ms |
24804 KB |
Output is correct |
52 |
Correct |
0 ms |
24940 KB |
Output is correct |
53 |
Correct |
6 ms |
25324 KB |
Output is correct |
54 |
Correct |
6 ms |
24940 KB |
Output is correct |
55 |
Correct |
9 ms |
25324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24804 KB |
Output is correct |
2 |
Correct |
0 ms |
24804 KB |
Output is correct |
3 |
Correct |
0 ms |
24804 KB |
Output is correct |
4 |
Correct |
0 ms |
24804 KB |
Output is correct |
5 |
Correct |
0 ms |
24804 KB |
Output is correct |
6 |
Correct |
0 ms |
24804 KB |
Output is correct |
7 |
Correct |
3 ms |
24804 KB |
Output is correct |
8 |
Correct |
0 ms |
24804 KB |
Output is correct |
9 |
Correct |
3 ms |
24804 KB |
Output is correct |
10 |
Correct |
3 ms |
24804 KB |
Output is correct |
11 |
Correct |
0 ms |
24804 KB |
Output is correct |
12 |
Correct |
3 ms |
24804 KB |
Output is correct |
13 |
Correct |
0 ms |
24804 KB |
Output is correct |
14 |
Correct |
3 ms |
24804 KB |
Output is correct |
15 |
Correct |
3 ms |
24804 KB |
Output is correct |
16 |
Correct |
3 ms |
24804 KB |
Output is correct |
17 |
Correct |
3 ms |
24804 KB |
Output is correct |
18 |
Correct |
3 ms |
24804 KB |
Output is correct |
19 |
Correct |
0 ms |
24804 KB |
Output is correct |
20 |
Correct |
3 ms |
24804 KB |
Output is correct |
21 |
Correct |
3 ms |
24804 KB |
Output is correct |
22 |
Correct |
0 ms |
24804 KB |
Output is correct |
23 |
Correct |
3 ms |
24804 KB |
Output is correct |
24 |
Correct |
3 ms |
24804 KB |
Output is correct |
25 |
Correct |
0 ms |
24804 KB |
Output is correct |
26 |
Correct |
3 ms |
24804 KB |
Output is correct |
27 |
Correct |
0 ms |
24804 KB |
Output is correct |
28 |
Correct |
0 ms |
24804 KB |
Output is correct |
29 |
Correct |
0 ms |
24804 KB |
Output is correct |
30 |
Correct |
0 ms |
24804 KB |
Output is correct |
31 |
Correct |
3 ms |
24804 KB |
Output is correct |
32 |
Correct |
3 ms |
24804 KB |
Output is correct |
33 |
Correct |
0 ms |
24804 KB |
Output is correct |
34 |
Correct |
0 ms |
24804 KB |
Output is correct |
35 |
Correct |
3 ms |
24804 KB |
Output is correct |
36 |
Correct |
3 ms |
24804 KB |
Output is correct |
37 |
Correct |
3 ms |
24804 KB |
Output is correct |
38 |
Correct |
3 ms |
24804 KB |
Output is correct |
39 |
Correct |
9 ms |
24940 KB |
Output is correct |
40 |
Correct |
299 ms |
27260 KB |
Output is correct |
41 |
Correct |
616 ms |
42400 KB |
Output is correct |
42 |
Correct |
556 ms |
42268 KB |
Output is correct |
43 |
Correct |
3 ms |
24804 KB |
Output is correct |
44 |
Correct |
559 ms |
41476 KB |
Output is correct |
45 |
Correct |
613 ms |
42136 KB |
Output is correct |
46 |
Correct |
186 ms |
26732 KB |
Output is correct |
47 |
Correct |
633 ms |
42400 KB |
Output is correct |
48 |
Correct |
606 ms |
42136 KB |
Output is correct |
49 |
Correct |
79 ms |
24804 KB |
Output is correct |
50 |
Correct |
536 ms |
34164 KB |
Output is correct |
51 |
Correct |
79 ms |
24804 KB |
Output is correct |
52 |
Correct |
629 ms |
42400 KB |
Output is correct |
53 |
Correct |
619 ms |
42400 KB |
Output is correct |
54 |
Correct |
596 ms |
40816 KB |
Output is correct |
55 |
Correct |
13 ms |
25324 KB |
Output is correct |
56 |
Correct |
9 ms |
25324 KB |
Output is correct |
57 |
Correct |
9 ms |
24940 KB |
Output is correct |
58 |
Correct |
3 ms |
24804 KB |
Output is correct |
59 |
Correct |
6 ms |
25100 KB |
Output is correct |
60 |
Correct |
13 ms |
25324 KB |
Output is correct |
61 |
Correct |
13 ms |
25324 KB |
Output is correct |
62 |
Correct |
3 ms |
24804 KB |
Output is correct |
63 |
Correct |
13 ms |
25100 KB |
Output is correct |
64 |
Correct |
0 ms |
24804 KB |
Output is correct |
65 |
Correct |
9 ms |
25100 KB |
Output is correct |
66 |
Correct |
9 ms |
25100 KB |
Output is correct |
67 |
Correct |
9 ms |
25100 KB |
Output is correct |
68 |
Correct |
6 ms |
24804 KB |
Output is correct |
69 |
Correct |
6 ms |
24804 KB |
Output is correct |
70 |
Correct |
3 ms |
24804 KB |
Output is correct |
71 |
Correct |
0 ms |
24940 KB |
Output is correct |
72 |
Correct |
6 ms |
25324 KB |
Output is correct |
73 |
Correct |
6 ms |
24940 KB |
Output is correct |
74 |
Correct |
9 ms |
25324 KB |
Output is correct |
75 |
Correct |
819 ms |
43456 KB |
Output is correct |
76 |
Correct |
499 ms |
39948 KB |
Output is correct |
77 |
Correct |
283 ms |
24940 KB |
Output is correct |
78 |
Correct |
73 ms |
24804 KB |
Output is correct |
79 |
Correct |
466 ms |
28676 KB |
Output is correct |
80 |
Correct |
793 ms |
43456 KB |
Output is correct |
81 |
Correct |
9 ms |
25100 KB |
Output is correct |
82 |
Correct |
746 ms |
42004 KB |
Output is correct |
83 |
Correct |
59 ms |
24804 KB |
Output is correct |
84 |
Correct |
679 ms |
40288 KB |
Output is correct |
85 |
Correct |
613 ms |
34032 KB |
Output is correct |
86 |
Correct |
599 ms |
34164 KB |
Output is correct |
87 |
Correct |
159 ms |
24804 KB |
Output is correct |
88 |
Correct |
143 ms |
24804 KB |
Output is correct |
89 |
Correct |
796 ms |
43456 KB |
Output is correct |
90 |
Correct |
749 ms |
43456 KB |
Output is correct |
91 |
Correct |
706 ms |
43456 KB |
Output is correct |
92 |
Correct |
699 ms |
43060 KB |
Output is correct |
93 |
Correct |
576 ms |
34032 KB |
Output is correct |
94 |
Correct |
759 ms |
43456 KB |
Output is correct |
95 |
Correct |
746 ms |
43456 KB |
Output is correct |