# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371002 | FatihSolak | Poklon (COCI17_poklon) | C++17 | 4 ms | 364 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>
#define N 500005
using namespace std;
int arr[N];
int ans[N];
int cnt[N];
map<int,int> mp;
int block = 700;
bool comp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
if(a.first.first/block == b.first.first/block){
return a.first.second < b.first.second;
}
return a.first.first/block < b.first.first/block;
}
int t;
int sum;
void upd(int pos,int val){
sum -= (cnt[arr[pos]] == 2);
cnt[arr[pos]] += val;
sum += (cnt[arr[pos]] == 2);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int n,q;
cin >> n >> q;
for(int i=1;i<=n;i++){
int a;
cin >> a;
if(!mp[a])mp[a] = ++t;
arr[i] = mp[a];
}
vector<pair<pair<int,int>,int>> query;
for(int i=0;i<q;i++){
int l,r;
cin >> l >> r;
query.push_back({{l,r},i});
}
sort(query.begin(), query.end(),comp);
int l = 0,r = -1;
for(auto u: query){
int lq = u.first.first;
int rq = u.first.second;
while(l > lq){
upd(--l,1);
}
while(r < rq){
upd(++r,1);
}
while(l < lq){
upd(l++,-1);
}
while(r > rq){
upd(r--,-1);
}
ans[u.second] = sum;
}
for(int i=0;i<q;i++){
cout << ans[i] << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |