Submission #105121

# Submission time Handle Problem Language Result Execution time Memory
105121 2019-04-10T15:25:03 Z reality Two Antennas (JOI19_antennas) C++17
100 / 100
1139 ms 40116 KB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 2e5 + 5;
int n;
int s[N];
int A[N];
int B[N];
int L[N];
int R[N];
int ans[N];
vi Up[N];
vi Qu[N];
const int oo = 1e9;
const pii OO = pii(oo,-oo);
pii operator + (pii a,pii b) {
	return pii(min(a.fi,b.fi),max(a.se,b.se));
}
pii tx[N * 4];
pii llz[N * 4];
int t[N * 4];
void upd(int node) {
	smax(t[node],max(tx[node].se - llz[node].fi,llz[node].se - tx[node].fi));
}
void lz(int l,int r,int node) {
	if (l != r) 
		llz[node * 2] = llz[node * 2] + llz[node],
		llz[node * 2 + 1] = llz[node * 2 + 1] + llz[node];
	upd(node);
	llz[node] = OO;
}
void build(int l,int r,int node) {
	if (l == r) {
		tx[node] = llz[node] = OO;
		t[node] = -2 * oo;
	} else {
		int m = (l + r) / 2;
		build(l,m,node * 2);
		build(m+1,r,node * 2 + 1);
		tx[node] = tx[node * 2] + tx[node * 2 + 1];
		llz[node] = OO;
		t[node] = -2 * oo;
	}
}
void Upy(int l,int r,int l1,int r1,pii v,int node) {
	lz(l,r,node);
	if (l1 <= l && r <= r1)
		llz[node] = v,lz(l,r,node);
	else {
		int m = (l + r) / 2;
		if (l1 <= m)
			Upy(l,m,l1,r1,v,node * 2);
		else
			lz(l,m,node * 2);
		if (m+1<=r1)
			Upy(m+1,r,l1,r1,v,node * 2 + 1);
		else
			lz(m+1,r,node * 2 + 1);
		smax(t[node],t[node * 2]);
		smax(t[node],t[node * 2 + 1]);	
	}
}
void Upx(int l,int r,int ps,pii v,int node) {
	lz(l,r,node);
	if (l == r)
		tx[node] = v;
	else {
		int m = (l + r) / 2;
		if (ps <= m)
			Upx(l,m,ps,v,node * 2);
		else
			lz(l,m,node * 2);
		if (m+1<=ps)
			Upx(m+1,r,ps,v,node * 2 + 1);
		else
			lz(m+1,r,node * 2 + 1);
		tx[node] = tx[node * 2] + tx[node * 2 + 1];
		smax(t[node],t[node * 2]);
		smax(t[node],t[node * 2 + 1]);
	}
}
int query(int l,int r,int l1,int r1,int node) {
	lz(l,r,node);
	if (l1 <= l && r <= r1)
		return t[node];
	int m = (l + r) / 2;
	int ans = -2 * oo;
	if (l1 <= m)
		smax(ans,query(l,m,l1,r1,node * 2));
	if (m+1<=r1)
		smax(ans,query(m+1,r,l1,r1,node * 2 + 1));
	return ans;
}
int main(void) {
    int n,q;
    cin>>n;
    for (int i = 1;i <= n;++i)
    	cin>>s[i]>>A[i]>>B[i];
    cin>>q;
    for (int i = 1;i <= q;++i)
    	cin>>L[i]>>R[i],Qu[R[i]].pb(i);
    build(1,n,1);
    for (int i = 1;i <= n;++i) {
    	const int ly = min(n+1,A[i]+i);
    	const int ry = min(n,i + B[i]);
    	if (ly <= ry)
	    	Up[ly].pb(i),Up[ry + 1].pb(-i);
    }
    for (int i = 1;i <= n;++i) {
    	const int lx = max(1,i - B[i]);
    	const int rx = min(n,i - A[i]);
    	for (auto it : Up[i]) {
    		Upx(1,n,abs(it),it > 0 ? mp(s[it],s[it]) : OO,1);
    	}
    	if (lx <= rx) {
	    	Upy(1,n,lx,rx,mp(s[i],s[i]),1);
    	}
    	for (auto it : Qu[i])
    		ans[it] = query(1,n,L[it],R[it],1);
    }
    for (int i = 1;i <= q;++i)
    	cout << max(-1,ans[i]) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Correct 12 ms 9856 KB Output is correct
3 Correct 16 ms 9788 KB Output is correct
4 Correct 12 ms 9856 KB Output is correct
5 Correct 12 ms 9728 KB Output is correct
6 Correct 13 ms 9856 KB Output is correct
7 Correct 13 ms 9856 KB Output is correct
8 Correct 12 ms 9728 KB Output is correct
9 Correct 15 ms 9836 KB Output is correct
10 Correct 13 ms 9856 KB Output is correct
11 Correct 13 ms 9856 KB Output is correct
12 Correct 13 ms 9856 KB Output is correct
13 Correct 12 ms 9728 KB Output is correct
14 Correct 13 ms 9728 KB Output is correct
15 Correct 12 ms 9728 KB Output is correct
16 Correct 13 ms 9856 KB Output is correct
17 Correct 12 ms 9856 KB Output is correct
18 Correct 13 ms 9728 KB Output is correct
19 Correct 12 ms 9728 KB Output is correct
20 Correct 12 ms 9728 KB Output is correct
21 Correct 12 ms 9756 KB Output is correct
22 Correct 14 ms 9728 KB Output is correct
23 Correct 12 ms 9728 KB Output is correct
24 Correct 12 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Correct 12 ms 9856 KB Output is correct
3 Correct 16 ms 9788 KB Output is correct
4 Correct 12 ms 9856 KB Output is correct
5 Correct 12 ms 9728 KB Output is correct
6 Correct 13 ms 9856 KB Output is correct
7 Correct 13 ms 9856 KB Output is correct
8 Correct 12 ms 9728 KB Output is correct
9 Correct 15 ms 9836 KB Output is correct
10 Correct 13 ms 9856 KB Output is correct
11 Correct 13 ms 9856 KB Output is correct
12 Correct 13 ms 9856 KB Output is correct
13 Correct 12 ms 9728 KB Output is correct
14 Correct 13 ms 9728 KB Output is correct
15 Correct 12 ms 9728 KB Output is correct
16 Correct 13 ms 9856 KB Output is correct
17 Correct 12 ms 9856 KB Output is correct
18 Correct 13 ms 9728 KB Output is correct
19 Correct 12 ms 9728 KB Output is correct
20 Correct 12 ms 9728 KB Output is correct
21 Correct 12 ms 9756 KB Output is correct
22 Correct 14 ms 9728 KB Output is correct
23 Correct 12 ms 9728 KB Output is correct
24 Correct 12 ms 9856 KB Output is correct
25 Correct 185 ms 14856 KB Output is correct
26 Correct 33 ms 10488 KB Output is correct
27 Correct 306 ms 16940 KB Output is correct
28 Correct 322 ms 17012 KB Output is correct
29 Correct 194 ms 14796 KB Output is correct
30 Correct 191 ms 14712 KB Output is correct
31 Correct 261 ms 16248 KB Output is correct
32 Correct 267 ms 17020 KB Output is correct
33 Correct 266 ms 16540 KB Output is correct
34 Correct 114 ms 13280 KB Output is correct
35 Correct 308 ms 17112 KB Output is correct
36 Correct 254 ms 17020 KB Output is correct
37 Correct 149 ms 13404 KB Output is correct
38 Correct 298 ms 16220 KB Output is correct
39 Correct 67 ms 10744 KB Output is correct
40 Correct 276 ms 16092 KB Output is correct
41 Correct 206 ms 14428 KB Output is correct
42 Correct 251 ms 16112 KB Output is correct
43 Correct 98 ms 12024 KB Output is correct
44 Correct 260 ms 15992 KB Output is correct
45 Correct 54 ms 11000 KB Output is correct
46 Correct 252 ms 16092 KB Output is correct
47 Correct 68 ms 11512 KB Output is correct
48 Correct 292 ms 16232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 29040 KB Output is correct
2 Correct 610 ms 30020 KB Output is correct
3 Correct 386 ms 27128 KB Output is correct
4 Correct 563 ms 30068 KB Output is correct
5 Correct 269 ms 19464 KB Output is correct
6 Correct 621 ms 30196 KB Output is correct
7 Correct 549 ms 28688 KB Output is correct
8 Correct 651 ms 30068 KB Output is correct
9 Correct 75 ms 12692 KB Output is correct
10 Correct 656 ms 30168 KB Output is correct
11 Correct 352 ms 21112 KB Output is correct
12 Correct 633 ms 30052 KB Output is correct
13 Correct 511 ms 28024 KB Output is correct
14 Correct 386 ms 27984 KB Output is correct
15 Correct 435 ms 28124 KB Output is correct
16 Correct 361 ms 28408 KB Output is correct
17 Correct 427 ms 28108 KB Output is correct
18 Correct 488 ms 28708 KB Output is correct
19 Correct 389 ms 27888 KB Output is correct
20 Correct 406 ms 28124 KB Output is correct
21 Correct 404 ms 28096 KB Output is correct
22 Correct 473 ms 28172 KB Output is correct
23 Correct 428 ms 27936 KB Output is correct
24 Correct 431 ms 28024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Correct 12 ms 9856 KB Output is correct
3 Correct 16 ms 9788 KB Output is correct
4 Correct 12 ms 9856 KB Output is correct
5 Correct 12 ms 9728 KB Output is correct
6 Correct 13 ms 9856 KB Output is correct
7 Correct 13 ms 9856 KB Output is correct
8 Correct 12 ms 9728 KB Output is correct
9 Correct 15 ms 9836 KB Output is correct
10 Correct 13 ms 9856 KB Output is correct
11 Correct 13 ms 9856 KB Output is correct
12 Correct 13 ms 9856 KB Output is correct
13 Correct 12 ms 9728 KB Output is correct
14 Correct 13 ms 9728 KB Output is correct
15 Correct 12 ms 9728 KB Output is correct
16 Correct 13 ms 9856 KB Output is correct
17 Correct 12 ms 9856 KB Output is correct
18 Correct 13 ms 9728 KB Output is correct
19 Correct 12 ms 9728 KB Output is correct
20 Correct 12 ms 9728 KB Output is correct
21 Correct 12 ms 9756 KB Output is correct
22 Correct 14 ms 9728 KB Output is correct
23 Correct 12 ms 9728 KB Output is correct
24 Correct 12 ms 9856 KB Output is correct
25 Correct 185 ms 14856 KB Output is correct
26 Correct 33 ms 10488 KB Output is correct
27 Correct 306 ms 16940 KB Output is correct
28 Correct 322 ms 17012 KB Output is correct
29 Correct 194 ms 14796 KB Output is correct
30 Correct 191 ms 14712 KB Output is correct
31 Correct 261 ms 16248 KB Output is correct
32 Correct 267 ms 17020 KB Output is correct
33 Correct 266 ms 16540 KB Output is correct
34 Correct 114 ms 13280 KB Output is correct
35 Correct 308 ms 17112 KB Output is correct
36 Correct 254 ms 17020 KB Output is correct
37 Correct 149 ms 13404 KB Output is correct
38 Correct 298 ms 16220 KB Output is correct
39 Correct 67 ms 10744 KB Output is correct
40 Correct 276 ms 16092 KB Output is correct
41 Correct 206 ms 14428 KB Output is correct
42 Correct 251 ms 16112 KB Output is correct
43 Correct 98 ms 12024 KB Output is correct
44 Correct 260 ms 15992 KB Output is correct
45 Correct 54 ms 11000 KB Output is correct
46 Correct 252 ms 16092 KB Output is correct
47 Correct 68 ms 11512 KB Output is correct
48 Correct 292 ms 16232 KB Output is correct
49 Correct 559 ms 29040 KB Output is correct
50 Correct 610 ms 30020 KB Output is correct
51 Correct 386 ms 27128 KB Output is correct
52 Correct 563 ms 30068 KB Output is correct
53 Correct 269 ms 19464 KB Output is correct
54 Correct 621 ms 30196 KB Output is correct
55 Correct 549 ms 28688 KB Output is correct
56 Correct 651 ms 30068 KB Output is correct
57 Correct 75 ms 12692 KB Output is correct
58 Correct 656 ms 30168 KB Output is correct
59 Correct 352 ms 21112 KB Output is correct
60 Correct 633 ms 30052 KB Output is correct
61 Correct 511 ms 28024 KB Output is correct
62 Correct 386 ms 27984 KB Output is correct
63 Correct 435 ms 28124 KB Output is correct
64 Correct 361 ms 28408 KB Output is correct
65 Correct 427 ms 28108 KB Output is correct
66 Correct 488 ms 28708 KB Output is correct
67 Correct 389 ms 27888 KB Output is correct
68 Correct 406 ms 28124 KB Output is correct
69 Correct 404 ms 28096 KB Output is correct
70 Correct 473 ms 28172 KB Output is correct
71 Correct 428 ms 27936 KB Output is correct
72 Correct 431 ms 28024 KB Output is correct
73 Correct 944 ms 36736 KB Output is correct
74 Correct 621 ms 31084 KB Output is correct
75 Correct 813 ms 36544 KB Output is correct
76 Correct 1136 ms 40108 KB Output is correct
77 Correct 602 ms 26360 KB Output is correct
78 Correct 978 ms 37236 KB Output is correct
79 Correct 918 ms 38692 KB Output is correct
80 Correct 1108 ms 40116 KB Output is correct
81 Correct 472 ms 20472 KB Output is correct
82 Correct 831 ms 35320 KB Output is correct
83 Correct 730 ms 30584 KB Output is correct
84 Correct 1139 ms 40112 KB Output is correct
85 Correct 720 ms 33652 KB Output is correct
86 Correct 894 ms 37068 KB Output is correct
87 Correct 574 ms 29556 KB Output is correct
88 Correct 961 ms 37396 KB Output is correct
89 Correct 942 ms 35100 KB Output is correct
90 Correct 940 ms 37540 KB Output is correct
91 Correct 639 ms 31204 KB Output is correct
92 Correct 953 ms 36948 KB Output is correct
93 Correct 483 ms 29868 KB Output is correct
94 Correct 939 ms 37088 KB Output is correct
95 Correct 593 ms 30540 KB Output is correct
96 Correct 1000 ms 36916 KB Output is correct