답안 #20664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20664 2017-02-13T11:54:12 Z 우리OJ(#80, cki86201) 초음속철도 (OJUZ11_rail) C++14
100 / 100
579 ms 21532 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;

int n, m;
int xs[400040], xz;
Pi p[200020];

const int MOD = 1e9 + 7;

struct node{
	node(){sum = 0, C = 1;}
	ll sum, C;
}T[1<<20];

void add(int rt, int l, int r, int x, ll v){
	if(l == r){
		T[rt].sum = (T[rt].sum + v) % MOD;
		return;
	}
	if(T[rt].C != 1){
		T[rt<<1].C = (T[rt<<1].C * T[rt].C) % MOD;
		T[rt<<1|1].C = (T[rt<<1|1].C * T[rt].C) % MOD;
		T[rt<<1].sum = (T[rt<<1].sum * T[rt].C) % MOD;
		T[rt<<1|1].sum = (T[rt<<1|1].sum * T[rt].C) % MOD;
		T[rt].C = 1;
	}
	int m = (l + r) >> 1;
	if(x <= m)add(rt<<1, l, m, x, v);
	else add(rt<<1|1, m+1, r, x, v);
	T[rt].sum = (T[rt<<1].sum + T[rt<<1|1].sum) % MOD;
}

ll get_sum(int rt, int l,int r, int s, int d){
	if(s <= l && r <= d){
		return T[rt].sum;
	}
	if(T[rt].C != 1){
		T[rt<<1].C = (T[rt<<1].C * T[rt].C) % MOD;
		T[rt<<1|1].C = (T[rt<<1|1].C * T[rt].C) % MOD;
		T[rt<<1].sum = (T[rt<<1].sum * T[rt].C) % MOD;
		T[rt<<1|1].sum = (T[rt<<1|1].sum * T[rt].C) % MOD;
		T[rt].C = 1;
	}
	int m = (l + r) >> 1;
	ll res = 0;
	if(s <= m)res += get_sum(rt<<1, l, m, s, d);
	if(m < d)res += get_sum(rt<<1|1, m+1, r, s, d);
	return res % MOD;
}

void mul2(int rt, int l, int r, int s, int d){
	if(s <= l && r <= d){
		T[rt].sum = (T[rt].sum + T[rt].sum) % MOD;
		T[rt].C = (T[rt].C + T[rt].C) % MOD;
		return;
	}
	if(T[rt].C != 1){
		T[rt<<1].C = (T[rt<<1].C * T[rt].C) % MOD;
		T[rt<<1|1].C = (T[rt<<1|1].C * T[rt].C) % MOD;
		T[rt<<1].sum = (T[rt<<1].sum * T[rt].C) % MOD;
		T[rt<<1|1].sum = (T[rt<<1|1].sum * T[rt].C) % MOD;
		T[rt].C = 1;
	}
	int m = (l + r) >> 1;
	if(s <= m)mul2(rt<<1, l, m, s, d);
	if(m < d)mul2(rt<<1|1, m+1, r, s, d);
	T[rt].sum = (T[rt<<1].sum + T[rt<<1|1].sum) % MOD;
}

void solve(){
	scanf("%d%d", &n, &m);
	for(int i=1;i<=m;i++){
		int s, e;
		scanf("%d%d", &s, &e);
		p[i] = Pi(s, e);
		xs[xz++] = s, xs[xz++] = e;
	}
	xs[xz++] = 1; xs[xz++] = n;
	sort(xs, xs + xz);
	xz = (int)(unique(xs, xs + xz) - xs);
	for(int i=1;i<=m;i++){
		p[i].Fi = (int)(lower_bound(xs, xs + xz, p[i].Fi) - xs) + 1;
		p[i].Se = (int)(lower_bound(xs, xs + xz, p[i].Se) - xs) + 1;
	}
	add(1, 1, xz, 1, 1);
	sort(p+1, p+1+m);
	for(int i=1;i<=m;i++){
		int l = p[i].Fi, r = p[i].Se;
		if(l != 1)mul2(1, 1, xz, 1, l-1);
		if(r != xz)mul2(1, 1, xz, r+1, xz);
		ll s = get_sum(1, 1, xz, l, r);
		add(1, 1, xz, r, s);
	}
	printf("%lld\n", get_sum(1, 1, xz, xz, xz));
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Compilation message

rail.cpp: In function 'void solve()':
rail.cpp:100:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
rail.cpp:103:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &s, &e);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21532 KB Output is correct
2 Correct 6 ms 21532 KB Output is correct
3 Correct 3 ms 21532 KB Output is correct
4 Correct 6 ms 21532 KB Output is correct
5 Correct 0 ms 21532 KB Output is correct
6 Correct 0 ms 21532 KB Output is correct
7 Correct 0 ms 21532 KB Output is correct
8 Correct 0 ms 21532 KB Output is correct
9 Correct 0 ms 21532 KB Output is correct
10 Correct 0 ms 21532 KB Output is correct
11 Correct 3 ms 21532 KB Output is correct
12 Correct 0 ms 21532 KB Output is correct
13 Correct 0 ms 21532 KB Output is correct
14 Correct 3 ms 21532 KB Output is correct
15 Correct 0 ms 21532 KB Output is correct
16 Correct 3 ms 21532 KB Output is correct
17 Correct 3 ms 21532 KB Output is correct
18 Correct 3 ms 21532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21532 KB Output is correct
2 Correct 6 ms 21532 KB Output is correct
3 Correct 3 ms 21532 KB Output is correct
4 Correct 6 ms 21532 KB Output is correct
5 Correct 0 ms 21532 KB Output is correct
6 Correct 0 ms 21532 KB Output is correct
7 Correct 0 ms 21532 KB Output is correct
8 Correct 0 ms 21532 KB Output is correct
9 Correct 0 ms 21532 KB Output is correct
10 Correct 0 ms 21532 KB Output is correct
11 Correct 3 ms 21532 KB Output is correct
12 Correct 0 ms 21532 KB Output is correct
13 Correct 0 ms 21532 KB Output is correct
14 Correct 3 ms 21532 KB Output is correct
15 Correct 0 ms 21532 KB Output is correct
16 Correct 3 ms 21532 KB Output is correct
17 Correct 3 ms 21532 KB Output is correct
18 Correct 3 ms 21532 KB Output is correct
19 Correct 3 ms 21532 KB Output is correct
20 Correct 0 ms 21532 KB Output is correct
21 Correct 0 ms 21532 KB Output is correct
22 Correct 3 ms 21532 KB Output is correct
23 Correct 0 ms 21532 KB Output is correct
24 Correct 3 ms 21532 KB Output is correct
25 Correct 0 ms 21532 KB Output is correct
26 Correct 3 ms 21532 KB Output is correct
27 Correct 3 ms 21532 KB Output is correct
28 Correct 0 ms 21532 KB Output is correct
29 Correct 3 ms 21532 KB Output is correct
30 Correct 0 ms 21532 KB Output is correct
31 Correct 0 ms 21532 KB Output is correct
32 Correct 0 ms 21532 KB Output is correct
33 Correct 0 ms 21532 KB Output is correct
34 Correct 0 ms 21532 KB Output is correct
35 Correct 0 ms 21532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21532 KB Output is correct
2 Correct 3 ms 21532 KB Output is correct
3 Correct 0 ms 21532 KB Output is correct
4 Correct 6 ms 21532 KB Output is correct
5 Correct 226 ms 21532 KB Output is correct
6 Correct 389 ms 21532 KB Output is correct
7 Correct 376 ms 21532 KB Output is correct
8 Correct 0 ms 21532 KB Output is correct
9 Correct 359 ms 21532 KB Output is correct
10 Correct 376 ms 21532 KB Output is correct
11 Correct 136 ms 21532 KB Output is correct
12 Correct 399 ms 21532 KB Output is correct
13 Correct 386 ms 21532 KB Output is correct
14 Correct 73 ms 21532 KB Output is correct
15 Correct 389 ms 21532 KB Output is correct
16 Correct 73 ms 21532 KB Output is correct
17 Correct 376 ms 21532 KB Output is correct
18 Correct 386 ms 21532 KB Output is correct
19 Correct 396 ms 21532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21532 KB Output is correct
2 Correct 6 ms 21532 KB Output is correct
3 Correct 3 ms 21532 KB Output is correct
4 Correct 6 ms 21532 KB Output is correct
5 Correct 0 ms 21532 KB Output is correct
6 Correct 0 ms 21532 KB Output is correct
7 Correct 0 ms 21532 KB Output is correct
8 Correct 0 ms 21532 KB Output is correct
9 Correct 0 ms 21532 KB Output is correct
10 Correct 0 ms 21532 KB Output is correct
11 Correct 3 ms 21532 KB Output is correct
12 Correct 0 ms 21532 KB Output is correct
13 Correct 0 ms 21532 KB Output is correct
14 Correct 3 ms 21532 KB Output is correct
15 Correct 0 ms 21532 KB Output is correct
16 Correct 3 ms 21532 KB Output is correct
17 Correct 3 ms 21532 KB Output is correct
18 Correct 3 ms 21532 KB Output is correct
19 Correct 3 ms 21532 KB Output is correct
20 Correct 0 ms 21532 KB Output is correct
21 Correct 0 ms 21532 KB Output is correct
22 Correct 3 ms 21532 KB Output is correct
23 Correct 0 ms 21532 KB Output is correct
24 Correct 3 ms 21532 KB Output is correct
25 Correct 0 ms 21532 KB Output is correct
26 Correct 3 ms 21532 KB Output is correct
27 Correct 3 ms 21532 KB Output is correct
28 Correct 0 ms 21532 KB Output is correct
29 Correct 3 ms 21532 KB Output is correct
30 Correct 0 ms 21532 KB Output is correct
31 Correct 0 ms 21532 KB Output is correct
32 Correct 0 ms 21532 KB Output is correct
33 Correct 0 ms 21532 KB Output is correct
34 Correct 0 ms 21532 KB Output is correct
35 Correct 0 ms 21532 KB Output is correct
36 Correct 6 ms 21532 KB Output is correct
37 Correct 9 ms 21532 KB Output is correct
38 Correct 6 ms 21532 KB Output is correct
39 Correct 0 ms 21532 KB Output is correct
40 Correct 9 ms 21532 KB Output is correct
41 Correct 9 ms 21532 KB Output is correct
42 Correct 9 ms 21532 KB Output is correct
43 Correct 0 ms 21532 KB Output is correct
44 Correct 13 ms 21532 KB Output is correct
45 Correct 3 ms 21532 KB Output is correct
46 Correct 6 ms 21532 KB Output is correct
47 Correct 6 ms 21532 KB Output is correct
48 Correct 6 ms 21532 KB Output is correct
49 Correct 3 ms 21532 KB Output is correct
50 Correct 6 ms 21532 KB Output is correct
51 Correct 3 ms 21532 KB Output is correct
52 Correct 6 ms 21532 KB Output is correct
53 Correct 13 ms 21532 KB Output is correct
54 Correct 6 ms 21532 KB Output is correct
55 Correct 9 ms 21532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21532 KB Output is correct
2 Correct 6 ms 21532 KB Output is correct
3 Correct 3 ms 21532 KB Output is correct
4 Correct 6 ms 21532 KB Output is correct
5 Correct 0 ms 21532 KB Output is correct
6 Correct 0 ms 21532 KB Output is correct
7 Correct 0 ms 21532 KB Output is correct
8 Correct 0 ms 21532 KB Output is correct
9 Correct 0 ms 21532 KB Output is correct
10 Correct 0 ms 21532 KB Output is correct
11 Correct 3 ms 21532 KB Output is correct
12 Correct 0 ms 21532 KB Output is correct
13 Correct 0 ms 21532 KB Output is correct
14 Correct 3 ms 21532 KB Output is correct
15 Correct 0 ms 21532 KB Output is correct
16 Correct 3 ms 21532 KB Output is correct
17 Correct 3 ms 21532 KB Output is correct
18 Correct 3 ms 21532 KB Output is correct
19 Correct 3 ms 21532 KB Output is correct
20 Correct 0 ms 21532 KB Output is correct
21 Correct 0 ms 21532 KB Output is correct
22 Correct 3 ms 21532 KB Output is correct
23 Correct 0 ms 21532 KB Output is correct
24 Correct 3 ms 21532 KB Output is correct
25 Correct 0 ms 21532 KB Output is correct
26 Correct 3 ms 21532 KB Output is correct
27 Correct 3 ms 21532 KB Output is correct
28 Correct 0 ms 21532 KB Output is correct
29 Correct 3 ms 21532 KB Output is correct
30 Correct 0 ms 21532 KB Output is correct
31 Correct 0 ms 21532 KB Output is correct
32 Correct 0 ms 21532 KB Output is correct
33 Correct 0 ms 21532 KB Output is correct
34 Correct 0 ms 21532 KB Output is correct
35 Correct 0 ms 21532 KB Output is correct
36 Correct 3 ms 21532 KB Output is correct
37 Correct 3 ms 21532 KB Output is correct
38 Correct 0 ms 21532 KB Output is correct
39 Correct 6 ms 21532 KB Output is correct
40 Correct 226 ms 21532 KB Output is correct
41 Correct 389 ms 21532 KB Output is correct
42 Correct 376 ms 21532 KB Output is correct
43 Correct 0 ms 21532 KB Output is correct
44 Correct 359 ms 21532 KB Output is correct
45 Correct 376 ms 21532 KB Output is correct
46 Correct 136 ms 21532 KB Output is correct
47 Correct 399 ms 21532 KB Output is correct
48 Correct 386 ms 21532 KB Output is correct
49 Correct 73 ms 21532 KB Output is correct
50 Correct 389 ms 21532 KB Output is correct
51 Correct 73 ms 21532 KB Output is correct
52 Correct 376 ms 21532 KB Output is correct
53 Correct 386 ms 21532 KB Output is correct
54 Correct 396 ms 21532 KB Output is correct
55 Correct 6 ms 21532 KB Output is correct
56 Correct 9 ms 21532 KB Output is correct
57 Correct 6 ms 21532 KB Output is correct
58 Correct 0 ms 21532 KB Output is correct
59 Correct 9 ms 21532 KB Output is correct
60 Correct 9 ms 21532 KB Output is correct
61 Correct 9 ms 21532 KB Output is correct
62 Correct 0 ms 21532 KB Output is correct
63 Correct 13 ms 21532 KB Output is correct
64 Correct 3 ms 21532 KB Output is correct
65 Correct 6 ms 21532 KB Output is correct
66 Correct 6 ms 21532 KB Output is correct
67 Correct 6 ms 21532 KB Output is correct
68 Correct 3 ms 21532 KB Output is correct
69 Correct 6 ms 21532 KB Output is correct
70 Correct 3 ms 21532 KB Output is correct
71 Correct 6 ms 21532 KB Output is correct
72 Correct 13 ms 21532 KB Output is correct
73 Correct 6 ms 21532 KB Output is correct
74 Correct 9 ms 21532 KB Output is correct
75 Correct 569 ms 21532 KB Output is correct
76 Correct 349 ms 21532 KB Output is correct
77 Correct 266 ms 21532 KB Output is correct
78 Correct 66 ms 21532 KB Output is correct
79 Correct 399 ms 21532 KB Output is correct
80 Correct 553 ms 21532 KB Output is correct
81 Correct 6 ms 21532 KB Output is correct
82 Correct 496 ms 21532 KB Output is correct
83 Correct 53 ms 21532 KB Output is correct
84 Correct 416 ms 21532 KB Output is correct
85 Correct 463 ms 21532 KB Output is correct
86 Correct 466 ms 21532 KB Output is correct
87 Correct 133 ms 21532 KB Output is correct
88 Correct 143 ms 21532 KB Output is correct
89 Correct 559 ms 21532 KB Output is correct
90 Correct 556 ms 21532 KB Output is correct
91 Correct 579 ms 21532 KB Output is correct
92 Correct 509 ms 21532 KB Output is correct
93 Correct 469 ms 21532 KB Output is correct
94 Correct 576 ms 21532 KB Output is correct
95 Correct 553 ms 21532 KB Output is correct