| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 20584 | kdh9949 | 역사적 조사 (JOI14_historical) | C++14 | 2966 ms | 6804 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 131072, b = 320;
int n, q, a[100010], xx[100010];
ll ans[100010];
struct Query{
int s, e, idx;
bool operator<(const Query &oth) const {
return (s / b == oth.s / b) ? e < oth.e : s < oth.s;
}
} qa[100010];
struct Seg{
ll dat[2 * sz];
void init(){
for(int i = 1; i < 2 * sz; i++) dat[i] = 0;
}
void upd(int x, int v){
x += sz - 1; dat[x] += v * xx[x - sz + 1];
for(x /= 2; x; x /= 2) dat[x] = max(dat[2 * x], dat[2 * x + 1]);
}
ll get(){ return dat[1]; }
} S;
int main(){
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; i++){ scanf("%d", a + i); xx[i] = a[i]; }
sort(xx + 1, xx + n + 1);
for(int i = 1; i <= n; i++) a[i] = (int)(lower_bound(xx + 1, xx + n + 1, a[i]) - xx);
for(int i = 1; i <= q; i++){ scanf("%d%d", &qa[i].s, &qa[i].e); qa[i].idx = i; }
sort(qa + 1, qa + q + 1);
qa[0].s = 1; qa[0].e = 0;
S.init();
for(int i = 1; i <= q; i++){
int ls = qa[i - 1].s, le = qa[i - 1].e;
int cs = qa[i].s, ce = qa[i].e;
for(; ls < cs; ) S.upd(a[ls++], -1);
for(; ls > cs; ) S.upd(a[--ls], 1);
for(; le < ce; ) S.upd(a[++le], 1);
for(; le > ce; ) S.upd(a[le--], -1);
ans[qa[i].idx] = S.get();
}
for(int i = 1; i <= q; 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... | ||||
