# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
987642 | tamthegod | Poklon (COCI17_poklon) | C++17 | 240 ms | 13516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 5, maxsz = 1e6 + 5, b = 500;
ll n, q, a[maxn], res = 0;
ll cnt[maxsz], ans[maxn];
struct Query
{
ll l, r, id;
} qu[maxn];
void add(ll x) {
res -= (cnt[x] == 2);
cnt[x]++;
res += (cnt[x] == 2);
}
void del(ll x) {
res -= (cnt[x] == 2);
cnt[x]--;
res += (cnt[x] == 2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q;
for (ll i = 1; i <= n; i++) {
cin >> a[i];
}
for (ll i = 1; i <= q; i++) {
cin >> qu[i].l >> qu[i].r;
qu[i].id = i;
}
sort(qu + 1, qu + q + 1, [](Query p, Query q) {
ll x = ((p.l - 1) / b + 1), y = (q.l - 1) / b + 1;
return (x < y || (x == y && p.r < q.r));
});
ll l = 1, r = 0;
for (ll i = 1; i <= q; i++) {
while(l < qu[i].l) {
del(a[l]);
l++;
}
while(l > qu[i].l) {
l--;
add(a[l]);
}
while(r < qu[i].r) {
r++;
add(a[r]);
}
while(r > qu[i].r) {
del(a[r]);
r--;
}
ans[qu[i].id] = res;
}
for (ll i = 1; i <= q; i++) {
cout << ans[i] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |