Submission #20418

# Submission time Handle Problem Language Result Execution time Memory
20418 2017-02-11T09:56:47 Z tlwpdus(#44, tlwpdus) 초음속철도 (OJUZ11_rail) C++
100 / 100
666 ms 43976 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;

const ll MOD = 1000000007;
ll po[200100] = {1};

struct node {
	ll val, rex;
	node *l, *r;
	node(){val=rex=0;l=r=0;}
	void pd() {
		l->val *= po[rex];
		l->val %= MOD;
		r->val *= po[rex];
		r->val %= MOD;
		l->rex += rex;
		r->rex += rex;
		rex = 0;
	}
	void pu() {
		val = (l->val + r->val)%MOD;
	}
	void init(int s, int e) {
		if (s==e) {
			return;
		}
		int m = (s+e)>>1;
		l = new node();
		l -> init(s,m);
		r = new node();
		r -> init(m+1,e);
	}
	void upd(int s, int e, int idx, ll v) {
		if (e<idx||idx<s) return;
		if (s==e) {
			val += v;
			val %= MOD;
			return;
		}
		int m = (s+e)>>1;
		pd();
		l -> upd(s,m,idx,v);
		r -> upd(m+1,e,idx,v);
		pu();
	}
	void upde(int s, int e, int S, int E, ll ex) {
		if (e<S||E<s) return;
		if (S<=s&&e<=E) {
			rex += ex;
			val *= po[ex];
			val %= MOD;
			return;
		}
		int m = (s+e)>>1;
		pd();
		l -> upde(s,m,S,E,ex);
		r -> upde(m+1,e,S,E,ex);
		pu();
	}
	ll getv(int s, int e, int S, int E) {
		if (e<S||E<s) return 0;
		if (S<=s&&e<=E) {
			return val;
		}
		int m = (s+e)>>1;
		pd();
		ll res = (l -> getv(s,m,S,E) + r -> getv(m+1,e,S,E))%MOD;
		pu();
		return res;
	}
} *head;

int n, m;

vector<int> comp;
pii arr[200100];

bool cmpi(pii a, pii b) {
	return a.second<b.second||(a.second==b.second&&a.first<b.first);
}
int main() {
	int i;
	scanf("%d%d",&n,&m);
	comp.push_back(1);
	comp.push_back(n);
	for (i=1;i<=m+10;i++) po[i] = (po[i-1]*2)%MOD;
	for (i=0;i<m;i++) {
		scanf("%d%d",&arr[i].first,&arr[i].second);
		comp.push_back(arr[i].first);
		comp.push_back(arr[i].second);
	}
	sort(comp.begin(),comp.end());
	comp.erase(unique(comp.begin(),comp.end()),comp.end());
	n = (int)comp.size()-1;
	for (i=0;i<m;i++) {
		arr[i].first = lower_bound(comp.begin(),comp.end(),arr[i].first)-comp.begin();
		arr[i].second = lower_bound(comp.begin(),comp.end(),arr[i].second)-comp.begin();
	}
	sort(arr,arr+m,cmpi);
	head = new node();
	head->init(0,n);
	head->upd(0,n,0,1);
	for (i=0;i<m;i++) {
		head->upd(0,n,arr[i].second,head->getv(0,n,arr[i].first,arr[i].second));
		if (arr[i].first>0) head->upde(0,n,0,arr[i].first-1,1);
	}
	printf("%lld\n",head->getv(0,n,n,n));

	return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:91:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
rail.cpp:96:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&arr[i].first,&arr[i].second);
                                             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4360 KB Output is correct
2 Correct 0 ms 4360 KB Output is correct
3 Correct 0 ms 4360 KB Output is correct
4 Correct 0 ms 4360 KB Output is correct
5 Correct 0 ms 4360 KB Output is correct
6 Correct 0 ms 4360 KB Output is correct
7 Correct 0 ms 4360 KB Output is correct
8 Correct 0 ms 4360 KB Output is correct
9 Correct 0 ms 4360 KB Output is correct
10 Correct 0 ms 4360 KB Output is correct
11 Correct 0 ms 4360 KB Output is correct
12 Correct 0 ms 4360 KB Output is correct
13 Correct 0 ms 4360 KB Output is correct
14 Correct 0 ms 4360 KB Output is correct
15 Correct 0 ms 4360 KB Output is correct
16 Correct 0 ms 4360 KB Output is correct
17 Correct 0 ms 4360 KB Output is correct
18 Correct 0 ms 4360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4360 KB Output is correct
2 Correct 0 ms 4360 KB Output is correct
3 Correct 0 ms 4360 KB Output is correct
4 Correct 0 ms 4360 KB Output is correct
5 Correct 0 ms 4360 KB Output is correct
6 Correct 0 ms 4360 KB Output is correct
7 Correct 0 ms 4360 KB Output is correct
8 Correct 0 ms 4360 KB Output is correct
9 Correct 0 ms 4360 KB Output is correct
10 Correct 0 ms 4360 KB Output is correct
11 Correct 0 ms 4360 KB Output is correct
12 Correct 0 ms 4360 KB Output is correct
13 Correct 0 ms 4360 KB Output is correct
14 Correct 0 ms 4360 KB Output is correct
15 Correct 0 ms 4360 KB Output is correct
16 Correct 0 ms 4360 KB Output is correct
17 Correct 0 ms 4360 KB Output is correct
18 Correct 0 ms 4360 KB Output is correct
19 Correct 0 ms 4360 KB Output is correct
20 Correct 0 ms 4360 KB Output is correct
21 Correct 0 ms 4360 KB Output is correct
22 Correct 0 ms 4360 KB Output is correct
23 Correct 0 ms 4360 KB Output is correct
24 Correct 0 ms 4360 KB Output is correct
25 Correct 0 ms 4360 KB Output is correct
26 Correct 0 ms 4360 KB Output is correct
27 Correct 0 ms 4360 KB Output is correct
28 Correct 0 ms 4360 KB Output is correct
29 Correct 0 ms 4360 KB Output is correct
30 Correct 0 ms 4360 KB Output is correct
31 Correct 0 ms 4360 KB Output is correct
32 Correct 0 ms 4360 KB Output is correct
33 Correct 0 ms 4360 KB Output is correct
34 Correct 0 ms 4360 KB Output is correct
35 Correct 0 ms 4360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4360 KB Output is correct
2 Correct 0 ms 4360 KB Output is correct
3 Correct 0 ms 4360 KB Output is correct
4 Correct 6 ms 4632 KB Output is correct
5 Correct 283 ms 11636 KB Output is correct
6 Correct 443 ms 40808 KB Output is correct
7 Correct 429 ms 40280 KB Output is correct
8 Correct 0 ms 4360 KB Output is correct
9 Correct 406 ms 38168 KB Output is correct
10 Correct 429 ms 39884 KB Output is correct
11 Correct 136 ms 8632 KB Output is correct
12 Correct 443 ms 40808 KB Output is correct
13 Correct 439 ms 40148 KB Output is correct
14 Correct 83 ms 7516 KB Output is correct
15 Correct 406 ms 25232 KB Output is correct
16 Correct 83 ms 7516 KB Output is correct
17 Correct 439 ms 40808 KB Output is correct
18 Correct 459 ms 40808 KB Output is correct
19 Correct 446 ms 35924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4360 KB Output is correct
2 Correct 0 ms 4360 KB Output is correct
3 Correct 0 ms 4360 KB Output is correct
4 Correct 0 ms 4360 KB Output is correct
5 Correct 0 ms 4360 KB Output is correct
6 Correct 0 ms 4360 KB Output is correct
7 Correct 0 ms 4360 KB Output is correct
8 Correct 0 ms 4360 KB Output is correct
9 Correct 0 ms 4360 KB Output is correct
10 Correct 0 ms 4360 KB Output is correct
11 Correct 0 ms 4360 KB Output is correct
12 Correct 0 ms 4360 KB Output is correct
13 Correct 0 ms 4360 KB Output is correct
14 Correct 0 ms 4360 KB Output is correct
15 Correct 0 ms 4360 KB Output is correct
16 Correct 0 ms 4360 KB Output is correct
17 Correct 0 ms 4360 KB Output is correct
18 Correct 0 ms 4360 KB Output is correct
19 Correct 0 ms 4360 KB Output is correct
20 Correct 0 ms 4360 KB Output is correct
21 Correct 0 ms 4360 KB Output is correct
22 Correct 0 ms 4360 KB Output is correct
23 Correct 0 ms 4360 KB Output is correct
24 Correct 0 ms 4360 KB Output is correct
25 Correct 0 ms 4360 KB Output is correct
26 Correct 0 ms 4360 KB Output is correct
27 Correct 0 ms 4360 KB Output is correct
28 Correct 0 ms 4360 KB Output is correct
29 Correct 0 ms 4360 KB Output is correct
30 Correct 0 ms 4360 KB Output is correct
31 Correct 0 ms 4360 KB Output is correct
32 Correct 0 ms 4360 KB Output is correct
33 Correct 0 ms 4360 KB Output is correct
34 Correct 0 ms 4360 KB Output is correct
35 Correct 0 ms 4360 KB Output is correct
36 Correct 6 ms 5424 KB Output is correct
37 Correct 9 ms 5160 KB Output is correct
38 Correct 6 ms 4764 KB Output is correct
39 Correct 0 ms 4500 KB Output is correct
40 Correct 6 ms 4896 KB Output is correct
41 Correct 9 ms 5424 KB Output is correct
42 Correct 6 ms 5424 KB Output is correct
43 Correct 0 ms 4360 KB Output is correct
44 Correct 6 ms 5028 KB Output is correct
45 Correct 3 ms 4500 KB Output is correct
46 Correct 3 ms 4896 KB Output is correct
47 Correct 9 ms 4896 KB Output is correct
48 Correct 6 ms 4896 KB Output is correct
49 Correct 3 ms 4500 KB Output is correct
50 Correct 3 ms 4500 KB Output is correct
51 Correct 3 ms 4500 KB Output is correct
52 Correct 3 ms 4624 KB Output is correct
53 Correct 9 ms 5424 KB Output is correct
54 Correct 6 ms 4632 KB Output is correct
55 Correct 9 ms 5424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4360 KB Output is correct
2 Correct 0 ms 4360 KB Output is correct
3 Correct 0 ms 4360 KB Output is correct
4 Correct 0 ms 4360 KB Output is correct
5 Correct 0 ms 4360 KB Output is correct
6 Correct 0 ms 4360 KB Output is correct
7 Correct 0 ms 4360 KB Output is correct
8 Correct 0 ms 4360 KB Output is correct
9 Correct 0 ms 4360 KB Output is correct
10 Correct 0 ms 4360 KB Output is correct
11 Correct 0 ms 4360 KB Output is correct
12 Correct 0 ms 4360 KB Output is correct
13 Correct 0 ms 4360 KB Output is correct
14 Correct 0 ms 4360 KB Output is correct
15 Correct 0 ms 4360 KB Output is correct
16 Correct 0 ms 4360 KB Output is correct
17 Correct 0 ms 4360 KB Output is correct
18 Correct 0 ms 4360 KB Output is correct
19 Correct 0 ms 4360 KB Output is correct
20 Correct 0 ms 4360 KB Output is correct
21 Correct 0 ms 4360 KB Output is correct
22 Correct 0 ms 4360 KB Output is correct
23 Correct 0 ms 4360 KB Output is correct
24 Correct 0 ms 4360 KB Output is correct
25 Correct 0 ms 4360 KB Output is correct
26 Correct 0 ms 4360 KB Output is correct
27 Correct 0 ms 4360 KB Output is correct
28 Correct 0 ms 4360 KB Output is correct
29 Correct 0 ms 4360 KB Output is correct
30 Correct 0 ms 4360 KB Output is correct
31 Correct 0 ms 4360 KB Output is correct
32 Correct 0 ms 4360 KB Output is correct
33 Correct 0 ms 4360 KB Output is correct
34 Correct 0 ms 4360 KB Output is correct
35 Correct 0 ms 4360 KB Output is correct
36 Correct 0 ms 4360 KB Output is correct
37 Correct 0 ms 4360 KB Output is correct
38 Correct 0 ms 4360 KB Output is correct
39 Correct 6 ms 4632 KB Output is correct
40 Correct 283 ms 11636 KB Output is correct
41 Correct 443 ms 40808 KB Output is correct
42 Correct 429 ms 40280 KB Output is correct
43 Correct 0 ms 4360 KB Output is correct
44 Correct 406 ms 38168 KB Output is correct
45 Correct 429 ms 39884 KB Output is correct
46 Correct 136 ms 8632 KB Output is correct
47 Correct 443 ms 40808 KB Output is correct
48 Correct 439 ms 40148 KB Output is correct
49 Correct 83 ms 7516 KB Output is correct
50 Correct 406 ms 25232 KB Output is correct
51 Correct 83 ms 7516 KB Output is correct
52 Correct 439 ms 40808 KB Output is correct
53 Correct 459 ms 40808 KB Output is correct
54 Correct 446 ms 35924 KB Output is correct
55 Correct 6 ms 5424 KB Output is correct
56 Correct 9 ms 5160 KB Output is correct
57 Correct 6 ms 4764 KB Output is correct
58 Correct 0 ms 4500 KB Output is correct
59 Correct 6 ms 4896 KB Output is correct
60 Correct 9 ms 5424 KB Output is correct
61 Correct 6 ms 5424 KB Output is correct
62 Correct 0 ms 4360 KB Output is correct
63 Correct 6 ms 5028 KB Output is correct
64 Correct 3 ms 4500 KB Output is correct
65 Correct 3 ms 4896 KB Output is correct
66 Correct 9 ms 4896 KB Output is correct
67 Correct 6 ms 4896 KB Output is correct
68 Correct 3 ms 4500 KB Output is correct
69 Correct 3 ms 4500 KB Output is correct
70 Correct 3 ms 4500 KB Output is correct
71 Correct 3 ms 4624 KB Output is correct
72 Correct 9 ms 5424 KB Output is correct
73 Correct 6 ms 4632 KB Output is correct
74 Correct 9 ms 5424 KB Output is correct
75 Correct 626 ms 43976 KB Output is correct
76 Correct 393 ms 31040 KB Output is correct
77 Correct 296 ms 7516 KB Output is correct
78 Correct 96 ms 7516 KB Output is correct
79 Correct 446 ms 13616 KB Output is correct
80 Correct 633 ms 43976 KB Output is correct
81 Correct 9 ms 4896 KB Output is correct
82 Correct 579 ms 39752 KB Output is correct
83 Correct 79 ms 7516 KB Output is correct
84 Correct 509 ms 34604 KB Output is correct
85 Correct 536 ms 25100 KB Output is correct
86 Correct 523 ms 25232 KB Output is correct
87 Correct 159 ms 7516 KB Output is correct
88 Correct 166 ms 7516 KB Output is correct
89 Correct 633 ms 43976 KB Output is correct
90 Correct 643 ms 43976 KB Output is correct
91 Correct 629 ms 43976 KB Output is correct
92 Correct 603 ms 42788 KB Output is correct
93 Correct 536 ms 25100 KB Output is correct
94 Correct 666 ms 43976 KB Output is correct
95 Correct 666 ms 43976 KB Output is correct