Submission #383336

# Submission time Handle Problem Language Result Execution time Memory
383336 2021-03-29T16:30:40 Z peijar Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1351 ms 93236 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Requete
{
	int deb, fin, patience, iRequete;

	bool operator<(Requete other) const
	{
		return patience < other.patience;
	}
};

const int NB_FEUILLES = 1 << 20;

int seg[2 * NB_FEUILLES];

void init()
{
	for (int i(0); i < 2 * NB_FEUILLES; ++i) seg[i]= -1;
}

void upd(int iPos, int val)
{
	iPos += NB_FEUILLES;
	seg[iPos] = val;
	while (iPos > 1)
	{
		iPos /= 2;
		seg[iPos] = max(seg[2*iPos], seg[2*iPos+1]);
	}
}

int query(int deb, int fin)
{
	deb += NB_FEUILLES, fin += NB_FEUILLES;
	int sol(-1);
	while (deb < fin)
	{
		if (deb % 2)
			sol = max(sol, seg[deb++]);
		if (fin%2==0)
			sol = max(sol, seg[fin--]);
		deb /= 2; fin /= 2;
	}
	if (deb == fin) sol = max(sol, seg[deb]);
	return sol;
}

signed main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int nbLivres, nbRequetes;
	cin >> nbLivres >> nbRequetes;
	vector<int> poids(nbLivres);
	for (auto &v : poids) cin >> v;
	vector<Requete> requetes(nbRequetes);
	for (int iRequete = 0; iRequete < nbRequetes; ++iRequete) 
	{
		auto &r = requetes[iRequete];
		cin >> r.deb >> r.fin >> r.patience;
		r.deb--, r.fin--;
		r.iRequete = iRequete;
	}
	sort(requetes.begin(), requetes.end());
	vector<int> lft(nbLivres);
	for (int iLivre = 0; iLivre < nbLivres; ++iLivre) 
	{
		lft[iLivre] = iLivre-1;
		while (lft[iLivre] != -1 and poids[lft[iLivre]] <= poids[iLivre])
			lft[iLivre] = lft[lft[iLivre]];
	}
	vector<pair<int, int>> aAjouter;
	for (int iLivre = 0; iLivre < nbLivres; ++iLivre) 
		if (lft[iLivre] != -1)
			aAjouter.emplace_back(poids[iLivre] + poids[lft[iLivre]], iLivre);
	sort(aAjouter.begin(), aAjouter.end());
	init();
	vector<bool> solRequete(nbRequetes);
	vector<int> curVal(nbLivres, -1);
	for (int iRequete(nbRequetes-1); iRequete >= 0; --iRequete)
	{
		while (!aAjouter.empty() and aAjouter.back().first > requetes[iRequete].patience)
		{
			upd(aAjouter.back().second, lft[aAjouter.back().second]);
			curVal[aAjouter.back().second] = lft[aAjouter.back().second];
			aAjouter.pop_back();
		}
		solRequete[requetes[iRequete].iRequete] = query(requetes[iRequete].deb, requetes[iRequete].fin) < requetes[iRequete].deb;
	}
	for (auto v : solRequete)
		cout << v << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 13 ms 16748 KB Output is correct
