# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
259018 | 2020-08-07T04:20:53 Z | 반딧불(#5071) | 역사적 조사 (JOI14_historical) | C++17 | 4000 ms | 9704 KB |
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") using namespace std; typedef long long ll; int sqrtN; struct Query{ int l, r, idx; Query(){} Query(int l, int r, int idx): l(l), r(r), idx(idx){} bool operator<(const Query &tmp)const{ if(l/sqrtN != tmp.l/sqrtN) return l < tmp.l; return r < tmp.r; } }; int n, q, k; ll arr[100002]; vector<Query> vec; ll cnt[100002]; ll ans[100002]; vector<ll> v; multiset<ll> mst; void removeNum(ll x){ mst.erase(mst.find(cnt[x] * v[x])); cnt[x]--; mst.insert(cnt[x] * v[x]); } void addNum(ll x){ mst.erase(mst.find(cnt[x] * v[x])); cnt[x]++; mst.insert(cnt[x] * v[x]); } void renumber(){ for(int i=0; i<n; i++) v.push_back(arr[i]); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for(int i=0; i<n; i++) arr[i] = lower_bound(v.begin(), v.end(), arr[i]) - v.begin(); k = (int)v.size(); } int main(){ scanf("%d %d", &n, &q); sqrtN = ceil(sqrt(n)); for(int i=0; i<n; i++) scanf("%lld", &arr[i]); renumber(); for(int i=1; i<=q; i++){ int l, r; scanf("%d %d", &l, &r); l--, r--; vec.push_back(Query(l, r, i)); } sort(vec.begin(), vec.end()); for(int i=0; i<k; i++) mst.insert(0); int s = 0, e = -1; for(int i=0; i<q; i++){ Query tmp = vec[i]; int l = tmp.l, r = tmp.r, idx = tmp.idx; while(e < r) addNum(arr[++e]); while(s > l) addNum(arr[--s]); while(e > r) removeNum(arr[e--]); while(s < l) removeNum(arr[s++]); ans[idx] = *mst.rbegin(); } for(int i=1; i<=q; i++){ printf("%lld\n", ans[i]); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 18 ms | 512 KB | Output is correct |
5 | Correct | 48 ms | 512 KB | Output is correct |
6 | Correct | 81 ms | 760 KB | Output is correct |
7 | Correct | 92 ms | 640 KB | Output is correct |
8 | Correct | 64 ms | 676 KB | Output is correct |
9 | Correct | 75 ms | 672 KB | Output is correct |
10 | Correct | 119 ms | 640 KB | Output is correct |
11 | Correct | 116 ms | 640 KB | Output is correct |
12 | Correct | 113 ms | 684 KB | Output is correct |
13 | Correct | 116 ms | 760 KB | Output is correct |
14 | Correct | 112 ms | 640 KB | Output is correct |
15 | Correct | 112 ms | 760 KB | Output is correct |
16 | Correct | 70 ms | 640 KB | Output is correct |
17 | Correct | 32 ms | 640 KB | Output is correct |
18 | Correct | 112 ms | 640 KB | Output is correct |
19 | Correct | 117 ms | 640 KB | Output is correct |
20 | Correct | 115 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 17 ms | 768 KB | Output is correct |
9 | Correct | 35 ms | 1148 KB | Output is correct |
10 | Correct | 15 ms | 1404 KB | Output is correct |
11 | Correct | 104 ms | 4968 KB | Output is correct |
12 | Correct | 70 ms | 2288 KB | Output is correct |
13 | Correct | 95 ms | 2920 KB | Output is correct |
14 | Correct | 146 ms | 5612 KB | Output is correct |
15 | Correct | 178 ms | 7984 KB | Output is correct |
16 | Correct | 175 ms | 8812 KB | Output is correct |
17 | Correct | 64 ms | 3048 KB | Output is correct |
18 | Correct | 102 ms | 4840 KB | Output is correct |
19 | Correct | 144 ms | 9704 KB | Output is correct |
20 | Correct | 88 ms | 7916 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 207 ms | 952 KB | Output is correct |
2 | Correct | 833 ms | 1392 KB | Output is correct |
3 | Correct | 2062 ms | 1904 KB | Output is correct |
4 | Correct | 3708 ms | 2928 KB | Output is correct |
5 | Execution timed out | 4078 ms | 2920 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |