답안 #410346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410346 2021-05-22T14:29:10 Z alishahali1382 Bitaro, who Leaps through Time (JOI19_timeleap) C++14
100 / 100
835 ms 97480 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=300010, LOG=20;

int n, m, k, u, v, x, y, t, l, r, a, b;

struct Node{
	ll dp[2][2];
	Node(ll l=0, ll r=0){
		dp[0][0]=l;
		dp[0][1]=0;
		dp[1][0]=0;
		dp[1][1]=-r;
	}
};
Node Merge(Node X, Node Y){
	Node Z;
	for (int a=0; a<2; a++) for (int b=0; b<2; b++)
		Z.dp[a][b]=max(X.dp[a][0]+Y.dp[1][b], X.dp[a][1]+Y.dp[0][b]);
	return Z;
}
struct Solver{
	int L[MAXN], R[MAXN];
	Node seg[MAXN<<2];
	Solver(){
		seg[0].dp[0][0]=-INF;
		seg[0].dp[0][1]=0;
		seg[0].dp[1][0]=0;
		seg[0].dp[1][1]=-INF;
	}
	void Build(int id, int tl, int tr){
		if (tr-tl==1){
			seg[id]=Node(L[tl], R[tl]);
			return ;
		}
		int mid=(tl+tr)>>1;
		Build(id<<1, tl, mid);
		Build(id<<1 | 1, mid, tr);
		seg[id]=Merge(seg[id<<1], seg[id<<1 | 1]);
	}
	void Set(int id, int tl, int tr, int pos){
		if (pos<tl || tr<=pos) return ;
		if (tr-tl==1){
			seg[id]=Node(L[tl], R[tl]);
			return ;	
		}
		int mid=(tl+tr)>>1;
		Set(id<<1, tl, mid, pos);
		Set(id<<1 | 1, mid, tr, pos);
		seg[id]=Merge(seg[id<<1], seg[id<<1 | 1]);	
	}
	Node Get(int id, int tl, int tr, int l, int r){
		if (r<=tl || tr<=l) return seg[0];
		if (l<=tl && tr<=r) return seg[id];
		int mid=(tl+tr)>>1;
		return Merge(Get(id<<1, tl, mid, l, r), Get(id<<1 | 1, mid, tr, l, r));
	}
	ll Solve(int x, int y, int a, int b){
		a-=x;
		b-=y;
		Node X(a, a);
		Node Y=Get(1, 1, n, x, y);
		Node Z(b, b);
		X=Merge(X, Merge(Y, Z));
//		return max(X.dp[0][1], X.dp[1][0]);
		return X.dp[0][1];
	}
} S1, S2;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	if (n==1){
		while (m--){
			cin>>t>>x>>a>>y>>b;
			cout<<max(0, a-b)<<"\n";
		}
		return 0;
	}
	for (int i=1; i<n; i++){
		cin>>l>>r; r--;
		S1.L[i]=l-i;
		S2.L[n-i]=l-(n-i);
		S1.R[i]=r-i;
		S2.R[n-i]=r-(n-i);
	}
	S1.Build(1, 1, n);
	S2.Build(1, 1, n);
	
	while (m--){
		cin>>t;
		if (t==1){
			cin>>x>>l>>r;
			r--;
			S1.L[x]=l-x;
			S2.L[n-x]=l-(n-x);
			S1.R[x]=r-x;
			S2.R[n-x]=r-(n-x);
			S1.Set(1, 1, n, x);
			S2.Set(1, 1, n, n-x);
		}
		else{
			cin>>x>>a>>y>>b;
			if (x==y) cout<<max(0, a-b)<<"\n";
			if (x<y) cout<<S1.Solve(x, y, a, b)<<"\n";
			if (x>y) cout<<S2.Solve(n+1-x, n+1-y, a, b)<<"\n";
		}
	}
	
	return 0;
}
/*
5 1
3 5
4 8
2 6
5 10
2 5 3 1 10

5 1
5 10
2 6
4 8
3 5
2 1 3 5 10

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 75460 KB Output is correct
2 Correct 40 ms 75460 KB Output is correct
3 Correct 42 ms 75412 KB Output is correct
4 Correct 40 ms 75448 KB Output is correct
5 Correct 40 ms 75392 KB Output is correct
6 Correct 40 ms 75460 KB Output is correct
7 Correct 41 ms 75400 KB Output is correct
8 Correct 40 ms 75404 KB Output is correct
9 Correct 45 ms 75392 KB Output is correct
10 Correct 40 ms 75444 KB Output is correct
11 Correct 41 ms 75420 KB Output is correct
12 Correct 42 ms 75556 KB Output is correct
13 Correct 41 ms 75412 KB Output is correct
14 Correct 42 ms 75476 KB Output is correct
15 Correct 42 ms 75500 KB Output is correct
16 Correct 41 ms 75492 KB Output is correct
17 Correct 42 ms 75480 KB Output is correct
18 Correct 42 ms 75496 KB Output is correct
19 Correct 42 ms 75444 KB Output is correct
20 Correct 42 ms 75492 KB Output is correct
21 Correct 45 ms 75396 KB Output is correct
22 Correct 46 ms 75488 KB Output is correct
23 Correct 45 ms 75468 KB Output is correct
24 Correct 42 ms 75460 KB Output is correct
25 Correct 42 ms 75500 KB Output is correct
26 Correct 41 ms 75424 KB Output is correct
27 Correct 49 ms 75372 KB Output is correct
28 Correct 43 ms 75468 KB Output is correct
29 Correct 49 ms 75396 KB Output is correct
30 Correct 43 ms 75408 KB Output is correct
31 Correct 40 ms 75396 KB Output is correct
32 Correct 42 ms 75396 KB Output is correct
33 Correct 41 ms 75388 KB Output is correct
34 Correct 41 ms 75400 KB Output is correct
35 Correct 42 ms 75480 KB Output is correct
36 Correct 42 ms 75472 KB Output is correct
37 Correct 42 ms 75472 KB Output is correct
38 Correct 42 ms 75468 KB Output is correct
39 Correct 46 ms 75496 KB Output is correct
40 Correct 41 ms 75448 KB Output is correct
41 Correct 40 ms 75468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 690 ms 83988 KB Output is correct
2 Correct 694 ms 83816 KB Output is correct
3 Correct 677 ms 83812 KB Output is correct
4 Correct 706 ms 83612 KB Output is correct
5 Correct 694 ms 84032 KB Output is correct
6 Correct 698 ms 83824 KB Output is correct
7 Correct 735 ms 84036 KB Output is correct
8 Correct 712 ms 84356 KB Output is correct
9 Correct 687 ms 83780 KB Output is correct
10 Correct 711 ms 83920 KB Output is correct
11 Correct 728 ms 83996 KB Output is correct
12 Correct 718 ms 84304 KB Output is correct
13 Correct 742 ms 84400 KB Output is correct
14 Correct 40 ms 75336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 75460 KB Output is correct
2 Correct 40 ms 75460 KB Output is correct
3 Correct 42 ms 75412 KB Output is correct
4 Correct 40 ms 75448 KB Output is correct
5 Correct 40 ms 75392 KB Output is correct
6 Correct 40 ms 75460 KB Output is correct
7 Correct 41 ms 75400 KB Output is correct
8 Correct 40 ms 75404 KB Output is correct
9 Correct 45 ms 75392 KB Output is correct
10 Correct 40 ms 75444 KB Output is correct
11 Correct 41 ms 75420 KB Output is correct
12 Correct 42 ms 75556 KB Output is correct
13 Correct 41 ms 75412 KB Output is correct
14 Correct 42 ms 75476 KB Output is correct
15 Correct 42 ms 75500 KB Output is correct
16 Correct 41 ms 75492 KB Output is correct
17 Correct 42 ms 75480 KB Output is correct
18 Correct 42 ms 75496 KB Output is correct
19 Correct 42 ms 75444 KB Output is correct
20 Correct 42 ms 75492 KB Output is correct
21 Correct 45 ms 75396 KB Output is correct
22 Correct 46 ms 75488 KB Output is correct
23 Correct 45 ms 75468 KB Output is correct
24 Correct 42 ms 75460 KB Output is correct
25 Correct 42 ms 75500 KB Output is correct
26 Correct 41 ms 75424 KB Output is correct
27 Correct 49 ms 75372 KB Output is correct
28 Correct 43 ms 75468 KB Output is correct
29 Correct 49 ms 75396 KB Output is correct
30 Correct 43 ms 75408 KB Output is correct
31 Correct 40 ms 75396 KB Output is correct
32 Correct 42 ms 75396 KB Output is correct
33 Correct 41 ms 75388 KB Output is correct
34 Correct 41 ms 75400 KB Output is correct
35 Correct 42 ms 75480 KB Output is correct
36 Correct 42 ms 75472 KB Output is correct
37 Correct 42 ms 75472 KB Output is correct
38 Correct 42 ms 75468 KB Output is correct
39 Correct 46 ms 75496 KB Output is correct
40 Correct 41 ms 75448 KB Output is correct
41 Correct 40 ms 75468 KB Output is correct
42 Correct 690 ms 83988 KB Output is correct
43 Correct 694 ms 83816 KB Output is correct
44 Correct 677 ms 83812 KB Output is correct
45 Correct 706 ms 83612 KB Output is correct
46 Correct 694 ms 84032 KB Output is correct
47 Correct 698 ms 83824 KB Output is correct
48 Correct 735 ms 84036 KB Output is correct
49 Correct 712 ms 84356 KB Output is correct
50 Correct 687 ms 83780 KB Output is correct
51 Correct 711 ms 83920 KB Output is correct
52 Correct 728 ms 83996 KB Output is correct
53 Correct 718 ms 84304 KB Output is correct
54 Correct 742 ms 84400 KB Output is correct
55 Correct 40 ms 75336 KB Output is correct
56 Correct 766 ms 96292 KB Output is correct
57 Correct 752 ms 95592 KB Output is correct
58 Correct 760 ms 96672 KB Output is correct
59 Correct 790 ms 96656 KB Output is correct
60 Correct 745 ms 95940 KB Output is correct
61 Correct 835 ms 97048 KB Output is correct
62 Correct 770 ms 96996 KB Output is correct
63 Correct 778 ms 96956 KB Output is correct
64 Correct 791 ms 97088 KB Output is correct
65 Correct 786 ms 96424 KB Output is correct
66 Correct 765 ms 96480 KB Output is correct
67 Correct 788 ms 97012 KB Output is correct
68 Correct 753 ms 95884 KB Output is correct
69 Correct 805 ms 97116 KB Output is correct
70 Correct 765 ms 95996 KB Output is correct
71 Correct 761 ms 95168 KB Output is correct
72 Correct 741 ms 95680 KB Output is correct
73 Correct 768 ms 96476 KB Output is correct
74 Correct 770 ms 96576 KB Output is correct
75 Correct 779 ms 96888 KB Output is correct
76 Correct 776 ms 97480 KB Output is correct
77 Correct 37 ms 75408 KB Output is correct