답안 #792856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792856 2023-07-25T09:58:56 Z IvanJ Boat (APIO16_boat) C++17
31 / 100
2000 ms 49720 KB
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 505;
const int MOD = 1e9 + 7;

int mult(ll x, ll y) {return x * y % MOD;}
int add(int x, int y) {x += y;if(x >= MOD) x -= MOD;return x;}
int sub(int x, int y) {x -= y;if(x < 0) x += MOD;return x;}

struct Seg {
	int sz;
	vector<int> dp, L;
	vector<ii> nxt;
	
	void init() {
		sz = 1;
		dp.pb(0), L.pb(0);
		nxt.pb({-1, -1});
	}
	
	void expand(int x) {
		if(nxt[x].x == -1) {
			nxt[x].x = sz++;
			dp.pb(0), L.pb(0), nxt.pb({-1, -1});
		} 
		if(nxt[x].y == -1) {
			nxt[x].y = sz++;
			dp.pb(0), L.pb(0), nxt.pb({-1, -1});
		}
	}
	
	void prop(int x, int lo, int hi) {
		if(lo < hi) expand(x);
		dp[x] = add(dp[x], mult(L[x], hi - lo + 1));
		if(lo < hi) {
			L[nxt[x].x] = add(L[nxt[x].x], L[x]);
			L[nxt[x].y] = add(L[nxt[x].y], L[x]);
		}
		L[x] = 0;
	}
	
	int query(int x, int lo, int hi, int a, int b) {
		prop(x, lo, hi);
		if(hi < a || b < lo) return 0;
		if(a <= lo && hi <= b) return dp[x];
		int mid = (lo + hi) / 2;
		expand(x);
		int l = query(nxt[x].x, lo, mid, a, b);
		int r = query(nxt[x].y, mid + 1, hi, a, b);
		return add(l, r);
	}
	
	void update(int x, int lo, int hi, int a, int b, int v) {
		prop(x, lo, hi);
		if(hi < a || b < lo) return;
		if(a <= lo && hi <= b) {
			L[x] = add(L[x], v);
			prop(x, lo, hi);
			return;
		}
		int mid = (lo + hi) / 2;
		expand(x);
		update(nxt[x].x, lo, mid, a, b, v);
		update(nxt[x].y, mid + 1, hi, a, b, v);
		dp[x] = add(dp[nxt[x].x], dp[nxt[x].y]);
	}
	
	int get(int x) {return query(0, 0, 1e9, 0, x);}
	void upd(int lo, int hi, int v) {update(0, 0, 1e9, lo, hi, v);}
};

int n;
int a[maxn], b[maxn];

int main() {
	scanf("%d", &n);
	for(int i = 0;i < n;i++) 
		scanf("%d%d", a + i, b + i);
	
	Seg S;
	S.init();
	S.upd(0, 0, 1);
	S.upd(a[0], b[0], 1);

	for(int i = 1;i < n;i++) {
		for(int j = b[i];j >= a[i];j--)
			S.upd(j, j, S.get(j - 1));
	}
	
	int ans = S.get(1e9);
	ans = sub(ans, 1);
	printf("%d\n", ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%d%d", a + i, b + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1204 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1248 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1208 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1204 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1248 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1208 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1299 ms 612 KB Output is correct
22 Correct 1269 ms 612 KB Output is correct
23 Correct 1207 ms 616 KB Output is correct
24 Correct 1321 ms 616 KB Output is correct
25 Correct 1328 ms 596 KB Output is correct
26 Correct 1441 ms 484 KB Output is correct
27 Correct 1446 ms 592 KB Output is correct
28 Correct 1414 ms 496 KB Output is correct
29 Correct 1440 ms 484 KB Output is correct
30 Correct 1514 ms 31420 KB Output is correct
31 Correct 1475 ms 30824 KB Output is correct
32 Correct 1514 ms 31300 KB Output is correct
33 Correct 1474 ms 30600 KB Output is correct
34 Correct 1495 ms 30852 KB Output is correct
35 Correct 1412 ms 29312 KB Output is correct
36 Correct 1469 ms 30544 KB Output is correct
37 Correct 1505 ms 30732 KB Output is correct
38 Correct 1494 ms 29788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2063 ms 49720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1204 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1248 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1208 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1299 ms 612 KB Output is correct
22 Correct 1269 ms 612 KB Output is correct
23 Correct 1207 ms 616 KB Output is correct
24 Correct 1321 ms 616 KB Output is correct
25 Correct 1328 ms 596 KB Output is correct
26 Correct 1441 ms 484 KB Output is correct
27 Correct 1446 ms 592 KB Output is correct
28 Correct 1414 ms 496 KB Output is correct
29 Correct 1440 ms 484 KB Output is correct
30 Correct 1514 ms 31420 KB Output is correct
31 Correct 1475 ms 30824 KB Output is correct
32 Correct 1514 ms 31300 KB Output is correct
33 Correct 1474 ms 30600 KB Output is correct
34 Correct 1495 ms 30852 KB Output is correct
35 Correct 1412 ms 29312 KB Output is correct
36 Correct 1469 ms 30544 KB Output is correct
37 Correct 1505 ms 30732 KB Output is correct
38 Correct 1494 ms 29788 KB Output is correct
39 Execution timed out 2063 ms 49720 KB Time limit exceeded
40 Halted 0 ms 0 KB -