Submission #519758

# Submission time Handle Problem Language Result Execution time Memory
519758 2022-01-27T09:46:20 Z SiddhantAttavar Poklon (COCI17_poklon) C++14
56 / 140
5000 ms 8040 KB
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline void input(T& inVar) {cin >> inVar;}
template<typename T, typename... S> inline void input(T& inVar, S&... args) {cin >> inVar; input(args ...);}
template<typename T> inline void print(T outVar) {cout << outVar << endl;}
template<typename T, typename... S> inline void print(T outVar, S... args) {cout << outVar << ' '; print(args ...);}
#define range(it, start, end) for (int it = start; it < end; it++)
#define arrPut(var) for (auto &inVar : var) {cin >> inVar;}
#define arrPrint(var) for (auto outVar : var) {cout << outVar << ' ';} cout << endl
#define setup() ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long

int32_t main() {
	setup();

	int n, q;
	input(n, q);
	
	map<int, vector<int>> m;
	range(i, 0, n) {
		int x;
		input(x);
		m[x].push_back(i);
	}

	while (q--) {
		int l, r;
		input(l, r);
		l--;
		r--;

		int res = 0;
		for (pair<int, vector<int>> p : m) {
			vector<int> v = p.second;
			int x = lower_bound(v.begin(), v.end(), l) - v.begin();
			int y = upper_bound(v.begin(), v.end(), r) - v.begin();
			
			if (y - x == 2) {
				res++;
			}
		}

		print(res);
	}
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 50 ms 460 KB Output is correct
5 Execution timed out 5020 ms 2956 KB Time limit exceeded
6 Execution timed out 5053 ms 2868 KB Time limit exceeded
7 Execution timed out 5088 ms 3928 KB Time limit exceeded
8 Execution timed out 5029 ms 6548 KB Time limit exceeded
9 Execution timed out 5033 ms 7640 KB Time limit exceeded
10 Execution timed out 5070 ms 8040 KB Time limit exceeded