# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
371003 | FatihSolak | Poklon (COCI17_poklon) | C++17 | 3138 ms | 19960 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |