# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44779 | evpipis | Poklon (COCI17_poklon) | C++11 | 2074 ms | 36092 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.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef pair<int, int> ii;
const int len = 5e5+5;
int arr[len], ans, k, cnt[len];
pair<int, ii> ask[len];
map<int, int> mymap;
bool comp(pair<int, ii> a, pair<int, ii> b){
if (a.se.fi/k < b.se.fi/k) return true;
if (a.se.fi/k > b.se.fi/k) return false;
return (a.se.se < b.se.se);
}
void add(int i, int x){
if (cnt[arr[i]] == 2) ans--;
cnt[arr[i]] += x;
if (cnt[arr[i]] == 2) ans++;
}
int main(){
int n, q, cur = 0, temp;
scanf("%d %d", &n, &q);
k = sqrt(n);
for (int i = 0; i < n; i++){
scanf("%d", &temp);
if (!mymap.count(temp))
arr[i] = mymap[temp] = cur++;
else
arr[i] = mymap[temp];
}
for (int i = 0; i < q; i++){
scanf("%d %d", &ask[i].se.fi, &ask[i].se.se);
ask[i].se.fi--, ask[i].se.se--;
ask[i].fi = i;
}
sort(ask, ask+q, comp);
int l = 0, r = -1;
for (int i = 0; i < q; i++){
while (r < ask[i].se.se)
r++, add(r, 1);
while (r > ask[i].se.se)
add(r, -1), r--;
while (l < ask[i].se.fi)
add(l, -1), l++;
while (l > ask[i].se.fi)
l--, add(l, 1);
ask[i].se.fi = ans;
}
sort(ask, ask+q);
for (int i = 0; i < q; i++)
printf("%d\n", ask[i].se.fi);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |