# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1024020 | kustizus | Poklon (COCI17_poklon) | C++17 | 2197 ms | 19636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int n, q, cn, a[N + 5], ans[N + 5];
struct Node
{
int l, r, pos;
};
vector<Node> qu;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen ("file.inp","r",stdin);
// freopen ("file.out","w",stdout);
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= q; i++)
{
int l, r;
cin >> l >> r;
qu.push_back({l, r, i});
}
cn = sqrt(n);
sort(qu.begin(), qu.end(), [&](Node a, Node b)
{ return a.l / cn < b.l / cn || (a.l / cn == b.l / cn && a.r < b.r); });
int l = 1, r = 0, now = 0;
unordered_map<int, int> mp;
for (int i = 0; i < q; i++)
{
while (l < qu[i].l)
{
int x = --mp[a[l]];
if (x == 2)
now++;
else if (x == 1)
now--;
++l;
}
while (l > qu[i].l)
{
--l;
int x = ++mp[a[l]];
if (x == 2)
now++;
else if (x == 3)
now--;
}
while (r > qu[i].r)
{
int x = --mp[a[r]];
if (x == 2)
now++;
else if (x == 1)
now--;
r--;
}
while (r < qu[i].r)
{
r++;
int x = ++mp[a[r]];
if (x == 2)
now++;
else if (x == 3)
now--;
}
ans[qu[i].pos] = now;
}
for (int i = 1; i <= q; i++)
cout << ans[i] << "\n";
return 0;
}
// hay
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |