답안 #105253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105253 2019-04-11T04:28:54 Z Just_Solve_The_Problem Bitaro, who Leaps through Time (JOI19_timeleap) C++11
100 / 100
1186 ms 68832 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define ll long long

using namespace std;

const int N = (int)3e5 + 7;

int n, q;
pair<int, int> ar[N];

struct node {
	ll l, r, cost, to;
	node() {
		l = -1e18;
		r = 1e18;
		cost = -1;
		to = 0;
	}
	node(ll _l, ll _r, ll _cost, ll _to) {
		l = _l;
		r = _r;
		cost = _cost;
		to = _to;
	}
};

node merge(node a, node b) {
	if (a.cost != -1) {
		a.cost += max(a.to - b.r, 0LL);
		a.to = max(b.l, min(a.to, b.r));
		if (b.cost != -1) {
			a.to = b.to;
			a.cost += b.cost;
		}
	} else if (a.l > b.r) {
		a = {a.l, a.l, a.l - b.r, b.r};
		if (b.cost != -1) {
			a.to = b.to;
			a.cost += b.cost;
		}
	} else if (a.r < b.l) {
		a = {a.r, a.r, 0, b.l};
		if (b.cost != -1) {
			a.to = b.to;
			a.cost += b.cost;
		}
	} else if (b.cost != -1) {
		a = b;
	} else {
		a.l = max(a.l, b.l);
		a.r = min(a.r, b.r);
	}
	return a;
}
node tree[N * 4];

void upd(int pos, node val, int v = 1, int l = 1, int r = n) {
	if (l == r) {
		tree[v] = val;
		return ;
	}
	int mid = (l + r) >> 1;
	if (pos <= mid) {
		upd(pos, val, v + v, l, mid);
	} else {
		upd(pos, val, v + v + 1, mid + 1, r);
	}
	tree[v] = merge(tree[v + v], tree[v + v + 1]);
}

node get(int l, int r, int v = 1, int tl = 1, int tr = n) {
	if (tl > r || tr < l) return node();
	if (l <= tl && tr <= r) return tree[v];
	int mid = (tl + tr) >> 1;
	return merge(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
}

int A[N], B[N], C[N], D[N], tp[N];
ll ans[N];

main() {
	scanf("%d %d", &n, &q);
	for (int i = 1; i < n; i++) {
		scanf("%d %d", &ar[i].fr, &ar[i].sc);
		upd(i, node(ar[i].fr - i, ar[i].sc - i - 1, -1, 0));
	}
	for (int i = 1; i <= q; i++) {
		scanf("%d", &tp[i]);
		if (tp[i] == 1) {
			scanf("%d %d %d", &A[i], &B[i], &C[i]);
			upd(A[i], node(B[i] - A[i], C[i] - A[i] - 1, -1, 0));
 		} else {
			scanf("%d %d %d %d", &A[i], &B[i], &C[i], &D[i]);
			if (A[i] > C[i]) continue;
			B[i] -= A[i];
			D[i] -= C[i];
			if (A[i] == C[i]) {
				ans[i] = max(B[i] - D[i], 0);
				B[i] += A[i];
				D[i] += C[i];
				continue;
			}
			//node asd = get(A[i], C[i] - 1);
			//cout << asd.l << ' ' << asd.r << ' ' << asd.cost << ' ' << asd.to << '\n';
			ans[i] = merge(node(B[i], B[i], 0, B[i]), merge(get(A[i], C[i] - 1), node(D[i], D[i], 0, D[i]))).cost;
			B[i] += A[i];
			D[i] += C[i];
 		}
	}
	for (int i = 1; i < n; i++) {
		upd(n - i, node(ar[i].fr + i + 1, ar[i].sc + i, -1, 0));
	}
	for (int i = 1; i <= q; i++) {
		if (tp[i] == 1) {
			upd(n - A[i], node(B[i] + A[i] + 1, C[i] + A[i], -1, 0));
		} else {
			if (A[i] <= C[i]) continue;
			B[i] += A[i];
			D[i] += C[i];
			//node asd = get(n - A[i] + 1, n - C[i]);
			//cout << asd.l << ' ' << asd.r << ' ' << asd.cost << ' ' << asd.to << '\n';
			ans[i] = merge(node(B[i], B[i], 0, B[i]), merge(get(n - A[i] + 1, n - C[i]), node(D[i], D[i], 0, D[i]))).cost;
		}
	}
	for (int i = 1; i <= q; i++) {
		if (tp[i] == 2) {
			printf("%lld\n", ans[i]);
		}
	}
}

Compilation message

timeleap.cpp:84:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
timeleap.cpp: In function 'int main()':
timeleap.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~~
timeleap.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &ar[i].fr, &ar[i].sc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &tp[i]);
   ~~~~~^~~~~~~~~~~~~~