3 Correct 11 ms 16752 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 12 ms 16832 KB Output is correct
7 Correct 13 ms 16752 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 11 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 13 ms 16748 KB Output is correct
3 Correct 11 ms 16752 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 12 ms 16832 KB Output is correct
7 Correct 13 ms 16752 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 11 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
11 Correct 15 ms 16876 KB Output is correct
12 Correct 15 ms 17132 KB Output is correct
13 Correct 16 ms 17132 KB Output is correct
14 Correct 17 ms 17260 KB Output is correct
15 Correct 15 ms 17268 KB Output is correct
16 Correct 17 ms 17132 KB Output is correct
17 Correct 16 ms 17004 KB Output is correct
18 Correct 16 ms 17132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1310 ms 89456 KB Output is correct
2 Correct 1314 ms 89424 KB Output is correct
3 Correct 1351 ms 89320 KB Output is correct
4 Correct 1300 ms 89404 KB Output is correct
5 Correct 977 ms 73708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 24036 KB Output is correct
2 Correct 116 ms 24036 KB Output is correct
3 Correct 94 ms 22496 KB Output is correct
4 Correct 78 ms 22508 KB Output is correct
5 Correct 83 ms 22508 KB Output is correct
6 Correct 81 ms 22756 KB Output is correct
7 Correct 72 ms 22768 KB Output is correct
8 Correct 79 ms 23524 KB Output is correct
9 Correct 56 ms 20076 KB Output is correct
10 Correct 87 ms 23516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 13 ms 16748 KB Output is correct
3 Correct 11 ms 16752 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 12 ms 16832 KB Output is correct
7 Correct 13 ms 16752 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 11 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
11 Correct 15 ms 16876 KB Output is correct
12 Correct 15 ms 17132 KB Output is correct
13 Correct 16 ms 17132 KB Output is correct
14 Correct 17 ms 17260 KB Output is correct
15 Correct 15 ms 17268 KB Output is correct
16 Correct 17 ms 17132 KB Output is correct
17 Correct 16 ms 17004 KB Output is correct
18 Correct 16 ms 17132 KB Output is correct
19 Correct 236 ms 31324 KB Output is correct
20 Correct 239 ms 31324 KB Output is correct
21 Correct 254 ms 31256 KB Output is correct
22 Correct 251 ms 37844 KB Output is correct
23 Correct 225 ms 37744 KB Output is correct
24 Correct 172 ms 34456 KB Output is correct
25 Correct 177 ms 34456 KB Output is correct
26 Correct 173 ms 34780 KB Output is correct
27 Correct 198 ms 34796 KB Output is correct
28 Correct 199 ms 34704 KB Output is correct
29 Correct 185 ms 34712 KB Output is correct
30 Correct 179 ms 34796 KB Output is correct
31 Correct 189 ms 34796 KB Output is correct
32 Correct 180 ms 34712 KB Output is correct
33 Correct 174 ms 34728 KB Output is correct
34 Correct 164 ms 34412 KB Output is correct
35 Correct 177 ms 34328 KB Output is correct
36 Correct 159 ms 34156 KB Output is correct
37 Correct 154 ms 34156 KB Output is correct
38 Correct 158 ms 34412 KB Output is correct
39 Correct 182 ms 34404 KB Output is correct
40 Correct 165 ms 31596 KB Output is correct
41 Correct 174 ms 34788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16748 KB Output is correct
2 Correct 13 ms 16748 KB Output is correct
3 Correct 11 ms 16752 KB Output is correct
4 Correct 13 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 12 ms 16832 KB Output is correct
7 Correct 13 ms 16752 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 11 ms 16748 KB Output is correct
10 Correct 12 ms 16748 KB Output is correct
11 Correct 15 ms 16876 KB Output is correct
12 Correct 15 ms 17132 KB Output is correct
13 Correct 16 ms 17132 KB Output is correct
14 Correct 17 ms 17260 KB Output is correct
15 Correct 15 ms 17268 KB Output is correct
16 Correct 17 ms 17132 KB Output is correct
17 Correct 16 ms 17004 KB Output is correct
18 Correct 16 ms 17132 KB Output is correct
19 Correct 1310 ms 89456 KB Output is correct
20 Correct 1314 ms 89424 KB Output is correct
21 Correct 1351 ms 89320 KB Output is correct
22 Correct 1300 ms 89404 KB Output is correct
23 Correct 977 ms 73708 KB Output is correct
24 Correct 103 ms 24036 KB Output is correct
25 Correct 116 ms 24036 KB Output is correct
26 Correct 94 ms 22496 KB Output is correct
27 Correct 78 ms 22508 KB Output is correct
28 Correct 83 ms 22508 KB Output is correct
29 Correct 81 ms 22756 KB Output is correct
30 Correct 72 ms 22768 KB Output is correct
31 Correct 79 ms 23524 KB Output is correct
32 Correct 56 ms 20076 KB Output is correct
33 Correct 87 ms 23516 KB Output is correct
34 Correct 236 ms 31324 KB Output is correct
35 Correct 239 ms 31324 KB Output is correct
36 Correct 254 ms 31256 KB Output is correct
37 Correct 251 ms 37844 KB Output is correct
38 Correct 225 ms 37744 KB Output is correct
39 Correct 172 ms 34456 KB Output is correct
40 Correct 177 ms 34456 KB Output is correct
41 Correct 173 ms 34780 KB Output is correct
42 Correct 198 ms 34796 KB Output is correct
43 Correct 199 ms 34704 KB Output is correct
44 Correct 185 ms 34712 KB Output is correct
45 Correct 179 ms 34796 KB Output is correct
46 Correct 189 ms 34796 KB Output is correct
47 Correct 180 ms 34712 KB Output is correct
48 Correct 174 ms 34728 KB Output is correct
49 Correct 164 ms 34412 KB Output is correct
50 Correct 177 ms 34328 KB Output is correct
51 Correct 159 ms 34156 KB Output is correct
52 Correct 154 ms 34156 KB Output is correct
53 Correct 158 ms 34412 KB Output is correct
54 Correct 182 ms 34404 KB Output is correct
55 Correct 165 ms 31596 KB Output is correct
56 Correct 174 ms 34788 KB Output is correct
57 Correct 1311 ms 93140 KB Output is correct
58 Correct 1294 ms 93008 KB Output is correct
59 Correct 1302 ms 92972 KB Output is correct
60 Correct 1280 ms 93092 KB Output is correct
61 Correct 1337 ms 93236 KB Output is correct
62 Correct 1292 ms 92972 KB Output is correct
63 Correct 796 ms 77032 KB Output is correct
64 Correct 828 ms 77164 KB Output is correct
65 Correct 986 ms 77292 KB Output is correct
66 Correct 936 ms 77292 KB Output is correct
67 Correct 924 ms 77360 KB Output is correct
68 Correct 946 ms 77420 KB Output is correct
69 Correct 890 ms 77420 KB Output is correct
70 Correct 933 ms 77400 KB Output is correct
71 Correct 945 ms 77396 KB Output is correct
72 Correct 1030 ms 77344 KB Output is correct
73 Correct 709 ms 77036 KB Output is correct
74 Correct 761 ms 76976 KB Output is correct
75 Correct 729 ms 77160 KB Output is correct
76 Correct 723 ms 77032 KB Output is correct
77 Correct 719 ms 76976 KB Output is correct
78 Correct 995 ms 82256 KB Output is correct
79 Correct 687 ms 67756 KB Output is correct
80 Correct 893 ms 88040 KB Output is correct