Submission #375626

# Submission time Handle Problem Language Result Execution time Memory
375626 2021-03-09T15:43:16 Z peijar Examination (JOI19_examination) C++17
100 / 100
641 ms 47768 KB
#include <bits/stdc++.h>
using namespace std;

struct CountLess
{
	vector<int> values;
	vector<vector<int>> seg;
	vector<int> iDeb, iFin;

	CountLess(const vector<int> &_values) : values(_values)
	{
		int p(0);
		while ((1 << p) < (int)values.size()) ++p;
		seg.resize((1 << (p+1))+1);
		iDeb.resize((1 <<(p+1))+1);
		iFin.resize((1<<(p+1))+1);
		build(1, 0, (int)values.size() - 1);
	};

	void build(int iNoeud, int deb, int fin)
	{
		iDeb[iNoeud] = deb;
		iFin[iNoeud] = fin;
		if (deb == fin)
		{
			seg[iNoeud] = {values[deb]};
			return ;
		}
		build(2*iNoeud, deb, (deb+fin)/2);
		build(2*iNoeud+1, (deb+fin)/2+1, fin);
		seg[iNoeud].resize(seg[2*iNoeud].size() + seg[2*iNoeud+1].size());
		merge(seg[2*iNoeud].begin(), seg[2*iNoeud].end(),
												seg[2*iNoeud+1].begin(), seg[2*iNoeud+1].end(),
												seg[iNoeud].begin());
	}

	int countGreater(int iNoeud, int iDebR, int iFinR, int borne)
	{
		if (iFinR < iDeb[iNoeud] or iDebR > iFin[iNoeud])
			return 0;
		if (iDeb[iNoeud] >= iDebR and iFin[iNoeud] <= iFinR)
		{
			int pos = lower_bound(seg[iNoeud].begin(), seg[iNoeud].end(), borne)
				- seg[iNoeud].begin();
			return (int)seg[iNoeud].size() - pos;
		}
		return countGreater(2*iNoeud, iDebR, iFinR, borne)
			+ countGreater(2*iNoeud+1, iDebR, iFinR, borne);
	}
};

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

	int nbEleves, nbRequetes;
	cin >> nbEleves >> nbRequetes;
	vector<pair<int, int>> notes(nbEleves);
	for (auto &[noteMaths, noteInfo] : notes)
		cin >> noteMaths >> noteInfo;
	sort(notes.begin(), notes.end());

	vector<int> notesInfo(nbEleves);
	vector<int> sommeNotes(nbEleves);
	for (int i(0); i < nbEleves; ++i)
	{
		notesInfo[i] = notes[i].second;
		sommeNotes[i] = notes[i].first + notes[i].second;
	}

	CountLess countInfo(notesInfo), countSomme(sommeNotes);
	for (int iRequete(0); iRequete < nbRequetes; ++iRequete)
	{
		int mathsMin, infoMin, sommeMin;
		cin >> mathsMin >> infoMin >> sommeMin;
		int posDepart = lower_bound(notes.begin(), notes.end(), make_pair(mathsMin, 0)) - notes.begin();
		// info >= infoMin et info >= sommeMin - maths
		// sommeMin - maths >= infoMin <=> maths <= sommeMin - infoMin
		int posDebInfo = upper_bound(notes.begin(), notes.end(), make_pair(sommeMin-infoMin, -1)) - notes.begin();
		if (posDebInfo < posDepart) posDebInfo = posDepart;
		int ret(0);
		if (posDepart < posDebInfo)
			ret += countSomme.countGreater(1, posDepart, posDebInfo-1, sommeMin);
		if (posDebInfo < nbEleves)
			ret += countInfo.countGreater(1, posDebInfo, nbEleves-1, infoMin);
		cout << ret << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 8 ms 1644 KB Output is correct
8 Correct 9 ms 1772 KB Output is correct
9 Correct 8 ms 1772 KB Output is correct
10 Correct 10 ms 1644 KB Output is correct
11 Correct 6 ms 1644 KB Output is correct
12 Correct 5 ms 1516 KB Output is correct
13 Correct 7 ms 1644 KB Output is correct
14 Correct 7 ms 1792 KB Output is correct
15 Correct 9 ms 1644 KB Output is correct
16 Correct 5 ms 1644 KB Output is correct
17 Correct 7 ms 1644 KB Output is correct
18 Correct 4 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 45256 KB Output is correct
2 Correct 384 ms 45164 KB Output is correct
3 Correct 341 ms 45420 KB Output is correct
4 Correct 348 ms 44652 KB Output is correct
5 Correct 207 ms 44524 KB Output is correct
6 Correct 170 ms 43756 KB Output is correct
7 Correct 288 ms 45164 KB Output is correct
8 Correct 307 ms 45292 KB Output is correct
9 Correct 253 ms 45036 KB Output is correct
10 Correct 140 ms 44268 KB Output is correct
11 Correct 282 ms 44440 KB Output is correct
12 Correct 122 ms 43500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 45256 KB Output is correct
2 Correct 384 ms 45164 KB Output is correct
3 Correct 341 ms 45420 KB Output is correct
4 Correct 348 ms 44652 KB Output is correct
5 Correct 207 ms 44524 KB Output is correct
6 Correct 170 ms 43756 KB Output is correct
7 Correct 288 ms 45164 KB Output is correct
8 Correct 307 ms 45292 KB Output is correct
9 Correct 253 ms 45036 KB Output is correct
10 Correct 140 ms 44268 KB Output is correct
11 Correct 282 ms 44440 KB Output is correct
12 Correct 122 ms 43500 KB Output is correct
13 Correct 460 ms 45676 KB Output is correct
14 Correct 458 ms 45548 KB Output is correct
15 Correct 336 ms 45164 KB Output is correct
16 Correct 451 ms 44908 KB Output is correct
17 Correct 212 ms 44780 KB Output is correct
18 Correct 218 ms 43784 KB Output is correct
19 Correct 459 ms 45548 KB Output is correct
20 Correct 520 ms 45676 KB Output is correct
21 Correct 551 ms 45676 KB Output is correct
22 Correct 145 ms 44268 KB Output is correct
23 Correct 270 ms 44396 KB Output is correct
24 Correct 147 ms 43372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 8 ms 1644 KB Output is correct
8 Correct 9 ms 1772 KB Output is correct
9 Correct 8 ms 1772 KB Output is correct
10 Correct 10 ms 1644 KB Output is correct
11 Correct 6 ms 1644 KB Output is correct
12 Correct 5 ms 1516 KB Output is correct
13 Correct 7 ms 1644 KB Output is correct
14 Correct 7 ms 1792 KB Output is correct
15 Correct 9 ms 1644 KB Output is correct
16 Correct 5 ms 1644 KB Output is correct
17 Correct 7 ms 1644 KB Output is correct
18 Correct 4 ms 1516 KB Output is correct
19 Correct 381 ms 45256 KB Output is correct
20 Correct 384 ms 45164 KB Output is correct
21 Correct 341 ms 45420 KB Output is correct
22 Correct 348 ms 44652 KB Output is correct
23 Correct 207 ms 44524 KB Output is correct
24 Correct 170 ms 43756 KB Output is correct
25 Correct 288 ms 45164 KB Output is correct
26 Correct 307 ms 45292 KB Output is correct
27 Correct 253 ms 45036 KB Output is correct
28 Correct 140 ms 44268 KB Output is correct
29 Correct 282 ms 44440 KB Output is correct
30 Correct 122 ms 43500 KB Output is correct
31 Correct 460 ms 45676 KB Output is correct
32 Correct 458 ms 45548 KB Output is correct
33 Correct 336 ms 45164 KB Output is correct
34 Correct 451 ms 44908 KB Output is correct
35 Correct 212 ms 44780 KB Output is correct
36 Correct 218 ms 43784 KB Output is correct
37 Correct 459 ms 45548 KB Output is correct
38 Correct 520 ms 45676 KB Output is correct
39 Correct 551 ms 45676 KB Output is correct
40 Correct 145 ms 44268 KB Output is correct
41 Correct 270 ms 44396 KB Output is correct
42 Correct 147 ms 43372 KB Output is correct
43 Correct 520 ms 47768 KB Output is correct
44 Correct 497 ms 47556 KB Output is correct
45 Correct 482 ms 47520 KB Output is correct
46 Correct 492 ms 46248 KB Output is correct
47 Correct 221 ms 45976 KB Output is correct
48 Correct 180 ms 43628 KB Output is correct
49 Correct 556 ms 47508 KB Output is correct
50 Correct 466 ms 47644 KB Output is correct
51 Correct 641 ms 47408 KB Output is correct
52 Correct 165 ms 45804 KB Output is correct
53 Correct 278 ms 45164 KB Output is correct