timeleap.cpp:93:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d %d", &A[i], &B[i], &C[i]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:96:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d %d %d", &A[i], &B[i], &C[i], &D[i]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 38016 KB Output is correct
2 Correct 30 ms 37916 KB Output is correct
3 Correct 32 ms 37880 KB Output is correct
4 Correct 35 ms 38008 KB Output is correct
5 Correct 30 ms 37880 KB Output is correct
6 Correct 38 ms 37880 KB Output is correct
7 Correct 33 ms 38008 KB Output is correct
8 Correct 35 ms 37880 KB Output is correct
9 Correct 32 ms 37888 KB Output is correct
10 Correct 35 ms 37880 KB Output is correct
11 Correct 38 ms 38008 KB Output is correct
12 Correct 32 ms 38008 KB Output is correct
13 Correct 32 ms 38008 KB Output is correct
14 Correct 37 ms 37980 KB Output is correct
15 Correct 35 ms 38012 KB Output is correct
16 Correct 42 ms 38008 KB Output is correct
17 Correct 36 ms 38008 KB Output is correct
18 Correct 36 ms 38008 KB Output is correct
19 Correct 37 ms 38008 KB Output is correct
20 Correct 40 ms 38008 KB Output is correct
21 Correct 38 ms 38008 KB Output is correct
22 Correct 34 ms 38008 KB Output is correct
23 Correct 32 ms 38008 KB Output is correct
24 Correct 35 ms 38008 KB Output is correct
25 Correct 33 ms 38008 KB Output is correct
26 Correct 32 ms 38008 KB Output is correct
27 Correct 34 ms 38008 KB Output is correct
28 Correct 38 ms 38008 KB Output is correct
29 Correct 37 ms 38064 KB Output is correct
30 Correct 33 ms 38008 KB Output is correct
31 Correct 33 ms 38016 KB Output is correct
32 Correct 35 ms 38008 KB Output is correct
33 Correct 34 ms 38008 KB Output is correct
34 Correct 35 ms 37928 KB Output is correct
35 Correct 33 ms 38008 KB Output is correct
36 Correct 33 ms 38008 KB Output is correct
37 Correct 36 ms 37976 KB Output is correct
38 Correct 33 ms 38016 KB Output is correct
39 Correct 34 ms 38008 KB Output is correct
40 Correct 32 ms 37964 KB Output is correct
41 Correct 31 ms 37968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1182 ms 52520 KB Output is correct
2 Correct 1133 ms 67656 KB Output is correct
3 Correct 1075 ms 67764 KB Output is correct
4 Correct 1058 ms 67492 KB Output is correct
5 Correct 1008 ms 68216 KB Output is correct
6 Correct 1044 ms 67884 KB Output is correct
7 Correct 1037 ms 67960 KB Output is correct
8 Correct 1186 ms 68708 KB Output is correct
9 Correct 1058 ms 67928 KB Output is correct
10 Correct 1088 ms 68136 KB Output is correct
11 Correct 1101 ms 68108 KB Output is correct
12 Correct 1153 ms 68716 KB Output is correct
13 Correct 1118 ms 68832 KB Output is correct
14 Correct 37 ms 37880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 38016 KB Output is correct
2 Correct 30 ms 37916 KB Output is correct
3 Correct 32 ms 37880 KB Output is correct
4 Correct 35 ms 38008 KB Output is correct
5 Correct 30 ms 37880 KB Output is correct
6 Correct 38 ms 37880 KB Output is correct
7 Correct 33 ms 38008 KB Output is correct
8 Correct 35 ms 37880 KB Output is correct
9 Correct 32 ms 37888 KB Output is correct
10 Correct 35 ms 37880 KB Output is correct
11 Correct 38 ms 38008 KB Output is correct
12 Correct 32 ms 38008 KB Output is correct
13 Correct 32 ms 38008 KB Output is correct
14 Correct 37 ms 37980 KB Output is correct
15 Correct 35 ms 38012 KB Output is correct
16 Correct 42 ms 38008 KB Output is correct
17 Correct 36 ms 38008 KB Output is correct
18 Correct 36 ms 38008 KB Output is correct
19 Correct 37 ms 38008 KB Output is correct
20 Correct 40 ms 38008 KB Output is correct
21 Correct 38 ms 38008 KB Output is correct
22 Correct 34 ms 38008 KB Output is correct
23 Correct 32 ms 38008 KB Output is correct
24 Correct 35 ms 38008 KB Output is correct
25 Correct 33 ms 38008 KB Output is correct
26 Correct 32 ms 38008 KB Output is correct
27 Correct 34 ms 38008 KB Output is correct
28 Correct 38 ms 38008 KB Output is correct
29 Correct 37 ms 38064 KB Output is correct
30 Correct 33 ms 38008 KB Output is correct
31 Correct 33 ms 38016 KB Output is correct
32 Correct 35 ms 38008 KB Output is correct
33 Correct 34 ms 38008 KB Output is correct
34 Correct 35 ms 37928 KB Output is correct
35 Correct 33 ms 38008 KB Output is correct
36 Correct 33 ms 38008 KB Output is correct
37 Correct 36 ms 37976 KB Output is correct
38 Correct 33 ms 38016 KB Output is correct
39 Correct 34 ms 38008 KB Output is correct
40 Correct 32 ms 37964 KB Output is correct
41 Correct 31 ms 37968 KB Output is correct
42 Correct 1182 ms 52520 KB Output is correct
43 Correct 1133 ms 67656 KB Output is correct
44 Correct 1075 ms 67764 KB Output is correct
45 Correct 1058 ms 67492 KB Output is correct
46 Correct 1008 ms 68216 KB Output is correct
47 Correct 1044 ms 67884 KB Output is correct
48 Correct 1037 ms 67960 KB Output is correct
49 Correct 1186 ms 68708 KB Output is correct
50 Correct 1058 ms 67928 KB Output is correct
51 Correct 1088 ms 68136 KB Output is correct
52 Correct 1101 ms 68108 KB Output is correct
53 Correct 1153 ms 68716 KB Output is correct
54 Correct 1118 ms 68832 KB Output is correct
55 Correct 37 ms 37880 KB Output is correct
56 Correct 1020 ms 65080 KB Output is correct
57 Correct 957 ms 64368 KB Output is correct
58 Correct 1129 ms 65024 KB Output is correct
59 Correct 1094 ms 65192 KB Output is correct
60 Correct 1004 ms 64544 KB Output is correct
61 Correct 1111 ms 65528 KB Output is correct
62 Correct 1071 ms 65464 KB Output is correct
63 Correct 1072 ms 65528 KB Output is correct
64 Correct 1135 ms 65400 KB Output is correct
65 Correct 1035 ms 65104 KB Output is correct
66 Correct 937 ms 65244 KB Output is correct
67 Correct 981 ms 65304 KB Output is correct
68 Correct 1004 ms 64408 KB Output is correct
69 Correct 1087 ms 65564 KB Output is correct
70 Correct 927 ms 64612 KB Output is correct
71 Correct 942 ms 63864 KB Output is correct
72 Correct 925 ms 64128 KB Output is correct
73 Correct 1097 ms 65116 KB Output is correct
74 Correct 1099 ms 65016 KB Output is correct
75 Correct 1139 ms 65224 KB Output is correct
76 Correct 1096 ms 65772 KB Output is correct
77 Correct 32 ms 38008 KB Output is correct