# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
164836 | 2019-11-23T16:49:28 Z | ly20 | 역사적 조사 (JOI14_historical) | C++17 | 20 ms | 764 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 112345; const int sz = sqrt(MAXN) + 10; int v[MAXN]; long long marc[MAXN]; long long mrk[sz][MAXN]; int sq[MAXN]; map <int, int> mp; set <int> s; set <int> :: iterator it; int ini[sz], fim[sz]; long long rs[sz][sz]; long long imp[MAXN]; int main() { int n, q; scanf("%d %d", &n, &q); int par = (n - 1) / sz + 1; for(int i = 0; i < n; i++) { scanf("%d", &v[i]); s.insert(v[i]); } int temp = 0; for(it = s.begin(); it != s.end(); it++) { mp[*it] = temp; imp[temp] = *it; temp++; } for(int i = 0; i < n; i++) { v[i] = mp[v[i]]; sq[i] = i / sz; } for(int i = 0; i < par; i++) { ini[i] = i * sz; fim[i] = min(n - 1, i * (sz + 1) - 1); } long long resp; for(int i = 0; i < par; i++) { resp = 0; for(int j = ini[i]; j < n; j++) { mrk[i][v[j]]++; if(mrk[i][v[j]] * imp[v[j]] > resp) { resp = mrk[i][v[j]] * imp[v[j]]; } if(j == fim[sq[j]]) { rs[i][sq[j]] = resp; } } } for(int i = 0; i < q; i++) { int a, b; scanf("%d %d", &a, &b); a--; b--; if(sq[a] == sq[b]) { long long resp = 0; for(int j = a; j <= b; j++) { marc[v[j]]++; resp = max(resp, marc[v[j]] * imp[v[j]]); } printf("%lld\n", resp); for(int j = a; j <= b; j++) marc[v[j]]--; } else { long long resp = rs[sq[a] + 1][sq[b] - 1]; for(int j = a; j <= fim[sq[a]]; j++) { marc[v[j]]++; if((marc[v[j]] + mrk[sq[a] + 1][v[j]] - mrk[sq[b]][v[j]]) * imp[v[j]] > resp) { resp = (marc[v[j]] + mrk[sq[a] + 1][v[j]] - mrk[sq[b]][v[j]]) * imp[v[j]]; } } for(int j = b; j >= ini[sq[b]];j--) { marc[v[j]]++; if((marc[v[j]] + mrk[sq[a] + 1][v[j]] - mrk[sq[b]][v[j]]) * imp[v[j]] > resp) { resp = (marc[v[j]] + mrk[sq[a] + 1][v[j]] - mrk[sq[b]][v[j]]) * imp[v[j]]; } } printf("%lld\n", resp); for(int j = a; j <= fim[sq[a]]; j++) { marc[v[j]]--; } for(int j = b; j >= ini[sq[b]];j--) { marc[v[j]]--; } } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Correct | 2 ms | 380 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 348 KB | Output is correct |
13 | Correct | 9 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 0 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Incorrect | 2 ms | 376 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 764 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |