# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
401516 | NintsiChkhaidze | Poklon (COCI17_poklon) | C++14 | 167 ms | 40588 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int long long
#define left (node<<1),l,((l+r)>>1)
#define right ((node<<1)|1),((l+r)>>1) + 1,r
using namespace std;
const int Bl = 707,N = 500005;
pair<pair<int,int>,int> d[N];
int ans[N],res,a[N];
map <int,int> cnt;
bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
if (a.f.f/Bl == b.f.f/Bl)
return a.f.s < b.f.s;
return a.f.f/Bl < b.f.f<Bl;
}
void add(int ind){
if (cnt[a[ind]] == 2) res--;
cnt[a[ind]]++;
if(cnt[a[ind]] == 2) res++;
}
void remove(int ind){
if (cnt[a[ind]] == 2) res--;
cnt[a[ind]]--;
if(cnt[a[ind]] == 2) res++;
}
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=m;i++){
int l,r;
cin>>l>>r;
d[i] = {{l,r},i};
}
sort(d+1,d+m+1,cmp);
int L = 0,R = -1;
for (int i=1;i<=m;i++){
int l = d[i].f.f,r = d[i].f.s,idx = d[i].s;
while (L > l) add(--L);
while (R < r) add(++R);
while (L < l) remove(L++);
while (R > r) remove(R--);
ans[idx] = res;
}
for (int i=1;i<=m;i++)
cout<<ans[i]<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |