Submission #744247

# Submission time Handle Problem Language Result Execution time Memory
744247 2023-05-18T09:57:47 Z b00norp Boat (APIO16_boat) C++14
31 / 100
2000 ms 455944 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18, N = 1e6 + 4, MOD = 1e9 + 7;
int seg[N * 4];

int add(int a, int b)
{
	a %= MOD;
	b %= MOD;
	int ans = (a + b) % MOD;
	return ans;
}

void Update(int l, int r, int pos, int qpos, int qval)
{
	if(l == r)
	{
		seg[pos] = add(seg[pos], qval);
		seg[pos] %= MOD;
		return;
	}
	int mid = (l + r) >> 1;
	if(qpos <= mid)
	{
		Update(l, mid, pos * 2, qpos, qval);
	}
	else
	{
		Update(mid + 1, r, pos * 2 + 1, qpos, qval);
	}
	seg[pos] = add(seg[pos * 2], seg[pos * 2 + 1]);
}

int Query(int l, int r, int pos, int ql, int qr)
{
	if(ql <= l && r <= qr)
	{
		return seg[pos];
	}
	if(ql > r || l > qr)
	{
		return 0;
	}
	int mid = (l + r) >> 1;
	return add(Query(l, mid, pos * 2, ql, qr), Query(mid + 1, r, pos * 2 + 1, ql, qr));
}

void Solve() 
{
	int n;
	cin >> n;
	vector<pair<int, int> > a(n);
	map<int, int> mp;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
		for(int j = a[i].first; j <= a[i].second; j++)
		{
			mp[j]++;
		}
	}
	int cnt = 1;
	for(auto i: mp)
	{
		mp[i.first] = cnt++;
	}
	for(int i = 0; i < n; i++)
	{
		a[i].first = mp[a[i].first];
		a[i].second = mp[a[i].second];
	}
	Update(0, N, 1, 0, 1);
	for(int i = 0; i < n; i++)
	{
		for(int j = a[i].second; j >= a[i].first; j--)
		{
			int val = Query(0, N, 1, 0, j - 1);
			Update(0, N, 1, j, val);
		}
	}
	// cout << Query(0, N, 1, 1, 1) << " -> ans for 1\n";
	// cout << Query(0, N, 1, 2, 2) << " -> ans for 2\n";
	// cout << Query(0, N, 1, 3, 3) << " -> ans for 3\n";
	cout << (Query(0, N, 1, 1, N)) % MOD << "\n";
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 406 ms 796 KB Output is correct
22 Correct 438 ms 804 KB Output is correct
23 Correct 397 ms 796 KB Output is correct
24 Correct 435 ms 792 KB Output is correct
25 Correct 422 ms 796 KB Output is correct
26 Correct 445 ms 796 KB Output is correct
27 Correct 456 ms 584 KB Output is correct
28 Correct 497 ms 696 KB Output is correct
29 Correct 471 ms 692 KB Output is correct
30 Correct 786 ms 78424 KB Output is correct
31 Correct 737 ms 77020 KB Output is correct
32 Correct 757 ms 78496 KB Output is correct
33 Correct 764 ms 76408 KB Output is correct
34 Correct 821 ms 77096 KB Output is correct
35 Correct 650 ms 73772 KB Output is correct
36 Correct 637 ms 76232 KB Output is correct
37 Correct 688 ms 76968 KB Output is correct
38 Correct 659 ms 74460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2056 ms 455944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 406 ms 796 KB Output is correct
22 Correct 438 ms 804 KB Output is correct
23 Correct 397 ms 796 KB Output is correct
24 Correct 435 ms 792 KB Output is correct
25 Correct 422 ms 796 KB Output is correct
26 Correct 445 ms 796 KB Output is correct
27 Correct 456 ms 584 KB Output is correct
28 Correct 497 ms 696 KB Output is correct
29 Correct 471 ms 692 KB Output is correct
30 Correct 786 ms 78424 KB Output is correct
31 Correct 737 ms 77020 KB Output is correct
32 Correct 757 ms 78496 KB Output is correct
33 Correct 764 ms 76408 KB Output is correct
34 Correct 821 ms 77096 KB Output is correct
35 Correct 650 ms 73772 KB Output is correct
36 Correct 637 ms 76232 KB Output is correct
37 Correct 688 ms 76968 KB Output is correct
38 Correct 659 ms 74460 KB Output is correct
39 Execution timed out 2056 ms 455944 KB Time limit exceeded
40 Halted 0 ms 0 KB -