# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
570728 | YouAreMyGalaxy | Poklon (COCI17_poklon) | C++17 | 597 ms | 37376 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Make CSP great again
//You're as beautiful as the day I lost you
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 5e5;
int n, q, a[N + 1], res[N + 1];
struct FenwickTree
{
int Tree[N + 1];
void add(int pos, int val)
{
if (pos == 0)
{
return ;
}
for (; pos <= n; pos += pos & (-pos))
{
Tree[pos] += val;
}
}
int sum(int pos)
{
int ret = 0;
for (; pos > 0; pos -= pos & (-pos))
{
ret += Tree[pos];
}
return ret;
}
int sum(int l, int r)
{
return sum(r) - sum(l - 1);
}
} Tree;
vector<pair<int, int> > Query[N + 1];
map<int, int> Map[3];
void read()
{
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;
Query[r].push_back(make_pair(i, l));
}
}
void solve()
{
for (int i = 1; i <= n; ++ i)
{
Tree.add(Map[2][a[i]], 1);
Map[2][a[i]] = Map[1][a[i]];
Tree.add(Map[2][a[i]], -2);
Map[1][a[i]] = Map[0][a[i]];
Tree.add(Map[1][a[i]], 1);
Map[0][a[i]] = i;
for (auto x : Query[i])
{
res[x.first] = Tree.sum(x.second, i);
}
}
for (int i = 1; i <= q; ++ i)
{
cout << res[i] << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |