Submission #20832

# Submission time Handle Problem Language Result Execution time Memory
20832 2017-02-24T07:45:14 Z Namnamseo 초음속철도 (OJUZ11_rail) C++14
100 / 100
773 ms 44224 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back

pp data[200010];
int n;
vector<int> xp;

void in(){
	int p;
	read(p); xp.pb(1); xp.pb(p);
	read(n);
	for(int i=1; i<=n; ++i){
		int a, b; read(a, b);
		xp.pb(a); xp.pb(b); data[i]=pp{a, b};
	}
}

int xn;

void cc(){
	sort(all(xp));
	xp.erase(unique(all(xp)), xp.end());
	for(int i=1; i<=n; ++i){
		int a, b; tie(a, b) = data[i];
		a = lower_bound(all(xp), a) - xp.begin();
		b = lower_bound(all(xp), b) - xp.begin();
		data[i] = pp{a, b};
	}
	xn = xp.size();
}

const ll M=1'000'000'007;
const ll inv2=(M+1)/2;
ll dp[200010];
ll p2[400010];

auto rcmp = [](const pp& a, const pp& b){ return a.second < b.second; };

struct SEG {
	static const int T=524288;
	ll tsum[T<<1];
	ll tdp [T<<1];
	ll ttwo[T<<1];
	ll lazy[T<<1];
	void init(){
		for(auto& x:ttwo) x=1;
		for(auto& x:lazy) x=1;
	}
	void pd(int l, int r, int p){
		if(l==r || lazy[p]==1) return;
		for(int i=0; i<2; ++i){
			int x=p*2+i;
			tsum[x] = (tsum[x]*lazy[p])%M;
			ttwo[x] = (ttwo[x]*lazy[p])%M;
			lazy[x] = (lazy[x]*lazy[p])%M;
		}
		lazy[p]=1;
	}
	void divhalf(int l, int r, int ml=0, int mr=n, int p=1){
		pd(ml, mr, p);
		if(r<ml || mr<l) return;
		if(l<=ml && mr<=r){
			tsum[p] = (tsum[p]*inv2)%M;
			ttwo[p] = (ttwo[p]*inv2)%M;
			lazy[p] = inv2;
			return;
		}
		int mid=(ml+mr)/2;
		divhalf(l, r, ml, mid, p*2);
		divhalf(l, r, mid+1, mr, p*2+1);
		tsum[p]=(tsum[p*2]+tsum[p*2+1])%M;
	}
	ll rsum(int l, int r, int ml=0, int mr=n, int p=1){
		pd(ml, mr, p);
		if(r<ml || mr<l) return 0;
		if(l<=ml && mr<=r) return tsum[p];
		int mid=(ml+mr)/2;
		return rsum(l, r, ml, mid, p*2) + rsum(l, r, mid+1, mr, p*2+1);
	}
	void upd(int up, ll uv, int ml=0, int mr=n, int p=1){
		pd(ml, mr, p);
		if(up<ml || mr<up) return;
		if(ml==up && mr==up){
			tdp[p]=uv;
			tsum[p]=(tdp[p]*ttwo[p])%M;
			return;
		}
		int mid=(ml+mr)/2;
		upd(up, uv, ml, mid, p*2);
		upd(up, uv, mid+1, mr, p*2+1);
		tsum[p]=(tsum[p*2]+tsum[p*2+1])%M;
	}
} seg;

int main()
{
	//freopen("in", "r", stdin);
    in(); cc();
    
    p2[0]=1; for(int i=1; i<=400000; ++i) p2[i]=(p2[i-1]*2)%M;
    
    sort(data+1, data+n+1, rcmp);
    
    seg.init();
    dp[0]=1; seg.upd(0, 1);
    
    for(int i=1; i<=n; ++i){
		int a, b; tie(a, b) = data[i];
		int last = lower_bound(data, data+n+1, pp{0, a}, rcmp)-data-1;
		ll invdp = seg.rsum(0, last);
		invdp = (invdp * p2[i-1])%M;
		dp[i] = (p2[i-1]-invdp+M)%M;
		seg.divhalf(last+1, n);
		seg.upd(i, dp[i]);
    }
    
    ll ans=0;
    for(int i=1; i<=n; ++i) if(data[i].second == xn-1) ans = (ans+dp[i])%M;
    printf("%lld\n", ans);
    return 0;
}

