Submission #108921

# Submission time Handle Problem Language Result Execution time Memory
108921 2019-05-02T18:27:01 Z hugo_pm Two Antennas (JOI19_antennas) C++17
100 / 100
1183 ms 64124 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 10000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

const int borne = 201*1000;
int nbAntennes, nbRequetes;

struct Antenne
{
	int hauteur, rgDeb, rgFin;
};

struct Requete
{
	int deb=0, fin=0, rep=-1;
};

vector<Antenne> ants;
vector<Requete> requetes;


// Segtree

int stOrig[4*borne];
int stCool[4*borne]; // Une nomenclature de qualité
int lazy[4*borne];

void pushCool(int nod) // A VERIFIER
{
	if (lazy[nod] != BIG) {
		chmax(stCool[nod], stOrig[nod] - lazy[nod]);
		//cout << nod << " " << stOrig[nod] << " " << lazy[nod] << " => " << stOrig[nod] - lazy[nod] << "\n";
	}

	if (2*nod+1 < 4*borne) {
		chmin(lazy[2*nod], lazy[nod]);
		chmin(lazy[2*nod+1], lazy[nod]);
	}

	lazy[nod] = BIG;
}

void updOrig(int nod, int lno, int rno, int pos, int val)
{
	pushCool(nod); // A VERIFIER
	if (lno == rno) {
		assert(lno == pos);
		stOrig[nod] = val;
	} else {
		int midNo = (lno+rno) / 2;
		if (pos <= midNo) updOrig(2*nod, lno, midNo, pos, val);
		else updOrig(2*nod + 1, midNo+1, rno, pos, val);
		stOrig[nod] = max(stOrig[2*nod], stOrig[2*nod+1]);
	}
}

int getMaxCool(int nod, int lno, int rno, int li, int ri)
{
	pushCool(nod);
	if (lno > ri || rno < li) return -BIG;
	if (li <= lno && rno <= ri) return stCool[nod];
	int midNo = (lno+rno) / 2;

	int rd = max(getMaxCool(2*nod, lno, midNo, li, ri), getMaxCool(2*nod+1, midNo+1, rno, li, ri));
	return rd;
}

void updCool(int nod, int lno, int rno, int li, int ri, int delta)
{
	if (lno > ri || rno < li) return;
	if (li <= lno && rno <= ri) {
		chmin(lazy[nod], delta);
		pushCool(nod);
		return;
	}
	pushCool(nod);
	int midNo = (lno+rno) / 2;
	updCool(2*nod, lno, midNo, li, ri, delta);
	updCool(2*nod+1, midNo+1, rno, li, ri, delta);
	stCool[nod] = max(stCool[nod], max(stCool[2*nod], stCool[2*nod+1])); // A VERIFIER
}

// Fin segtree

vector<int> evAdd[borne];
vector<int> evDel[borne];
vector<int> evReq[borne];

void resoudre()
{
	fill_n(&stOrig[0], 4*borne, -BIG);
	fill_n(&stCool[0], 4*borne, -BIG);
	fill_n(&lazy[0], 4*borne, BIG);

	form(i, borne) { evAdd[i].clear(); evDel[i].clear(); evReq[i].clear(); }

	form(iReq, nbRequetes) {
		evReq[requetes[iReq].fin].push_back(iReq);
	}

	form(posAnt, nbAntennes) {
		Antenne &an = ants[posAnt];
		int posDeb = posAnt + an.rgDeb;
		if (posDeb >= nbAntennes) continue;
		int posFin = min(nbAntennes, posAnt + an.rgFin);

		evAdd[posDeb].push_back(posAnt);
		evDel[posFin].push_back(posAnt);
	}

	multiset<int> curHa;

	form(posAnt, nbAntennes) {

		for (int ev : evAdd[posAnt]) {
			updOrig(1, 0, nbAntennes-1, ev, ants[ev].hauteur);
		}

		Antenne &an = ants[posAnt];
		int rgDeb = max(0LL, posAnt - an.rgFin);
		int rgFin = posAnt - an.rgDeb;
		if (rgFin >= rgDeb) {
			updCool(1, 0, nbAntennes-1, rgDeb, rgFin, an.hauteur);
		}

		for (int ev : evReq[posAnt]) { // A VERIFIER : sur de l'ordre ?
			Requete &rq = requetes[ev];
			assert(rq.fin == posAnt);
			chmax(rq.rep, getMaxCool(1, 0, nbAntennes-1, rq.deb, rq.fin));
		}

		for (int ev : evDel[posAnt]) {
			updOrig(1, 0, nbAntennes-1, ev, -BIG);
		}
	}
}

void solve()
{
	cin >> nbAntennes;
	ants.resize(nbAntennes);

	form(iAnt, nbAntennes) {
		Antenne &an = ants[iAnt];
		cin >> an.hauteur >> an.rgDeb >> an.rgFin;
	}

	cin >> nbRequetes;
	requetes.resize(nbRequetes);

	form(iReq, nbRequetes) {
		cin >> requetes[iReq].deb >> requetes[iReq].fin;
		--requetes[iReq].deb;
		--requetes[iReq].fin;
		requetes[iReq].rep = -1;
	}

	resoudre();
	
	reverse(ants.begin(), ants.end());

	form(iReq, nbRequetes) {
		int newDeb = (nbAntennes - 1) - requetes[iReq].fin;
		int newFin = (nbAntennes - 1) - requetes[iReq].deb;
		
		requetes[iReq].deb = newDeb;
		requetes[iReq].fin = newFin;
	}

	resoudre();

	form(iReq, nbRequetes) cout << requetes[iReq].rep << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 33528 KB Output is correct
2 Correct 43 ms 33400 KB Output is correct
3 Correct 36 ms 33408 KB Output is correct
4 Correct 37 ms 33408 KB Output is correct
5 Correct 37 ms 33480 KB Output is correct
6 Correct 42 ms 33400 KB Output is correct
7 Correct 36 ms 33408 KB Output is correct
8 Correct 36 ms 33408 KB Output is correct
9 Correct 38 ms 33408 KB Output is correct
10 Correct 37 ms 33400 KB Output is correct
11 Correct 39 ms 33452 KB Output is correct
12 Correct 39 ms 33400 KB Output is correct
13 Correct 44 ms 33400 KB Output is correct
14 Correct 38 ms 33408 KB Output is correct
15 Correct 36 ms 33400 KB Output is correct
16 Correct 37 ms 33400 KB Output is correct
17 Correct 41 ms 33400 KB Output is correct
18 Correct 38 ms 33400 KB Output is correct
19 Correct 37 ms 33400 KB Output is correct
20 Correct 46 ms 33400 KB Output is correct
21 Correct 42 ms 33372 KB Output is correct
22 Correct 39 ms 33436 KB Output is correct
23 Correct 37 ms 33408 KB Output is correct
24 Correct 38 ms 33400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 33528 KB Output is correct
2 Correct 43 ms 33400 KB Output is correct
3 Correct 36 ms 33408 KB Output is correct
4 Correct 37 ms 33408 KB Output is correct
5 Correct 37 ms 33480 KB Output is correct
6 Correct 42 ms 33400 KB Output is correct
7 Correct 36 ms 33408 KB Output is correct
8 Correct 36 ms 33408 KB Output is correct
9 Correct 38 ms 33408 KB Output is correct
10 Correct 37 ms 33400 KB Output is correct
11 Correct 39 ms 33452 KB Output is correct
12 Correct 39 ms 33400 KB Output is correct
13 Correct 44 ms 33400 KB Output is correct
14 Correct 38 ms 33408 KB Output is correct
15 Correct 36 ms 33400 KB Output is correct
16 Correct 37 ms 33400 KB Output is correct
17 Correct 41 ms 33400 KB Output is correct
18 Correct 38 ms 33400 KB Output is correct
19 Correct 37 ms 33400 KB Output is correct
20 Correct 46 ms 33400 KB Output is correct
21 Correct 42 ms 33372 KB Output is correct
22 Correct 39 ms 33436 KB Output is correct
23 Correct 37 ms 33408 KB Output is correct
24 Correct 38 ms 33400 KB Output is correct
25 Correct 183 ms 41704 KB Output is correct
26 Correct 63 ms 34424 KB Output is correct
27 Correct 265 ms 45148 KB Output is correct
28 Correct 261 ms 44944 KB Output is correct
29 Correct 215 ms 41848 KB Output is correct
30 Correct 189 ms 41364 KB Output is correct
31 Correct 207 ms 44028 KB Output is correct
32 Correct 264 ms 44932 KB Output is correct
33 Correct 232 ms 44536 KB Output is correct
34 Correct 141 ms 39032 KB Output is correct
35 Correct 259 ms 45304 KB Output is correct
36 Correct 271 ms 44924 KB Output is correct
37 Correct 167 ms 39672 KB Output is correct
38 Correct 303 ms 44020 KB Output is correct
39 Correct 72 ms 35064 KB Output is correct
40 Correct 283 ms 43884 KB Output is correct
41 Correct 212 ms 41336 KB Output is correct
42 Correct 279 ms 43896 KB Output is correct
43 Correct 140 ms 37340 KB Output is correct
44 Correct 300 ms 43944 KB Output is correct
45 Correct 76 ms 35320 KB Output is correct
46 Correct 281 ms 43992 KB Output is correct
47 Correct 87 ms 36216 KB Output is correct
48 Correct 264 ms 44024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 47332 KB Output is correct
2 Correct 687 ms 48880 KB Output is correct
3 Correct 448 ms 44144 KB Output is correct
4 Correct 556 ms 48972 KB Output is correct
5 Correct 228 ms 40308 KB Output is correct
6 Correct 591 ms 48752 KB Output is correct
7 Correct 476 ms 46704 KB Output is correct
8 Correct 544 ms 48752 KB Output is correct
9 Correct 95 ms 35832 KB Output is correct
10 Correct 596 ms 49008 KB Output is correct
11 Correct 338 ms 42940 KB Output is correct
12 Correct 594 ms 48752 KB Output is correct
13 Correct 251 ms 48168 KB Output is correct
14 Correct 247 ms 47936 KB Output is correct
15 Correct 251 ms 46608 KB Output is correct
16 Correct 227 ms 47004 KB Output is correct
17 Correct 307 ms 48516 KB Output is correct
18 Correct 241 ms 47300 KB Output is correct
19 Correct 282 ms 47340 KB Output is correct
20 Correct 280 ms 47592 KB Output is correct
21 Correct 237 ms 48100 KB Output is correct
22 Correct 258 ms 47720 KB Output is correct
23 Correct 270 ms 47728 KB Output is correct
24 Correct 249 ms 46368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 33528 KB Output is correct
2 Correct 43 ms 33400 KB Output is correct
3 Correct 36 ms 33408 KB Output is correct
4 Correct 37 ms 33408 KB Output is correct
5 Correct 37 ms 33480 KB Output is correct
6 Correct 42 ms 33400 KB Output is correct
7 Correct 36 ms 33408 KB Output is correct
8 Correct 36 ms 33408 KB Output is correct
9 Correct 38 ms 33408 KB Output is correct
10 Correct 37 ms 33400 KB Output is correct
11 Correct 39 ms 33452 KB Output is correct
12 Correct 39 ms 33400 KB Output is correct
13 Correct 44 ms 33400 KB Output is correct
14 Correct 38 ms 33408 KB Output is correct
15 Correct 36 ms 33400 KB Output is correct
16 Correct 37 ms 33400 KB Output is correct
17 Correct 41 ms 33400 KB Output is correct
18 Correct 38 ms 33400 KB Output is correct
19 Correct 37 ms 33400 KB Output is correct
20 Correct 46 ms 33400 KB Output is correct
21 Correct 42 ms 33372 KB Output is correct
22 Correct 39 ms 33436 KB Output is correct
23 Correct 37 ms 33408 KB Output is correct
24 Correct 38 ms 33400 KB Output is correct
25 Correct 183 ms 41704 KB Output is correct
26 Correct 63 ms 34424 KB Output is correct
27 Correct 265 ms 45148 KB Output is correct
28 Correct 261 ms 44944 KB Output is correct
29 Correct 215 ms 41848 KB Output is correct
30 Correct 189 ms 41364 KB Output is correct
31 Correct 207 ms 44028 KB Output is correct
32 Correct 264 ms 44932 KB Output is correct
33 Correct 232 ms 44536 KB Output is correct
34 Correct 141 ms 39032 KB Output is correct
35 Correct 259 ms 45304 KB Output is correct
36 Correct 271 ms 44924 KB Output is correct
37 Correct 167 ms 39672 KB Output is correct
38 Correct 303 ms 44020 KB Output is correct
39 Correct 72 ms 35064 KB Output is correct
40 Correct 283 ms 43884 KB Output is correct
41 Correct 212 ms 41336 KB Output is correct
42 Correct 279 ms 43896 KB Output is correct
43 Correct 140 ms 37340 KB Output is correct
44 Correct 300 ms 43944 KB Output is correct
45 Correct 76 ms 35320 KB Output is correct
46 Correct 281 ms 43992 KB Output is correct
47 Correct 87 ms 36216 KB Output is correct
48 Correct 264 ms 44024 KB Output is correct
49 Correct 558 ms 47332 KB Output is correct
50 Correct 687 ms 48880 KB Output is correct
51 Correct 448 ms 44144 KB Output is correct
52 Correct 556 ms 48972 KB Output is correct
53 Correct 228 ms 40308 KB Output is correct
54 Correct 591 ms 48752 KB Output is correct
55 Correct 476 ms 46704 KB Output is correct
56 Correct 544 ms 48752 KB Output is correct
57 Correct 95 ms 35832 KB Output is correct
58 Correct 596 ms 49008 KB Output is correct
59 Correct 338 ms 42940 KB Output is correct
60 Correct 594 ms 48752 KB Output is correct
61 Correct 251 ms 48168 KB Output is correct
62 Correct 247 ms 47936 KB Output is correct
63 Correct 251 ms 46608 KB Output is correct
64 Correct 227 ms 47004 KB Output is correct
65 Correct 307 ms 48516 KB Output is correct
66 Correct 241 ms 47300 KB Output is correct
67 Correct 282 ms 47340 KB Output is correct
68 Correct 280 ms 47592 KB Output is correct
69 Correct 237 ms 48100 KB Output is correct
70 Correct 258 ms 47720 KB Output is correct
71 Correct 270 ms 47728 KB Output is correct
72 Correct 249 ms 46368 KB Output is correct
73 Correct 1018 ms 58956 KB Output is correct
74 Correct 584 ms 50416 KB Output is correct
75 Correct 925 ms 58496 KB Output is correct
76 Correct 1183 ms 64112 KB Output is correct
77 Correct 571 ms 50772 KB Output is correct
78 Correct 857 ms 59760 KB Output is correct
79 Correct 1016 ms 61716 KB Output is correct
80 Correct 1045 ms 64036 KB Output is correct
81 Correct 428 ms 47928 KB Output is correct
82 Correct 784 ms 57200 KB Output is correct
83 Correct 864 ms 57164 KB Output is correct
84 Correct 1103 ms 64124 KB Output is correct
85 Correct 601 ms 57156 KB Output is correct
86 Correct 760 ms 62180 KB Output is correct
87 Correct 321 ms 49172 KB Output is correct
88 Correct 902 ms 61180 KB Output is correct
89 Correct 654 ms 59428 KB Output is correct
90 Correct 1000 ms 61424 KB Output is correct
91 Correct 450 ms 52948 KB Output is correct
92 Correct 840 ms 61664 KB Output is correct
93 Correct 445 ms 51272 KB Output is correct
94 Correct 778 ms 61800 KB Output is correct
95 Correct 379 ms 52052 KB Output is correct
96 Correct 826 ms 60408 KB Output is correct