Submission #31021283


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using pii = pair<int, int>;
using ll = long long;

const int inf = 1e9;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	vector<vector<int>> id(n);
	rep(i, n) {
		id[a[i] - 1].push_back(i);
	}
	rep(i, n) id[i].push_back(inf);

	int q;
	cin >> q;
	rep(i, q) {
		int l, r, x;
		cin >> l >> r >> x;
		l--, r--, x--;
		auto itr1 = lower_bound(id[x].begin(), id[x].end(), l);
		auto itr2 = upper_bound(id[x].begin(), id[x].end(), r);
		int ans = itr2 - itr1;
		cout << ans << endl;
	}
	return 0;
}

Submission Info

Submission Time
Task D - Range Count Query
User icchipost
Language C++ (GCC 9.2.1)
Score 400
Code Size 649 Byte
Status AC
Exec Time 509 ms
Memory 16216 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 1
AC × 18
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 02_max_01.txt, 02_max_02.txt, 02_max_03.txt, 02_max_04.txt, 02_max_05.txt, 02_max_06.txt, 02_max_07.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 8 ms 3464 KiB
01_random_01.txt AC 236 ms 6772 KiB
01_random_02.txt AC 123 ms 5412 KiB
01_random_03.txt AC 218 ms 8244 KiB
01_random_04.txt AC 57 ms 10672 KiB
01_random_05.txt AC 271 ms 15640 KiB
01_random_06.txt AC 335 ms 8928 KiB
01_random_07.txt AC 232 ms 5496 KiB
01_random_08.txt AC 471 ms 9864 KiB
01_random_09.txt AC 420 ms 10668 KiB
01_random_10.txt AC 167 ms 9568 KiB
02_max_01.txt AC 481 ms 15716 KiB
02_max_02.txt AC 473 ms 16216 KiB
02_max_03.txt AC 479 ms 15948 KiB
02_max_04.txt AC 509 ms 15116 KiB
02_max_05.txt AC 507 ms 14940 KiB
02_max_06.txt AC 508 ms 15048 KiB
02_max_07.txt AC 501 ms 14952 KiB