| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 48257 | DrSwad | Poklon (COCI17_poklon) | C++11 | 1390 ms | 20848 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"
#define RUNTIME prinf("%lf\n",(double)clock()/CLOCKS_PER_SEC);
typedef long long ll;
const int N = int(5e5) + 10;
int n, sq, q;
int a[N];
int cnt[N];
int answer[N];
struct query {
	int id, l, r, ans;
	query() {scanf("%d %d", &l, &r); l--; r--;}
	bool operator < (query& q2) {
		return r < q2.r;
	}
};
vector<query> blk[1000];
int main() {
	/*freopen("out", "w", stdout);
	freopen("in", "r", stdin);*/
	//ios::sync_with_stdio(false);cin.tie(NULL);
	scanf("%d %d", &n, &q);
	sq = (int)sqrt(n + 0.5);
	vector<int> tmp(n);
	for (int i = 0; i < n; i++) scanf("%d", a+i), tmp[i] = a[i];
	sort(tmp.begin(), tmp.end());
	for (int i = 0; i < n; i++)
		a[i] = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin();
	for (int i = 0; i < q; i++) {
		query qq; qq.id = i;
		blk[qq.l/sq].push_back(qq);
	}
	for (int i = 0; i < 1000; i++)
		sort(blk[i].begin(), blk[i].end());
	for (int bi = 0; bi < 1000; bi++) {
		vector<query>& blkq = blk[bi];
		int l = sq*bi, r = sq*bi, qi = 0, totq = blkq.size();
		int ans = 0;
		memset(cnt, 0, sizeof cnt);
		for (; r < n; r++) {
			cnt[a[r]]++;
			if (cnt[a[r]] == 2) ans++;
			if (cnt[a[r]] == 3) ans--;
			while (qi < totq && r == blkq[qi].r) {
				while (l != blkq[qi].l) {
					if (l < blkq[qi].l) {
						cnt[a[l]]--;
						if (cnt[a[l]] == 1) ans--;
						else if (cnt[a[l]] == 2) ans++;
						l++;
					}
					else {
						l--;
						cnt[a[l]]++;
						if (cnt[a[l]] == 2) ans++;
						else if (cnt[a[l]] == 3) ans--;
					}
				}
				answer[blkq[qi].id] = ans;
				qi++;
			}
		}
	}
	for (int i = 0; i < q; i++) printf("%d\n", answer[i]);
	//RUNTIME
	return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
