| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 40981 | IvanC | Poklon (COCI17_poklon) | C++14 | 5183 ms | 524288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LSOne(S) (S & (-S))
using namespace std;
typedef tuple<int,int,int> trinca;
const int MAXN = 5*1e5 + 10;
const int MAXV = 1e6 + 10;
deque<int> aparicoes[MAXV];
int bit[MAXV],vetor[MAXN],resposta[MAXN],N,Q;
deque<trinca> perguntas;
void update(int idx,int delta){
while(idx < MAXN){
bit[idx] += delta;
idx += LSOne(idx);
}
}
int read(int idx){
int ans = 0;
while(idx > 0){
ans += bit[idx];
idx -= LSOne(idx);
}
return ans;
}
int main(){
scanf("%d %d",&N,&Q);
for(int i = 1;i<=N;i++){
scanf("%d",&vetor[i]);
int x = vetor[i];
aparicoes[x].push_back(i);
if(aparicoes[x].size() == 2) update(i,1);
else if(aparicoes[x].size() == 3) update(i,-1);
}
for(int i = 1;i<=Q;i++){
int a,b;
scanf("%d %d",&a,&b);
perguntas.push_back(make_tuple(a,b,i));
}
sort(perguntas.begin(),perguntas.end());
for(int i = 1;i<=N;i++){
while(!perguntas.empty() && get<0>(perguntas.front()) == i){
resposta[get<2>(perguntas.front())] = read(get<1>(perguntas.front()));
perguntas.pop_front();
}
int x = vetor[i];
aparicoes[x].pop_front();
if(aparicoes[x].size() >= 1) update(aparicoes[x][0],-1);
if(aparicoes[x].size() >= 2) update(aparicoes[x][1],2);
if(aparicoes[x].size() >= 3) update(aparicoes[x][2],-1);
}
for(int i = 1;i<=Q;i++) printf("%d\n",resposta[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
