Submission #66262

# Submission time Handle Problem Language Result Execution time Memory
66262 2018-08-10T06:12:57 Z 노영훈(#1886) 초음속철도 (OJUZ11_rail) C++11
100 / 100
771 ms 29324 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=200010, MOD=1e9+7;

int n, m, lim;
ll PW2[MX];
struct rail{
	int s, e;
	void scan(){ cin>>s>>e; }
} R[MX];
vector<int> P[2*MX];

struct node{
	int lz, sum;
} tree[1<<20];

void busy(int v, int s, int e){
	int &z=tree[v].lz;
	if(s!=e){
		node &nd1=tree[v*2], &nd2=tree[v*2+1];
		nd1.sum=PW2[z]*nd1.sum%MOD;
		nd2.sum=PW2[z]*nd2.sum%MOD;
		nd1.lz+=z;
		nd2.lz+=z;
	}
	z=0;
}
void two(int v, int s, int e, int l, int r){
	if(r<s || e<l) return;
	node &nd=tree[v];
	if(l<=s && e<=r){
		nd.lz++;
		nd.sum=(nd.sum*2)%MOD;
		return;
	}
	busy(v,s,e);
	two(v*2,s,(s+e)/2,l,r);
	two(v*2+1,(s+e)/2+1,e,l,r);
	nd.sum=(tree[v*2].sum+tree[v*2+1].sum)%MOD;
}
int sum(int v, int s, int e, int l, int r){
	if(r<s || e<l) return 0;
	busy(v,s,e);
	if(l<=s && e<=r) return tree[v].sum;
	return (sum(v*2,s,(s+e)/2,l,r) + sum(v*2+1,(s+e)/2+1,e,l,r))%MOD;
}
void add(int v, int s, int e, int pos, int val){
	if(pos<s || e<pos) return;
	busy(v,s,e);
	node &nd=tree[v];
	if(s==e){
		nd.sum=(nd.sum+val)%MOD;
		return;
	}
	add(v*2,s,(s+e)/2,pos,val);
	add(v*2+1,(s+e)/2+1,e,pos,val);
	nd.sum=(tree[v*2].sum+tree[v*2+1].sum)%MOD;
}
void two(int l, int r){
	if(r<l) return;
	two(1,1,lim,l,r);
}
int sum(int l, int r){
	assert(l<=r);
	return sum(1,1,lim,l,r);
}
void add(int pos, int val){
	add(1,1,lim,pos,val);
}

int solve(){
	for(int i=1; i<=n; i++){
		P[R[i].s].push_back(R[i].e);
	}
	for(int i=1; i<=lim; i++) sort(P[i].begin(), P[i].end());

	add(1,1);

	for(int s=1; s<=lim; s++){
		for(int e:P[s]){
			two(e+1, lim);
			add(e, sum(s,e));
		}
	}

	return sum(lim, lim);
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>m>>n;

	PW2[0]=1;
	for(int i=1; i<=n; i++) PW2[i]=PW2[i-1]*2%MOD;

	vector<int> X={1,m};
	for(int i=1; i<=n; i++){
		R[i].scan();
		X.push_back(R[i].s);
		X.push_back(R[i].e);
	}
	sort(X.begin(), X.end());
	lim=unique(X.begin(), X.end())-X.begin();
	X.resize(lim);
	for(int i=1; i<=n; i++){
		R[i].s=lower_bound(X.begin(), X.end(), R[i].s)-X.begin()+1;
		R[i].e=lower_bound(X.begin(), X.end(), R[i].e)-X.begin()+1;
	}

	cout<<solve()<<'\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9828 KB Output is correct
3 Correct 10 ms 9828 KB Output is correct
4 Correct 10 ms 9920 KB Output is correct
5 Correct 11 ms 9980 KB Output is correct
6 Correct 11 ms 10064 KB Output is correct
7 Correct 11 ms 10064 KB Output is correct
8 Correct 10 ms 10064 KB Output is correct
9 Correct 10 ms 10064 KB Output is correct
10 Correct 11 ms 10064 KB Output is correct
11 Correct 10 ms 10064 KB Output is correct
12 Correct 10 ms 10064 KB Output is correct
13 Correct 11 ms 10064 KB Output is correct
14 Correct 10 ms 10064 KB Output is correct
15 Correct 11 ms 10064 KB Output is correct
16 Correct 10 ms 10064 KB Output is correct
17 Correct 11 ms 10064 KB Output is correct
18 Correct 12 ms 10064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9828 KB Output is correct
3 Correct 10 ms 9828 KB Output is correct
4 Correct 10 ms 9920 KB Output is correct
5 Correct 11 ms 9980 KB Output is correct
6 Correct 11 ms 10064 KB Output is correct
7 Correct 11 ms 10064 KB Output is correct
8 Correct 10 ms 10064 KB Output is correct
9 Correct 10 ms 10064 KB Output is correct
10 Correct 11 ms 10064 KB Output is correct
11 Correct 10 ms 10064 KB Output is correct
12 Correct 10 ms 10064 KB Output is correct
13 Correct 11 ms 10064 KB Output is correct
14 Correct 10 ms 10064 KB Output is correct
15 Correct 11 ms 10064 KB Output is correct
16 Correct 10 ms 10064 KB Output is correct
17 Correct 11 ms 10064 KB Output is correct
18 Correct 12 ms 10064 KB Output is correct
19 Correct 13 ms 10064 KB Output is correct
20 Correct 11 ms 10064 KB Output is correct
21 Correct 10 ms 10064 KB Output is correct
22 Correct 11 ms 10064 KB Output is correct
23 Correct 10 ms 10064 KB Output is correct
24 Correct 11 ms 10064 KB Output is correct
25 Correct 11 ms 10064 KB Output is correct
26 Correct 10 ms 10064 KB Output is correct
27 Correct 11 ms 10064 KB Output is correct
28 Correct 10 ms 10064 KB Output is correct
29 Correct 11 ms 10064 KB Output is correct
30 Correct 11 ms 10064 KB Output is correct
31 Correct 12 ms 10064 KB Output is correct
32 Correct 10 ms 10064 KB Output is correct
33 Correct 11 ms 10064 KB Output is correct
34 Correct 11 ms 10064 KB Output is correct
35 Correct 10 ms 10064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10064 KB Output is correct
2 Correct 10 ms 10064 KB Output is correct
3 Correct 9 ms 10064 KB Output is correct
4 Correct 16 ms 10240 KB Output is correct
5 Correct 268 ms 17768 KB Output is correct
6 Correct 473 ms 29164 KB Output is correct
7 Correct 505 ms 29164 KB Output is correct
8 Correct 10 ms 29164 KB Output is correct
9 Correct 473 ms 29164 KB Output is correct
10 Correct 492 ms 29164 KB Output is correct
11 Correct 203 ms 29164 KB Output is correct
12 Correct 511 ms 29164 KB Output is correct
13 Correct 468 ms 29164 KB Output is correct
14 Correct 93 ms 29164 KB Output is correct
15 Correct 462 ms 29164 KB Output is correct
16 Correct 112 ms 29164 KB Output is correct
17 Correct 473 ms 29164 KB Output is correct
18 Correct 563 ms 29164 KB Output is correct
19 Correct 511 ms 29164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9828 KB Output is correct
3 Correct 10 ms 9828 KB Output is correct
4 Correct 10 ms 9920 KB Output is correct
5 Correct 11 ms 9980 KB Output is correct
6 Correct 11 ms 10064 KB Output is correct
7 Correct 11 ms 10064 KB Output is correct
8 Correct 10 ms 10064 KB Output is correct
9 Correct 10 ms 10064 KB Output is correct
10 Correct 11 ms 10064 KB Output is correct
11 Correct 10 ms 10064 KB Output is correct
12 Correct 10 ms 10064 KB Output is correct
13 Correct 11 ms 10064 KB Output is correct
14 Correct 10 ms 10064 KB Output is correct
15 Correct 11 ms 10064 KB Output is correct
16 Correct 10 ms 10064 KB Output is correct
17 Correct 11 ms 10064 KB Output is correct
18 Correct 12 ms 10064 KB Output is correct
19 Correct 13 ms 10064 KB Output is correct
20 Correct 11 ms 10064 KB Output is correct
21 Correct 10 ms 10064 KB Output is correct
22 Correct 11 ms 10064 KB Output is correct
23 Correct 10 ms 10064 KB Output is correct
24 Correct 11 ms 10064 KB Output is correct
25 Correct 11 ms 10064 KB Output is correct
26 Correct 10 ms 10064 KB Output is correct
27 Correct 11 ms 10064 KB Output is correct
28 Correct 10 ms 10064 KB Output is correct
29 Correct 11 ms 10064 KB Output is correct
30 Correct 11 ms 10064 KB Output is correct
31 Correct 12 ms 10064 KB Output is correct
32 Correct 10 ms 10064 KB Output is correct
33 Correct 11 ms 10064 KB Output is correct
34 Correct 11 ms 10064 KB Output is correct
35 Correct 10 ms 10064 KB Output is correct
36 Correct 20 ms 29164 KB Output is correct
37 Correct 19 ms 29164 KB Output is correct
38 Correct 17 ms 29164 KB Output is correct
39 Correct 13 ms 29164 KB Output is correct
40 Correct 20 ms 29164 KB Output is correct
41 Correct 22 ms 29164 KB Output is correct
42 Correct 23 ms 29164 KB Output is correct
43 Correct 10 ms 29164 KB Output is correct
44 Correct 17 ms 29164 KB Output is correct
45 Correct 12 ms 29164 KB Output is correct
46 Correct 16 ms 29164 KB Output is correct
47 Correct 20 ms 29164 KB Output is correct
48 Correct 20 ms 29164 KB Output is correct
49 Correct 16 ms 29164 KB Output is correct
50 Correct 14 ms 29164 KB Output is correct
51 Correct 14 ms 29164 KB Output is correct
52 Correct 11 ms 29164 KB Output is correct
53 Correct 20 ms 29164 KB Output is correct
54 Correct 16 ms 29164 KB Output is correct
55 Correct 20 ms 29164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 11 ms 9828 KB Output is correct
3 Correct 10 ms 9828 KB Output is correct
4 Correct 10 ms 9920 KB Output is correct
5 Correct 11 ms 9980 KB Output is correct
6 Correct 11 ms 10064 KB Output is correct
7 Correct 11 ms 10064 KB Output is correct
8 Correct 10 ms 10064 KB Output is correct
9 Correct 10 ms 10064 KB Output is correct
10 Correct 11 ms 10064 KB Output is correct
11 Correct 10 ms 10064 KB Output is correct
12 Correct 10 ms 10064 KB Output is correct
13 Correct 11 ms 10064 KB Output is correct
14 Correct 10 ms 10064 KB Output is correct
15 Correct 11 ms 10064 KB Output is correct
16 Correct 10 ms 10064 KB Output is correct
17 Correct 11 ms 10064 KB Output is correct
18 Correct 12 ms 10064 KB Output is correct
19 Correct 13 ms 10064 KB Output is correct
20 Correct 11 ms 10064 KB Output is correct
21 Correct 10 ms 10064 KB Output is correct
22 Correct 11 ms 10064 KB Output is correct
23 Correct 10 ms 10064 KB Output is correct
24 Correct 11 ms 10064 KB Output is correct
25 Correct 11 ms 10064 KB Output is correct
26 Correct 10 ms 10064 KB Output is correct
27 Correct 11 ms 10064 KB Output is correct
28 Correct 10 ms 10064 KB Output is correct
29 Correct 11 ms 10064 KB Output is correct
30 Correct 11 ms 10064 KB Output is correct
31 Correct 12 ms 10064 KB Output is correct
32 Correct 10 ms 10064 KB Output is correct
33 Correct 11 ms 10064 KB Output is correct
34 Correct 11 ms 10064 KB Output is correct
35 Correct 10 ms 10064 KB Output is correct
36 Correct 10 ms 10064 KB Output is correct
37 Correct 10 ms 10064 KB Output is correct
38 Correct 9 ms 10064 KB Output is correct
39 Correct 16 ms 10240 KB Output is correct
40 Correct 268 ms 17768 KB Output is correct
41 Correct 473 ms 29164 KB Output is correct
42 Correct 505 ms 29164 KB Output is correct
43 Correct 10 ms 29164 KB Output is correct
44 Correct 473 ms 29164 KB Output is correct
45 Correct 492 ms 29164 KB Output is correct
46 Correct 203 ms 29164 KB Output is correct
47 Correct 511 ms 29164 KB Output is correct
48 Correct 468 ms 29164 KB Output is correct
49 Correct 93 ms 29164 KB Output is correct
50 Correct 462 ms 29164 KB Output is correct
51 Correct 112 ms 29164 KB Output is correct
52 Correct 473 ms 29164 KB Output is correct
53 Correct 563 ms 29164 KB Output is correct
54 Correct 511 ms 29164 KB Output is correct
55 Correct 20 ms 29164 KB Output is correct
56 Correct 19 ms 29164 KB Output is correct
57 Correct 17 ms 29164 KB Output is correct
58 Correct 13 ms 29164 KB Output is correct
59 Correct 20 ms 29164 KB Output is correct
60 Correct 22 ms 29164 KB Output is correct
61 Correct 23 ms 29164 KB Output is correct
62 Correct 10 ms 29164 KB Output is correct
63 Correct 17 ms 29164 KB Output is correct
64 Correct 12 ms 29164 KB Output is correct
65 Correct 16 ms 29164 KB Output is correct
66 Correct 20 ms 29164 KB Output is correct
67 Correct 20 ms 29164 KB Output is correct
68 Correct 16 ms 29164 KB Output is correct
69 Correct 14 ms 29164 KB Output is correct
70 Correct 14 ms 29164 KB Output is correct
71 Correct 11 ms 29164 KB Output is correct
72 Correct 20 ms 29164 KB Output is correct
73 Correct 16 ms 29164 KB Output is correct
74 Correct 20 ms 29164 KB Output is correct
75 Correct 709 ms 29188 KB Output is correct
76 Correct 427 ms 29188 KB Output is correct
77 Correct 311 ms 29188 KB Output is correct
78 Correct 89 ms 29188 KB Output is correct
79 Correct 462 ms 29188 KB Output is correct
80 Correct 694 ms 29292 KB Output is correct
81 Correct 21 ms 29292 KB Output is correct
82 Correct 628 ms 29292 KB Output is correct
83 Correct 76 ms 29292 KB Output is correct
84 Correct 608 ms 29292 KB Output is correct
85 Correct 580 ms 29292 KB Output is correct
86 Correct 581 ms 29292 KB Output is correct
87 Correct 166 ms 29292 KB Output is correct
88 Correct 151 ms 29292 KB Output is correct
89 Correct 655 ms 29292 KB Output is correct
90 Correct 733 ms 29324 KB Output is correct
91 Correct 688 ms 29324 KB Output is correct
92 Correct 660 ms 29324 KB Output is correct
93 Correct 648 ms 29324 KB Output is correct
94 Correct 771 ms 29324 KB Output is correct
95 Correct 719 ms 29324 KB Output is correct