Compilation message

rail.cpp: In function 'void read(int&)':
rail.cpp:5:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 41068 KB Output is correct
2 Correct 6 ms 41068 KB Output is correct
3 Correct 3 ms 41068 KB Output is correct
4 Correct 6 ms 41068 KB Output is correct
5 Correct 3 ms 41068 KB Output is correct
6 Correct 3 ms 41068 KB Output is correct
7 Correct 6 ms 41068 KB Output is correct
8 Correct 13 ms 41068 KB Output is correct
9 Correct 3 ms 41068 KB Output is correct
10 Correct 3 ms 41068 KB Output is correct
11 Correct 0 ms 41068 KB Output is correct
12 Correct 0 ms 41068 KB Output is correct
13 Correct 3 ms 41068 KB Output is correct
14 Correct 6 ms 41068 KB Output is correct
15 Correct 0 ms 41068 KB Output is correct
16 Correct 3 ms 41068 KB Output is correct
17 Correct 0 ms 41068 KB Output is correct
18 Correct 3 ms 41068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 41068 KB Output is correct
2 Correct 6 ms 41068 KB Output is correct
3 Correct 3 ms 41068 KB Output is correct
4 Correct 6 ms 41068 KB Output is correct
5 Correct 3 ms 41068 KB Output is correct
6 Correct 3 ms 41068 KB Output is correct
7 Correct 6 ms 41068 KB Output is correct
8 Correct 13 ms 41068 KB Output is correct
9 Correct 3 ms 41068 KB Output is correct
10 Correct 3 ms 41068 KB Output is correct
11 Correct 0 ms 41068 KB Output is correct
12 Correct 0 ms 41068 KB Output is correct
13 Correct 3 ms 41068 KB Output is correct
14 Correct 6 ms 41068 KB Output is correct
15 Correct 0 ms 41068 KB Output is correct
16 Correct 3 ms 41068 KB Output is correct
17 Correct 0 ms 41068 KB Output is correct
18 Correct 3 ms 41068 KB Output is correct
19 Correct 6 ms 41068 KB Output is correct
20 Correct 13 ms 41068 KB Output is correct
21 Correct 3 ms 41068 KB Output is correct
22 Correct 6 ms 41068 KB Output is correct
23 Correct 0 ms 41068 KB Output is correct
24 Correct 3 ms 41068 KB Output is correct
25 Correct 3 ms 41068 KB Output is correct
26 Correct 3 ms 41068 KB Output is correct
27 Correct 3 ms 41068 KB Output is correct
28 Correct 6 ms 41068 KB Output is correct
29 Correct 6 ms 41068 KB Output is correct
30 Correct 3 ms 41068 KB Output is correct
31 Correct 0 ms 41068 KB Output is correct
32 Correct 0 ms 41068 KB Output is correct
33 Correct 0 ms 41068 KB Output is correct
34 Correct 6 ms 41068 KB Output is correct
35 Correct 9 ms 41068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 41068 KB Output is correct
2 Correct 6 ms 41068 KB Output is correct
3 Correct 3 ms 41068 KB Output is correct
4 Correct 6 ms 41208 KB Output is correct
5 Correct 423 ms 44224 KB Output is correct
6 Correct 379 ms 44224 KB Output is correct
7 Correct 389 ms 44224 KB Output is correct
8 Correct 9 ms 41068 KB Output is correct
9 Correct 356 ms 44224 KB Output is correct
10 Correct 369 ms 44224 KB Output is correct
11 Correct 196 ms 42688 KB Output is correct
12 Correct 413 ms 44224 KB Output is correct
13 Correct 423 ms 44224 KB Output is correct
14 Correct 303 ms 44224 KB Output is correct
15 Correct 403 ms 44224 KB Output is correct
16 Correct 309 ms 44224 KB Output is correct
17 Correct 389 ms 44224 KB Output is correct
18 Correct 399 ms 44224 KB Output is correct
19 Correct 419 ms 44224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 41068 KB Output is correct
2 Correct 6 ms 41068 KB Output is correct
3 Correct 3 ms 41068 KB Output is correct
4 Correct 6 ms 41068 KB Output is correct
5 Correct 3 ms 41068 KB Output is correct
6 Correct 3 ms 41068 KB Output is correct
7 Correct 6 ms 41068 KB Output is correct
8 Correct 13 ms 41068 KB Output is correct
9 Correct 3 ms 41068 KB Output is correct
10 Correct 3 ms 41068 KB Output is correct
11 Correct 0 ms 41068 KB Output is correct
12 Correct 0 ms 41068 KB Output is correct
13 Correct 3 ms 41068 KB Output is correct
14 Correct 6 ms 41068 KB Output is correct
15 Correct 0 ms 41068 KB Output is correct
16 Correct 3 ms 41068 KB Output is correct
17 Correct 0 ms 41068 KB Output is correct
18 Correct 3 ms 41068 KB Output is correct
19 Correct 6 ms 41068 KB Output is correct
20 Correct 13 ms 41068 KB Output is correct
21 Correct 3 ms 41068 KB Output is correct
22 Correct 6 ms 41068 KB Output is correct
23 Correct 0 ms 41068 KB Output is correct
24 Correct 3 ms 41068 KB Output is correct
25 Correct 3 ms 41068 KB Output is correct
26 Correct 3 ms 41068 KB Output is correct
27 Correct 3 ms 41068 KB Output is correct
28 Correct 6 ms 41068 KB Output is correct
29 Correct 6 ms 41068 KB Output is correct
30 Correct 3 ms 41068 KB Output is correct
31 Correct 0 ms 41068 KB Output is correct
32 Correct 0 ms 41068 KB Output is correct
33 Correct 0 ms 41068 KB Output is correct
34 Correct 6 ms 41068 KB Output is correct
35 Correct 9 ms 41068 KB Output is correct
36 Correct 16 ms 41208 KB Output is correct
37 Correct 16 ms 41208 KB Output is correct
38 Correct 9 ms 41208 KB Output is correct
39 Correct 9 ms 41208 KB Output is correct
40 Correct 13 ms 41208 KB Output is correct
41 Correct 16 ms 41208 KB Output is correct
42 Correct 9 ms 41208 KB Output is correct
43 Correct 0 ms 41068 KB Output is correct
44 Correct 16 ms 41208 KB Output is correct
45 Correct 13 ms 41208 KB Output is correct
46 Correct 9 ms 41208 KB Output is correct
47 Correct 13 ms 41208 KB Output is correct
48 Correct 19 ms 41208 KB Output is correct
49 Correct 9 ms 41208 KB Output is correct
50 Correct 13 ms 41208 KB Output is correct
51 Correct 13 ms 41208 KB Output is correct
52 Correct 6 ms 41068 KB Output is correct
53 Correct 19 ms 41208 KB Output is correct
54 Correct 6 ms 41208 KB Output is correct
55 Correct 19 ms 41208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 41068 KB Output is correct
2 Correct 6 ms 41068 KB Output is correct
3 Correct 3 ms 41068 KB Output is correct
4 Correct 6 ms 41068 KB Output is correct
5 Correct 3 ms 41068 KB Output is correct
6 Correct 3 ms 41068 KB Output is correct
7 Correct 6 ms 41068 KB Output is correct
8 Correct 13 ms 41068 KB Output is correct
9 Correct 3 ms 41068 KB Output is correct
10 Correct 3 ms 41068 KB Output is correct
11 Correct 0 ms 41068 KB Output is correct
12 Correct 0 ms 41068 KB Output is correct
13 Correct 3 ms 41068 KB Output is correct
14 Correct 6 ms 41068 KB Output is correct
15 Correct 0 ms 41068 KB Output is correct
16 Correct 3 ms 41068 KB Output is correct
17 Correct 0 ms 41068 KB Output is correct
18 Correct 3 ms 41068 KB Output is correct
19 Correct 6 ms 41068 KB Output is correct
20 Correct 13 ms 41068 KB Output is correct
21 Correct 3 ms 41068 KB Output is correct
22 Correct 6 ms 41068 KB Output is correct
23 Correct 0 ms 41068 KB Output is correct
24 Correct 3 ms 41068 KB Output is correct
25 Correct 3 ms 41068 KB Output is correct
26 Correct 3 ms 41068 KB Output is correct
27 Correct 3 ms 41068 KB Output is correct
28 Correct 6 ms 41068 KB Output is correct
29 Correct 6 ms 41068 KB Output is correct
30 Correct 3 ms 41068 KB Output is correct
31 Correct 0 ms 41068 KB Output is correct
32 Correct 0 ms 41068 KB Output is correct
33 Correct 0 ms 41068 KB Output is correct
34 Correct 6 ms 41068 KB Output is correct
35 Correct 9 ms 41068 KB Output is correct
36 Correct 3 ms 41068 KB Output is correct
37 Correct 6 ms 41068 KB Output is correct
38 Correct 3 ms 41068 KB Output is correct
39 Correct 6 ms 41208 KB Output is correct
40 Correct 423 ms 44224 KB Output is correct
41 Correct 379 ms 44224 KB Output is correct
42 Correct 389 ms 44224 KB Output is correct
43 Correct 9 ms 41068 KB Output is correct
44 Correct 356 ms 44224 KB Output is correct
45 Correct 369 ms 44224 KB Output is correct
46 Correct 196 ms 42688 KB Output is correct
47 Correct 413 ms 44224 KB Output is correct
48 Correct 423 ms 44224 KB Output is correct
49 Correct 303 ms 44224 KB Output is correct
50 Correct 403 ms 44224 KB Output is correct
51 Correct 309 ms 44224 KB Output is correct
52 Correct 389 ms 44224 KB Output is correct
53 Correct 399 ms 44224 KB Output is correct
54 Correct 419 ms 44224 KB Output is correct
55 Correct 16 ms 41208 KB Output is correct
56 Correct 16 ms 41208 KB Output is correct
57 Correct 9 ms 41208 KB Output is correct
58 Correct 9 ms 41208 KB Output is correct
59 Correct 13 ms 41208 KB Output is correct
60 Correct 16 ms 41208 KB Output is correct
61 Correct 9 ms 41208 KB Output is correct
62 Correct 0 ms 41068 KB Output is correct
63 Correct 16 ms 41208 KB Output is correct
64 Correct 13 ms 41208 KB Output is correct
65 Correct 9 ms 41208 KB Output is correct
66 Correct 13 ms 41208 KB Output is correct
67 Correct 19 ms 41208 KB Output is correct
68 Correct 9 ms 41208 KB Output is correct
69 Correct 13 ms 41208 KB Output is correct
70 Correct 13 ms 41208 KB Output is correct
71 Correct 6 ms 41068 KB Output is correct
72 Correct 19 ms 41208 KB Output is correct
73 Correct 6 ms 41208 KB Output is correct
74 Correct 19 ms 41208 KB Output is correct
75 Correct 773 ms 44224 KB Output is correct
76 Correct 446 ms 44224 KB Output is correct
77 Correct 623 ms 44224 KB Output is correct
78 Correct 399 ms 44224 KB Output is correct
79 Correct 689 ms 44224 KB Output is correct
80 Correct 756 ms 44224 KB Output is correct
81 Correct 13 ms 41208 KB Output is correct
82 Correct 726 ms 44224 KB Output is correct
83 Correct 273 ms 44224 KB Output is correct
84 Correct 613 ms 44224 KB Output is correct
85 Correct 659 ms 44224 KB Output is correct
86 Correct 603 ms 44224 KB Output is correct
87 Correct 439 ms 44224 KB Output is correct
88 Correct 443 ms 44224 KB Output is correct
89 Correct 773 ms 44224 KB Output is correct
90 Correct 729 ms 44224 KB Output is correct
91 Correct 726 ms 44224 KB Output is correct
92 Correct 649 ms 44224 KB Output is correct
93 Correct 659 ms 44224 KB Output is correct
94 Correct 696 ms 44224 KB Output is correct
95 Correct 723 ms 44224 KB Output is correct