#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const ll MAX_TAILLE=200*1000+5,INFINI=2*1000*1000*1000+5,DECA=(1<<18);
struct antenne{
ll hauteur,minDist,maxDist;
};
struct som{
ll deb,fin,minProp,maxProp,maxi,valMin,valMax;
};
ll taille,nbReq,debReq,finReq;
antenne ant[MAX_TAILLE];
vector<ll> ajout[MAX_TAILLE],suppre[MAX_TAILLE];
vector<pair<ll,ll>> reqFin[MAX_TAILLE];
som maxDiff[2*DECA];
ll rep[MAX_TAILLE];
void prepa(int pos,int debInter,int finInter) {
maxDiff[pos].deb=debInter;
maxDiff[pos].fin=finInter;
maxDiff[pos].minProp=INFINI;
maxDiff[pos].maxProp=-INFINI;
maxDiff[pos].maxi=-1;
maxDiff[pos].valMin=INFINI;
maxDiff[pos].valMax=-INFINI;
if (debInter!=finInter) {
int midInter=(debInter+finInter)/2;
prepa(2*pos,debInter,midInter);
prepa(2*pos+1,midInter+1,finInter);
}
}
void pushFlag(int pos) {
if (maxDiff[pos].minProp!=INFINI and maxDiff[pos].valMax!=-INFINI) {
maxDiff[pos].maxi=max(maxDiff[pos].maxi,abs(maxDiff[pos].minProp-maxDiff[pos].valMax));
}
if (maxDiff[pos].maxProp!=-INFINI and maxDiff[pos].valMin!=INFINI) {
maxDiff[pos].maxi=max(maxDiff[pos].maxi,abs(maxDiff[pos].maxProp-maxDiff[pos].valMin));
}
if (maxDiff[pos].deb!=maxDiff[pos].fin) {
for (int i=0;i<2;i++) {
maxDiff[2*pos+i].minProp=min(maxDiff[2*pos+i].minProp,maxDiff[pos].minProp);
maxDiff[2*pos+i].maxProp=max(maxDiff[2*pos+i].maxProp,maxDiff[pos].maxProp);
}
}
maxDiff[pos].minProp=INFINI;
maxDiff[pos].maxProp=-INFINI;
}
void modifSommet(int pos,int idSom,int typeModif) {
pushFlag(pos);
if (maxDiff[pos].deb>idSom or maxDiff[pos].fin<idSom) {
return;
}
if (maxDiff[pos].deb==maxDiff[pos].fin) {
if (typeModif==0) {
maxDiff[pos].valMin=INFINI;
maxDiff[pos].valMax=-INFINI;
}
else {
maxDiff[pos].valMin=ant[idSom].hauteur;
maxDiff[pos].valMax=ant[idSom].hauteur;
}
}
else {
modifSommet(2*pos,idSom,typeModif);
modifSommet(2*pos+1,idSom,typeModif);
maxDiff[pos].valMin=min(maxDiff[2*pos].valMin,maxDiff[2*pos+1].valMin);
maxDiff[pos].valMax=max(maxDiff[2*pos].valMax,maxDiff[2*pos+1].valMax);
}
}
void nouvProp(int pos,int debInter,int finInter,int valProp) {
if (maxDiff[pos].deb>finInter or maxDiff[pos].fin<debInter) {
pushFlag(pos);
return;
}
if (maxDiff[pos].deb>=debInter and maxDiff[pos].fin<=finInter) {
//cout<<pos<<" "<<debInter<<" "<<finInter<<" "<<valProp<<" : ";
maxDiff[pos].minProp=min(maxDiff[pos].minProp,valProp);
maxDiff[pos].maxProp=max(maxDiff[pos].maxProp,valProp);
//cout<<maxDiff[pos].minProp<<" "<<maxDiff[pos].maxProp<<endl;
pushFlag(pos);
return;
}
pushFlag(pos);
nouvProp(2*pos,debInter,finInter,valProp);
nouvProp(2*pos+1,debInter,finInter,valProp);
maxDiff[pos].maxi=max(maxDiff[pos].maxi,max(maxDiff[2*pos].maxi,maxDiff[2*pos+1].maxi));
}
int calcMax(int pos,int debInter,int finInter) {
pushFlag(pos);
if (maxDiff[pos].deb>finInter or maxDiff[pos].fin<debInter) {
return -1;
}
if (maxDiff[pos].deb>=debInter and maxDiff[pos].fin<=finInter) {
return maxDiff[pos].maxi;
}
return max(calcMax(2*pos,debInter,finInter),calcMax(2*pos+1,debInter,finInter));
}
void afficher() {
cout<<endl;
for (int pos=1;pos<=100;pos++) {
if (maxDiff[pos].deb>0) {
cout<<pos<<" : "<<maxDiff[pos].deb<<" "<<maxDiff[pos].fin<<" "<<maxDiff[pos].valMin<<" "<<maxDiff[pos].valMax<<" "
<<maxDiff[pos].minProp<<" "<<maxDiff[pos].maxProp<<" "<<maxDiff[pos].maxi<<endl;
}
}
cout<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>taille;
for (ll i=1;i<=taille;i++) {
cin>>ant[i].hauteur>>ant[i].minDist>>ant[i].maxDist;
}
prepa(1,1,taille);
cin>>nbReq;
for (int i=0;i<nbReq;i++) {
cin>>debReq>>finReq;
reqFin[finReq].push_back({debReq,i});
}
for (ll i=1;i<=taille;i++) {
for (ll j:ajout[i]) {
modifSommet(1,j,1);
}
//afficher();
if (ant[i].minDist<i) {
//cout<<i<<" : "<<max((int)1,i-ant[i].maxDist)<<" "<<i-ant[i].minDist<<" "<<ant[i].hauteur<<endl;
nouvProp(1,max((int)1,i-ant[i].maxDist),i-ant[i].minDist,ant[i].hauteur);
}
//afficher();
if (i+ant[i].minDist<=taille) {
ajout[i+ant[i].minDist].push_back(i);
}
if (i+ant[i].maxDist<=taille) {
suppre[i+ant[i].maxDist].push_back(i);
}
for (auto k:reqFin[i]) {
rep[k.second]=calcMax(1,k.first,i);
}
for (ll j:suppre[i]) {
modifSommet(1,j,0);
}
}
for (int i=0;i<nbReq;i++) {
cout<<rep[i]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14424 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
7 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14448 KB |
Output is correct |
8 |
Correct |
9 ms |
14432 KB |
Output is correct |
9 |
Correct |
7 ms |
14392 KB |
Output is correct |
10 |
Correct |
7 ms |
14400 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14432 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14448 KB |
Output is correct |
16 |
Correct |
7 ms |
14472 KB |
Output is correct |
17 |
Correct |
7 ms |
14432 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
19 |
Correct |
7 ms |
14424 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
8 ms |
14420 KB |
Output is correct |
22 |
Correct |
7 ms |
14428 KB |
Output is correct |
23 |
Correct |
7 ms |
14464 KB |
Output is correct |
24 |
Correct |
7 ms |
14420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14424 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
7 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14448 KB |
Output is correct |
8 |
Correct |
9 ms |
14432 KB |
Output is correct |
9 |
Correct |
7 ms |
14392 KB |
Output is correct |
10 |
Correct |
7 ms |
14400 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14432 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14448 KB |
Output is correct |
16 |
Correct |
7 ms |
14472 KB |
Output is correct |
17 |
Correct |
7 ms |
14432 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
19 |
Correct |
7 ms |
14424 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
8 ms |
14420 KB |
Output is correct |
22 |
Correct |
7 ms |
14428 KB |
Output is correct |
23 |
Correct |
7 ms |
14464 KB |
Output is correct |
24 |
Correct |
7 ms |
14420 KB |
Output is correct |
25 |
Correct |
76 ms |
21612 KB |
Output is correct |
26 |
Correct |
17 ms |
15444 KB |
Output is correct |
27 |
Correct |
112 ms |
24616 KB |
Output is correct |
28 |
Correct |
114 ms |
24720 KB |
Output is correct |
29 |
Correct |
77 ms |
21556 KB |
Output is correct |
30 |
Correct |
80 ms |
21364 KB |
Output is correct |
31 |
Correct |
84 ms |
23312 KB |
Output is correct |
32 |
Correct |
143 ms |
24656 KB |
Output is correct |
33 |
Correct |
101 ms |
23996 KB |
Output is correct |
34 |
Correct |
61 ms |
19448 KB |
Output is correct |
35 |
Correct |
115 ms |
24488 KB |
Output is correct |
36 |
Correct |
116 ms |
24688 KB |
Output is correct |
37 |
Correct |
68 ms |
20016 KB |
Output is correct |
38 |
Correct |
121 ms |
23716 KB |
Output is correct |
39 |
Correct |
23 ms |
15948 KB |
Output is correct |
40 |
Correct |
109 ms |
23756 KB |
Output is correct |
41 |
Correct |
82 ms |
21296 KB |
Output is correct |
42 |
Correct |
108 ms |
23780 KB |
Output is correct |
43 |
Correct |
41 ms |
17588 KB |
Output is correct |
44 |
Correct |
108 ms |
23776 KB |
Output is correct |
45 |
Correct |
28 ms |
16208 KB |
Output is correct |
46 |
Correct |
113 ms |
23776 KB |
Output is correct |
47 |
Correct |
34 ms |
16984 KB |
Output is correct |
48 |
Correct |
109 ms |
23720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
292 ms |
54604 KB |
Output is correct |
2 |
Correct |
302 ms |
55992 KB |
Output is correct |
3 |
Correct |
228 ms |
52264 KB |
Output is correct |
4 |
Correct |
322 ms |
55988 KB |
Output is correct |
5 |
Correct |
114 ms |
34504 KB |
Output is correct |
6 |
Correct |
321 ms |
56064 KB |
Output is correct |
7 |
Correct |
247 ms |
54240 KB |
Output is correct |
8 |
Correct |
317 ms |
56004 KB |
Output is correct |
9 |
Correct |
38 ms |
19976 KB |
Output is correct |
10 |
Correct |
296 ms |
56000 KB |
Output is correct |
11 |
Correct |
164 ms |
36756 KB |
Output is correct |
12 |
Correct |
296 ms |
55904 KB |
Output is correct |
13 |
Correct |
200 ms |
54268 KB |
Output is correct |
14 |
Correct |
189 ms |
54316 KB |
Output is correct |
15 |
Correct |
220 ms |
54380 KB |
Output is correct |
16 |
Correct |
163 ms |
54796 KB |
Output is correct |
17 |
Correct |
198 ms |
54396 KB |
Output is correct |
18 |
Correct |
209 ms |
54808 KB |
Output is correct |
19 |
Correct |
188 ms |
54132 KB |
Output is correct |
20 |
Correct |
188 ms |
54584 KB |
Output is correct |
21 |
Correct |
199 ms |
54244 KB |
Output is correct |
22 |
Correct |
196 ms |
54344 KB |
Output is correct |
23 |
Correct |
192 ms |
54272 KB |
Output is correct |
24 |
Correct |
168 ms |
54288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14424 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
7 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14448 KB |
Output is correct |
8 |
Correct |
9 ms |
14432 KB |
Output is correct |
9 |
Correct |
7 ms |
14392 KB |
Output is correct |
10 |
Correct |
7 ms |
14400 KB |
Output is correct |
11 |
Correct |
7 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14432 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
8 ms |
14448 KB |
Output is correct |
16 |
Correct |
7 ms |
14472 KB |
Output is correct |
17 |
Correct |
7 ms |
14432 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
19 |
Correct |
7 ms |
14424 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
8 ms |
14420 KB |
Output is correct |
22 |
Correct |
7 ms |
14428 KB |
Output is correct |
23 |
Correct |
7 ms |
14464 KB |
Output is correct |
24 |
Correct |
7 ms |
14420 KB |
Output is correct |
25 |
Correct |
76 ms |
21612 KB |
Output is correct |
26 |
Correct |
17 ms |
15444 KB |
Output is correct |
27 |
Correct |
112 ms |
24616 KB |
Output is correct |
28 |
Correct |
114 ms |
24720 KB |
Output is correct |
29 |
Correct |
77 ms |
21556 KB |
Output is correct |
30 |
Correct |
80 ms |
21364 KB |
Output is correct |
31 |
Correct |
84 ms |
23312 KB |
Output is correct |
32 |
Correct |
143 ms |
24656 KB |
Output is correct |
33 |
Correct |
101 ms |
23996 KB |
Output is correct |
34 |
Correct |
61 ms |
19448 KB |
Output is correct |
35 |
Correct |
115 ms |
24488 KB |
Output is correct |
36 |
Correct |
116 ms |
24688 KB |
Output is correct |
37 |
Correct |
68 ms |
20016 KB |
Output is correct |
38 |
Correct |
121 ms |
23716 KB |
Output is correct |
39 |
Correct |
23 ms |
15948 KB |
Output is correct |
40 |
Correct |
109 ms |
23756 KB |
Output is correct |
41 |
Correct |
82 ms |
21296 KB |
Output is correct |
42 |
Correct |
108 ms |
23780 KB |
Output is correct |
43 |
Correct |
41 ms |
17588 KB |
Output is correct |
44 |
Correct |
108 ms |
23776 KB |
Output is correct |
45 |
Correct |
28 ms |
16208 KB |
Output is correct |
46 |
Correct |
113 ms |
23776 KB |
Output is correct |
47 |
Correct |
34 ms |
16984 KB |
Output is correct |
48 |
Correct |
109 ms |
23720 KB |
Output is correct |
49 |
Correct |
292 ms |
54604 KB |
Output is correct |
50 |
Correct |
302 ms |
55992 KB |
Output is correct |
51 |
Correct |
228 ms |
52264 KB |
Output is correct |
52 |
Correct |
322 ms |
55988 KB |
Output is correct |
53 |
Correct |
114 ms |
34504 KB |
Output is correct |
54 |
Correct |
321 ms |
56064 KB |
Output is correct |
55 |
Correct |
247 ms |
54240 KB |
Output is correct |
56 |
Correct |
317 ms |
56004 KB |
Output is correct |
57 |
Correct |
38 ms |
19976 KB |
Output is correct |
58 |
Correct |
296 ms |
56000 KB |
Output is correct |
59 |
Correct |
164 ms |
36756 KB |
Output is correct |
60 |
Correct |
296 ms |
55904 KB |
Output is correct |
61 |
Correct |
200 ms |
54268 KB |
Output is correct |
62 |
Correct |
189 ms |
54316 KB |
Output is correct |
63 |
Correct |
220 ms |
54380 KB |
Output is correct |
64 |
Correct |
163 ms |
54796 KB |
Output is correct |
65 |
Correct |
198 ms |
54396 KB |
Output is correct |
66 |
Correct |
209 ms |
54808 KB |
Output is correct |
67 |
Correct |
188 ms |
54132 KB |
Output is correct |
68 |
Correct |
188 ms |
54584 KB |
Output is correct |
69 |
Correct |
199 ms |
54244 KB |
Output is correct |
70 |
Correct |
196 ms |
54344 KB |
Output is correct |
71 |
Correct |
192 ms |
54272 KB |
Output is correct |
72 |
Correct |
168 ms |
54288 KB |
Output is correct |
73 |
Correct |
465 ms |
63088 KB |
Output is correct |
74 |
Correct |
323 ms |
56836 KB |
Output is correct |
75 |
Correct |
419 ms |
63068 KB |
Output is correct |
76 |
Correct |
551 ms |
67316 KB |
Output is correct |
77 |
Correct |
265 ms |
42472 KB |
Output is correct |
78 |
Correct |
476 ms |
63644 KB |
Output is correct |
79 |
Correct |
498 ms |
65404 KB |
Output is correct |
80 |
Correct |
592 ms |
67276 KB |
Output is correct |
81 |
Correct |
221 ms |
30016 KB |
Output is correct |
82 |
Correct |
428 ms |
61488 KB |
Output is correct |
83 |
Correct |
388 ms |
47688 KB |
Output is correct |
84 |
Correct |
573 ms |
67220 KB |
Output is correct |
85 |
Correct |
346 ms |
60072 KB |
Output is correct |
86 |
Correct |
440 ms |
64528 KB |
Output is correct |
87 |
Correct |
227 ms |
55768 KB |
Output is correct |
88 |
Correct |
402 ms |
64852 KB |
Output is correct |
89 |
Correct |
386 ms |
61800 KB |
Output is correct |
90 |
Correct |
462 ms |
64964 KB |
Output is correct |
91 |
Correct |
290 ms |
57424 KB |
Output is correct |
92 |
Correct |
432 ms |
64652 KB |
Output is correct |
93 |
Correct |
239 ms |
56024 KB |
Output is correct |
94 |
Correct |
436 ms |
64456 KB |
Output is correct |
95 |
Correct |
269 ms |
56892 KB |
Output is correct |
96 |
Correct |
410 ms |
64296 KB |
Output is correct |