| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 42321 | minkank | 역사적 조사 (JOI14_historical) | C++14 | 249 ms | 66044 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
#define st first
#define nd second
typedef pair<int, int> ii;
ii qu[N];
int n, m, a[N], Time, b[N];
long long ans[N];
vector<int> Q[N];
map<int, int> sax;
int cnt[N], cnt2[N];
bool cmp(int a, int b) { return qu[a].nd < qu[b].nd; }
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
if(!sax[a[i]]) sax[a[i]] = ++Time;
b[i] = sax[a[i]];
}
for(int i = 1; i <= m; ++i)
cin >> qu[i].st >> qu[i].nd, Q[(long long)(qu[i].st / sqrt(n))].push_back(i);
for(int i = 0; i <= sqrt(n); ++i) {
sort(Q[i].begin(), Q[i].end(), cmp);
int maxL = 0;
for(int j = 0; j < Q[i].size(); ++j) maxL = max(maxL, qu[Q[i][j]].st);
int cur = maxL;
long long curmx = 0;
memset(cnt, 0, sizeof cnt);
for(int j = 0; j < Q[i].size(); ++j) {
int id = Q[i][j], L = qu[id].st, R = qu[id].nd;
while(cur <= R) {
int x = a[cur];
cnt[b[cur]]++; curmx = max(curmx, 1LL * cnt[b[cur]] * x);
cur++;
}
ans[id] = curmx;
for(int k = L; k < min(maxL, R + 1); ++k) {
int x = a[k];
cnt2[b[k]]++; ans[id] = max(ans[id], 1LL * (cnt2[b[k]] + cnt[b[k]]) * x);
}
for(int k = L; k < min(maxL, R + 1); ++k) {
int x = a[k];
cnt2[b[k]]--;
}
}
}
for(int i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
}컴파일 시 표준 에러 (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... | ||||
