# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
706595 | YugiHacker | Poklon (COCI17_poklon) | C++14 | 1809 ms | 23408 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn 500005
using namespace std;
int n, m, block, res;
int a[maxn], b[maxn], d[maxn], ans[maxn];
struct query
{
int l, r, id;
}q[maxn];
bool cmp (query q1, query q2)
{
if (q1.l/block == q2.l/block) return q1.r < q2.r;
return q1.l < q2.l;
}
void sub(int x)
{
d[a[x]]--;
if (d[a[x]] == 1) res--;
if (d[a[x]] == 2) res++;
}
void add(int x)
{
d[a[x]]++;
if (d[a[x]] == 2) res++;
if (d[a[x]] == 3) res--;
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
f1 (i, n) cin >> a[i], b[i] = a[i];
sort(b+1, b+n+1);
f1 (i, n) a[i] = lower_bound(b+1, b+n+1, a[i]) - b;
f1 (i, m)
{
int l, r;
cin >> l >> r;
q[i] = {l, r, i};
}
block = sqrt(n);
sort(q+1, q+m+1, cmp);
int L = 0, R = 0;
f1 (i, m)
{
while (L<q[i].l) sub(L++);
while (L>q[i].l) add(--L);
while (R<q[i].r) add(++R);
while (R>q[i].r) sub(R--);
ans[q[i].id] = res;
}
f1 (i, m) cout << ans[i] << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |