# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
62653 | win11905 | Poklon (COCI17_poklon) | C++11 | 5096 ms | 40132 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define iii tuple<int, int, int>
#define pii pair<int, int>
#define x first
#define y second
const int N = 5e5+5;
const int sz = 708;
int n, m, A[N], ans[N];
vector<iii> block[sz];
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i) scanf("%d", A+i);
for(int i = 0, a, b; i < m; ++i) {
scanf("%d %d", &a, &b);
block[a/sz].emplace_back(a, b, i);
}
for(int i = 0; i < sz; ++i) {
sort(block[i].begin(), block[i].end(), [&](const iii &a, const iii &b) {
return get<1>(a) < get<1>(b);
});
int l = i * sz, r = i * sz;
map<int, int> M;
int cnt = 0;
auto add = [&](int v) {
if(M[v] == 2) cnt--;
if(M[v] == 1) cnt++;
M[v]++;
};
auto del = [&](int v) {
if(M[v] == 3) cnt++;
if(M[v] == 2) cnt--;
M[v]--;
};
for(iii z : block[i]) {
int p, x, y; tie(x, y, p) = z;
while(r <= y) add(A[r++]);
while(l < x) del(A[l++]);
while(l > x) add(A[--l]);
ans[p] = cnt;
}
}
for_each(ans, ans+m, [](int x) { printf("%d\n", x); });
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |