Submission #1006412

# Submission time Handle Problem Language Result Execution time Memory
1006412 2024-06-24T01:47:31 Z AdamGS Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
380 ms 71508 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
struct item {
	ll t=0, a=0, b=0, c=0;
};
const ll INF=1e18+7;
const int LIM=3e5+7;
item tr[2][4*LIM];
int N=1;
item merge(item a, item b) {
	item x;
	x.c=a.c+b.c;
	if(a.t==0 && b.t==0) {
		x.a=max(a.a, b.a);
		x.b=min(a.b, b.b);
		if(x.a<=x.b) return x;
		if(a.a>b.b) {
			x.a=a.a;
			x.b=b.b;
			x.c+=a.a-b.b;
		} else {
			x.a=a.b;
			x.b=b.a;
		}
		x.t=1;
		return x;
	}
	x.t=1;
	if(b.t==0) {
		x.a=a.a;
		if(a.b>=b.b) {
			x.b=b.b;
			x.c+=a.b-b.b;
		} else if(a.b<=b.a) x.b=b.a;
		else x.b=a.b;
		return x;
	}
	x.b=b.b;
	if(a.t==0) {
		if(a.a>=b.a) {
			x.c+=a.a-b.a;
			x.a=a.a;
		} else if(a.b<=b.a) x.a=a.b;
		else x.a=b.a;
	} else {
		x.a=a.a;
		if(a.b>=b.a) x.c+=a.b-b.a;
	}
	return x;
}
void upd(int v, int k, item p) {
	v+=N;
	tr[k][v]=p;
	v/=2;
	while(v) {
		tr[k][v]=merge(tr[k][2*v], tr[k][2*v+1]);
		v/=2;
	}
}
item cnt(int l, int r, int k) {
	if(l>r) return {0, -INF, INF, 0};
	l+=N; r+=N;
	item ansl=tr[k][l];
	if(l==r) return ansl;
	item ansr=tr[k][r];
	while(l/2!=r/2) {
		if(l%2==0) ansl=merge(ansl, tr[k][l+1]);
		if(r%2==1) ansr=merge(tr[k][r-1], ansr);
		l/=2; r/=2;
	}
	return merge(ansl, ansr);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, q;
	cin >> n >> q;
	while(N<n) N*=2;
	rep(i, n-1) {
		ll a, b;
		cin >> a >> b; --b;
		tr[0][N+i]={0, a-i, b-i, 0};
		tr[1][N+n-i-2]={0, a-(n-i-2), b-(n-i-2), 0};
	}
	for(int i=N-1; i; --i) {
		tr[0][i]=merge(tr[0][2*i], tr[0][2*i+1]);
		tr[1][i]=merge(tr[1][2*i], tr[1][2*i+1]);
	}
	while(q--) {
		int t;
		cin >> t;
		if(t==2) {
			ll a, b, c, d;
			cin >> a >> b >> c >> d; --a; --c;
			if(a<=c) {
				b-=a; d-=c;
				item x={1, b, b, 0}, y={1, d, d, 0};
				x=merge(x, cnt(a, c-1, 0));
				x=merge(x, y);
				cout << x.c << '\n';
				continue;
			}
			b-=(n-a-1); d-=(n-c-1);
			item x={1, b, b, 0}, y={1, d, d, 0};
			item xd=cnt(n-a-1, n-c-2, 1);
			x=merge(x, cnt(n-a-1, n-c-2, 1));
			x=merge(x, y);
			cout << x.c << '\n';
		} else {
			ll a, b, c;
			cin >> a >> b >> c; --a; --c;
			upd(a, 0, {0, b-a, c-a, 0});
			upd(n-a-2, 1, {0, b-(n-a-2), c-(n-a-2), 0});
		}
	}
}

Compilation message

timeleap.cpp: In function 'int main()':
timeleap.cpp:111:9: warning: variable 'xd' set but not used [-Wunused-but-set-variable]
  111 |    item xd=cnt(n-a-1, n-c-2, 1);
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 290 ms 58336 KB Output is correct
2 Correct 294 ms 39604 KB Output is correct
3 Correct 289 ms 39656 KB Output is correct
4 Correct 276 ms 39644 KB Output is correct
5 Correct 319 ms 58140 KB Output is correct
6 Correct 318 ms 58080 KB Output is correct
7 Correct 317 ms 58168 KB Output is correct
8 Correct 292 ms 58180 KB Output is correct
9 Correct 299 ms 39764 KB Output is correct
10 Correct 317 ms 58104 KB Output is correct
11 Correct 332 ms 58092 KB Output is correct
12 Correct 291 ms 58196 KB Output is correct
13 Correct 346 ms 58196 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 290 ms 58336 KB Output is correct
43 Correct 294 ms 39604 KB Output is correct
44 Correct 289 ms 39656 KB Output is correct
45 Correct 276 ms 39644 KB Output is correct
46 Correct 319 ms 58140 KB Output is correct
47 Correct 318 ms 58080 KB Output is correct
48 Correct 317 ms 58168 KB Output is correct
49 Correct 292 ms 58180 KB Output is correct
50 Correct 299 ms 39764 KB Output is correct
51 Correct 317 ms 58104 KB Output is correct
52 Correct 332 ms 58092 KB Output is correct
53 Correct 291 ms 58196 KB Output is correct
54 Correct 346 ms 58196 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 333 ms 70480 KB Output is correct
57 Correct 318 ms 51540 KB Output is correct
58 Correct 363 ms 70740 KB Output is correct
59 Correct 306 ms 70736 KB Output is correct
60 Correct 283 ms 51848 KB Output is correct
61 Correct 355 ms 70996 KB Output is correct
62 Correct 312 ms 70996 KB Output is correct
63 Correct 333 ms 70872 KB Output is correct
64 Correct 326 ms 70984 KB Output is correct
65 Correct 325 ms 70736 KB Output is correct
66 Correct 344 ms 70500 KB Output is correct
67 Correct 318 ms 70788 KB Output is correct
68 Correct 380 ms 67924 KB Output is correct
69 Correct 335 ms 70996 KB Output is correct
70 Correct 305 ms 51876 KB Output is correct
71 Correct 311 ms 51028 KB Output is correct
72 Correct 307 ms 67668 KB Output is correct
73 Correct 329 ms 70484 KB Output is correct
74 Correct 334 ms 70484 KB Output is correct
75 Correct 328 ms 70648 KB Output is correct
76 Correct 361 ms 71508 KB Output is correct
77 Correct 1 ms 348 KB Output is correct