답안 #102082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102082 2019-03-22T07:10:39 Z ainta Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
1851 ms 98564 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#define SZ 1048576
#define N_ 601000
using namespace std;
const int INF = 2e9;
struct AA {
	struct Tree {
		long long M, L, R, LR;
	}IT[SZ + SZ];
	Tree Merge(Tree a, Tree b) {
		long long L = max(max(a.M + b.L, a.L + b.LR),a.L);
		long long R = max(max(b.M + a.R, b.R + a.LR),b.R);
		long long LR = max(max(a.LR,b.LR),max(a.R + b.L, a.LR + b.LR));
		long long M = max(a.M + b.M, a.L + b.R);
		Tree ret = { M,L,R,LR };
		return ret;
	}
	void Make(int a, long long l, long long r) {
		//printf("%d %lld %lld\n", a, l, r);
		a += SZ;
		IT[a] = { 0, l, -r, l - r };
		while (a != 1) {
			a >>= 1;
			IT[a] = Merge(IT[a * 2], IT[a * 2 + 1]);
		}
	};
	long long Get(int b, int e) {
		b += SZ, e += SZ;
		vector<int>T1, T2;
		while (b <= e) {
			if (b & 1) {
				T1.push_back(b);
			}
			if (!(e & 1)) {
				T2.push_back(e);
			}
			b = (b + 1) >> 1, e = (e - 1) >> 1;
		}
		reverse(T2.begin(), T2.end());
		for (auto &t : T2)T1.push_back(t);
		if (T1.empty())return 0;
		Tree ret = IT[T1[0]];
		for (int i = 1; i < T1.size(); i++)ret = Merge(ret, IT[T1[i]]);
		return ret.M;
	}
	long long Solve(int b, int e, int bT, int eT) {
		Make(b * 2, bT - b, INF);
		Make(e * 2, -INF, eT - e);
		long long res = Get(b * 2, e * 2);
		Make(b * 2, -INF, INF);
		Make(e * 2, -INF, INF);
		return res;
	}
}Right, Left;
int n, Q, LL[N_], RR[N_];
int main() {
	//freopen("input.txt", "r", stdin);
	int i, ck, a, b, c, d;
	scanf("%d%d", &n, &Q);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &LL[i], &RR[i]);
		Left.Make(i * 2 + 1, LL[i] - i, RR[i] - i - 1);
		Right.Make((n - i) * 2 + 1, LL[i] - (n-i), RR[i] - (n-i) - 1);
	}
	for (i = 1; i <= n; i++) {
		Left.Make(i * 2, -INF, INF);
		Right.Make(i * 2, -INF, INF);
	}
	while (Q--) {
		scanf("%d", &ck);
		if (ck == 1) {
			scanf("%d%d%d", &a, &b, &c);
			Left.Make(a * 2 + 1, b - a, c - a - 1);
			Right.Make((n - a) * 2 + 1, b - (n-a), c - (n-a) - 1);
		}
		else {
			scanf("%d%d%d%d", &a, &b, &c, &d);
			if (a == c) {
				printf("%d\n", max(b - d, 0));
			}
			else if (a < c) {
				printf("%lld\n", Left.Solve(a, c, b, d));
			}
			else {
				printf("%lld\n", Right.Solve(n + 1 - a, n + 1 - c, b, d));
			}
		}
	}
	return 0;
}

Compilation message

timeleap.cpp: In member function 'long long int AA::Get(int, int)':
timeleap.cpp:45:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 1; i < T1.size(); i++)ret = Merge(ret, IT[T1[i]]);
                   ~~^~~~~~~~~~~
timeleap.cpp: In function 'int main()':
timeleap.cpp:61: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:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &LL[i], &RR[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &ck);
   ~~~~~^~~~~~~~~~~
timeleap.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d%d", &a, &b, &c);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:79:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d%d%d", &a, &b, &c, &d);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 7 ms 768 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 5 ms 688 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
33 Correct 6 ms 768 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 6 ms 768 KB Output is correct
36 Correct 6 ms 768 KB Output is correct
37 Correct 5 ms 768 KB Output is correct
38 Correct 6 ms 768 KB Output is correct
39 Correct 5 ms 768 KB Output is correct
40 Correct 5 ms 768 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1471 ms 91104 KB Output is correct
2 Correct 1444 ms 86512 KB Output is correct
3 Correct 1630 ms 87528 KB Output is correct
4 Correct 1676 ms 84992 KB Output is correct
5 Correct 1578 ms 90976 KB Output is correct
6 Correct 1644 ms 89432 KB Output is correct
7 Correct 1446 ms 91916 KB Output is correct
8 Correct 1600 ms 95672 KB Output is correct
9 Correct 1641 ms 85992 KB Output is correct
10 Correct 1851 ms 91808 KB Output is correct
11 Correct 1527 ms 91128 KB Output is correct
12 Correct 1595 ms 97144 KB Output is correct
13 Correct 1595 ms 98564 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 7 ms 768 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 5 ms 688 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 5 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
33 Correct 6 ms 768 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 6 ms 768 KB Output is correct
36 Correct 6 ms 768 KB Output is correct
37 Correct 5 ms 768 KB Output is correct
38 Correct 6 ms 768 KB Output is correct
39 Correct 5 ms 768 KB Output is correct
40 Correct 5 ms 768 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 1471 ms 91104 KB Output is correct
43 Correct 1444 ms 86512 KB Output is correct
44 Correct 1630 ms 87528 KB Output is correct
45 Correct 1676 ms 84992 KB Output is correct
46 Correct 1578 ms 90976 KB Output is correct
47 Correct 1644 ms 89432 KB Output is correct
48 Correct 1446 ms 91916 KB Output is correct
49 Correct 1600 ms 95672 KB Output is correct
50 Correct 1641 ms 85992 KB Output is correct
51 Correct 1851 ms 91808 KB Output is correct
52 Correct 1527 ms 91128 KB Output is correct
53 Correct 1595 ms 97144 KB Output is correct
54 Correct 1595 ms 98564 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 1423 ms 87292 KB Output is correct
57 Correct 1185 ms 81756 KB Output is correct
58 Correct 1292 ms 89536 KB Output is correct
59 Correct 1401 ms 89972 KB Output is correct
60 Correct 1432 ms 84260 KB Output is correct
61 Correct 1295 ms 92552 KB Output is correct
62 Correct 1163 ms 92152 KB Output is correct
63 Correct 1332 ms 91912 KB Output is correct
64 Correct 1404 ms 92864 KB Output is correct
65 Correct 1405 ms 88220 KB Output is correct
66 Correct 1315 ms 88740 KB Output is correct
67 Correct 1409 ms 92280 KB Output is correct
68 Correct 1382 ms 85124 KB Output is correct
69 Correct 1362 ms 94840 KB Output is correct
70 Correct 1360 ms 84680 KB Output is correct
71 Correct 1279 ms 81236 KB Output is correct
72 Correct 1280 ms 84424 KB Output is correct
73 Correct 1276 ms 92612 KB Output is correct
74 Correct 1238 ms 93172 KB Output is correct
75 Correct 1399 ms 94564 KB Output is correct
76 Correct 1329 ms 95236 KB Output is correct
77 Correct 3 ms 512 KB Output is correct