Submission #103028

# Submission time Handle Problem Language Result Execution time Memory
103028 2019-03-28T19:16:04 Z jangwonyoung Bitaro, who Leaps through Time (JOI19_timeleap) C++14
100 / 100
1233 ms 71672 KB
#include<iostream>
using namespace std;
typedef long long ll;
int n,q;
ll l[300001],r[300001];
int t[300001],p[300001];
ll s[300001],e[300001];
int a[300001],c[300001];
ll b[300001],d[300001];
ll ans[300001];
struct info{
	ll l,r;
	ll cost,to;
};
info zero={(ll)-1e18,(ll)1e18,-1,0};
info f(info l,info r){
	if(l.cost!=-1){
		l.cost+=max(l.to-r.r,0LL);
		l.to=min(r.r,max(l.to,r.l));
		if(r.cost!=-1) l.to=r.to,l.cost+=r.cost;
	}
	else if(l.l>r.r){
		l={l.l,l.l,l.l-r.r,r.r};
		if(r.cost!=-1) l.to=r.to,l.cost+=r.cost;
	}
	else if(l.r<r.l){
		l={l.r,l.r,0,r.l};
		if(r.cost!=-1) l.to=r.to,l.cost+=r.cost;
	}
	else if(r.cost!=-1) l=r;
	else{
		l={max(l.l,r.l),min(l.r,r.r),-1,168};
	}
	return l;
}
info g[1<<20];
void upd(int id,int l,int r,int up,ll us,ll ue){
	if(l==r){
		g[id]={us,ue,-1,168};
		return;
	}
	int mid=(l+r)/2;
	if(up<=mid) upd(id*2,l,mid,up,us,ue);
	else upd(id*2+1,mid+1,r,up,us,ue);
	g[id]=f(g[id*2],g[id*2+1]);
}
info qry(int id,int l,int r,int ql,int qr){
	if(l>qr || r<ql) return zero;
	if(ql<=l && r<=qr) return g[id];
	int mid=(l+r)/2;
	return f(qry(id*2,l,mid,ql,qr),qry(id*2+1,mid+1,r,ql,qr));
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> q;
	for(int i=1; i<n ;i++) cin >> l[i] >> r[i];
	for(int i=1; i<n ;i++) upd(1,1,n,i,l[i]-i,r[i]-i-1);
	for(int i=1; i<=q ;i++){
		cin >> t[i];
		if(t[i]==1){
			cin >> p[i] >> s[i] >> e[i];
			upd(1,1,n,p[i],s[i]-p[i],e[i]-p[i]-1);
		}
		else{
			cin >> a[i] >> b[i] >> c[i] >> d[i];
			if(a[i]>c[i]) continue;
			if(a[i]==c[i]){
				ans[i]=max(b[i]-d[i],0LL);
				continue;
			}
			b[i]-=a[i],d[i]-=c[i];
			info x={b[i],b[i],0,b[i]};
			info y={d[i],d[i],0,d[i]};
			info z=f(x,f(qry(1,1,n,a[i],c[i]-1),y));
			ans[i]=z.cost;
		}
	}
	for(int i=1; i<n ;i++) upd(1,1,n,n-i,l[i]+i+1,r[i]+i);
	for(int i=1; i<=q ;i++){
		if(t[i]==1) upd(1,1,n,n-p[i],s[i]+p[i]+1,e[i]+p[i]);
		else{
			if(a[i]<=c[i]) continue;
			b[i]+=a[i],d[i]+=c[i];
			info x={b[i],b[i],0,b[i]};
			info y={d[i],d[i],0,d[i]};
			info z=f(x,f(qry(1,1,n,n-a[i]+1,n-c[i]),y));
			ans[i]=z.cost;
		}
	}
	for(int i=1; i<=q ;i++) if(t[i]==2) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 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 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 4 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 5 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 4 ms 640 KB Output is correct
36 Correct 4 ms 640 KB Output is correct
37 Correct 4 ms 640 KB Output is correct
38 Correct 5 ms 640 KB Output is correct
39 Correct 4 ms 640 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 944 ms 52388 KB Output is correct
2 Correct 881 ms 50912 KB Output is correct
3 Correct 896 ms 50936 KB Output is correct
4 Correct 924 ms 50680 KB Output is correct
5 Correct 959 ms 67960 KB Output is correct
6 Correct 857 ms 67660 KB Output is correct
7 Correct 831 ms 67832 KB Output is correct
8 Correct 985 ms 68728 KB Output is correct
9 Correct 847 ms 50808 KB Output is correct
10 Correct 979 ms 67964 KB Output is correct
11 Correct 849 ms 67888 KB Output is correct
12 Correct 879 ms 68600 KB Output is correct
13 Correct 964 ms 68728 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 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 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 4 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 5 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 4 ms 640 KB Output is correct
36 Correct 4 ms 640 KB Output is correct
37 Correct 4 ms 640 KB Output is correct
38 Correct 5 ms 640 KB Output is correct
39 Correct 4 ms 640 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 944 ms 52388 KB Output is correct
43 Correct 881 ms 50912 KB Output is correct
44 Correct 896 ms 50936 KB Output is correct
45 Correct 924 ms 50680 KB Output is correct
46 Correct 959 ms 67960 KB Output is correct
47 Correct 857 ms 67660 KB Output is correct
48 Correct 831 ms 67832 KB Output is correct
49 Correct 985 ms 68728 KB Output is correct
50 Correct 847 ms 50808 KB Output is correct
51 Correct 979 ms 67964 KB Output is correct
52 Correct 849 ms 67888 KB Output is correct
53 Correct 879 ms 68600 KB Output is correct
54 Correct 964 ms 68728 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 952 ms 70600 KB Output is correct
57 Correct 976 ms 53416 KB Output is correct
58 Correct 971 ms 70896 KB Output is correct
59 Correct 914 ms 70996 KB Output is correct
60 Correct 859 ms 53676 KB Output is correct
61 Correct 919 ms 71304 KB Output is correct
62 Correct 926 ms 71288 KB Output is correct
63 Correct 933 ms 71304 KB Output is correct
64 Correct 1031 ms 71316 KB Output is correct
65 Correct 854 ms 70596 KB Output is correct
66 Correct 1000 ms 70932 KB Output is correct
67 Correct 931 ms 71080 KB Output is correct
68 Correct 912 ms 63224 KB Output is correct
69 Correct 865 ms 71432 KB Output is correct
70 Correct 824 ms 53752 KB Output is correct
71 Correct 814 ms 52984 KB Output is correct
72 Correct 882 ms 58916 KB Output is correct
73 Correct 936 ms 70904 KB Output is correct
74 Correct 986 ms 70904 KB Output is correct
75 Correct 1233 ms 71148 KB Output is correct
76 Correct 1044 ms 71672 KB Output is correct
77 Correct 3 ms 384 KB Output is correct