# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
36589 | IvanC | 역사적 조사 (JOI14_historical) | C++14 | 1879 ms | 133784 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int BUCKET = 327;
vector<int> ida,volta;
int freq[BUCKET][MAXN],tempfreq[MAXN],versao[MAXN],divisao[MAXN],vetor[MAXN],iteracao,N,Q;
ll precalc[BUCKET][BUCKET];
void build(int id){
for(int i = 0;i<min((id+1)*BUCKET,N);i++){
int j = vetor[i];
freq[id][j]++;
}
memset(tempfreq,0,sizeof(tempfreq));
ll best = 0;
for(int i = id*BUCKET;i<N;i++){
int j = vetor[i];
tempfreq[j]++;
best = max(best, 1LL*tempfreq[j]*volta[j] );
precalc[id][divisao[i]] = best;
}
}
int main(){
scanf("%d %d",&N,&Q);
for(int i = 0;i<N;i++){
scanf("%d",&vetor[i]);
divisao[i] = i/BUCKET;
ida.push_back(vetor[i]);
}
sort(ida.begin(),ida.end());
ida.erase(unique(ida.begin(),ida.end()),ida.end());
for(int i = 0;i<ida.size();i++) volta.push_back(ida[i]);
for(int i = 0;i<N;i++){
vetor[i] = lower_bound(ida.begin(),ida.end(),vetor[i]) - ida.begin();
}
int tot_baldes = (N-1)/BUCKET;
for(int i = 0;i<=tot_baldes;i++){
build(i);
}
for(int q = 1;q<=Q;q++){
int l,r;
scanf("%d %d",&l,&r);
l--;r--;
ll resp = 0;
iteracao++;
int l_bucket = divisao[l];
int r_bucket = divisao[r];
if(l_bucket == r_bucket){
for(int i = l;i<=r;i++){
int j = vetor[i];
if(versao[j] != iteracao){
versao[j] = iteracao;
tempfreq[j] = 0;
}
tempfreq[j]++;
resp = max(resp, 1LL*tempfreq[j]*volta[j] );
}
}
else{
resp = precalc[l_bucket+1][r_bucket-1];
for(int i = l;i < (l_bucket+1)*BUCKET;i++){
int j = vetor[i];
if(versao[j] != iteracao){
versao[j] = iteracao;
tempfreq[j] = freq[r_bucket-1][j] - freq[l_bucket][j];
}
tempfreq[j]++;
resp = max(resp, 1LL*tempfreq[j]*volta[j] );
}
for(int i = r_bucket*BUCKET;i<=r;i++){
int j = vetor[i];
if(versao[j] != iteracao){
versao[j] = iteracao;
tempfreq[j] = freq[r_bucket-1][j] - freq[l_bucket][j];
}
tempfreq[j]++;
resp = max(resp, 1LL*tempfreq[j]*volta[j] );
}
}
printf("%lld\n",resp);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |