# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259593 |
2020-08-08T03:33:03 Z |
임성재(#5054) |
역사적 조사 (JOI14_historical) |
C++17 |
|
4000 ms |
74904 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define eb emplace_back
#define em emplace
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int inf = 1e9;
const ll sz = 317;
ll n, q;
ll x[100010];
ll cnt[100010];
ll ans[100010];
vector<ll> v;
vector<pair<pll, ll>> qr;
ll tree[400010];
priority_queue<pll> pQ;
void update(int node, int s, int e, int i, ll x) {
if(s == e) {
tree[node] = x;
return;
}
int m = s + e >> 1;
if(i <= m) update(node*2, s, m, i, x);
else update(node*2+1, m+1, e, i, x);
tree[node] = max(tree[node*2], tree[node*2+1]);
}
void add(int k) {
cnt[k]++;
pQ.em(cnt[k] * v[k], k);
}
void erase(int k) {
cnt[k]--;
}
ll cal() {
while(cnt[pQ.top().se] * v[pQ.top().se] != pQ.top().fi) pQ.pop();
return pQ.top().fi;
}
int main() {
fast;
cin >> n >> q;
for(int i=0; i<n; i++) {
cin >> x[i];
v.eb(x[i]);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
for(int i=0; i<n; i++) {
x[i] = lower_bound(all(v), x[i]) - v.begin();
}
for(int i=1; i<=q; i++) {
ll a, b;
cin >> a >> b;
a--, b--;
qr.eb(mp(a, b), i);
}
sort(all(qr), [](pair<pll, ll> i, pair<pll, ll> j) {
if(i.fi.fi / sz == j.fi.fi / sz) return i.fi.se < j.fi.se;
return i.fi.fi < j.fi.fi;
});
int s = qr[0].fi.fi;
int e = qr[0].fi.se;
for(int i=s; i<=e; i++) {
add(x[i]);
}
ans[qr[0].se] = cal();
for(int i=1; i<q; i++) {
while(s < qr[i].fi.fi) erase(x[s++]);
while(s > qr[i].fi.fi) add(x[--s]);
while(e < qr[i].fi.se) add(x[++e]);
while(e > qr[i].fi.se) erase(x[e--]);
ans[qr[i].se] = cal();
}
for(int i=1; i<=q; i++) {
cout << ans[i] << "\n";
}
}
Compilation message
historic.cpp: In function 'void update(int, int, int, int, ll)':
historic.cpp:36:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s + e >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
640 KB |
Output is correct |
18 |
Correct |
6 ms |
1020 KB |
Output is correct |
19 |
Correct |
12 ms |
1124 KB |
Output is correct |
20 |
Correct |
29 ms |
1852 KB |
Output is correct |
21 |
Correct |
50 ms |
1768 KB |
Output is correct |
22 |
Correct |
47 ms |
1768 KB |
Output is correct |
23 |
Correct |
48 ms |
1376 KB |
Output is correct |
24 |
Correct |
49 ms |
1768 KB |
Output is correct |
25 |
Correct |
40 ms |
2912 KB |
Output is correct |
26 |
Correct |
46 ms |
4952 KB |
Output is correct |
27 |
Correct |
44 ms |
2916 KB |
Output is correct |
28 |
Correct |
40 ms |
2916 KB |
Output is correct |
29 |
Correct |
44 ms |
2908 KB |
Output is correct |
30 |
Correct |
47 ms |
2908 KB |
Output is correct |
31 |
Correct |
49 ms |
1768 KB |
Output is correct |
32 |
Correct |
41 ms |
1304 KB |
Output is correct |
33 |
Correct |
46 ms |
2916 KB |
Output is correct |
34 |
Correct |
47 ms |
4936 KB |
Output is correct |
35 |
Correct |
36 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
6 ms |
1088 KB |
Output is correct |
9 |
Correct |
10 ms |
1412 KB |
Output is correct |
10 |
Correct |
15 ms |
1404 KB |
Output is correct |
11 |
Correct |
74 ms |
6252 KB |
Output is correct |
12 |
Correct |
38 ms |
3576 KB |
Output is correct |
13 |
Correct |
60 ms |
4720 KB |
Output is correct |
14 |
Correct |
79 ms |
6244 KB |
Output is correct |
15 |
Correct |
94 ms |
7272 KB |
Output is correct |
16 |
Correct |
68 ms |
7528 KB |
Output is correct |
17 |
Correct |
35 ms |
4872 KB |
Output is correct |
18 |
Correct |
61 ms |
8468 KB |
Output is correct |
19 |
Correct |
65 ms |
9700 KB |
Output is correct |
20 |
Correct |
39 ms |
5224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
640 KB |
Output is correct |
18 |
Correct |
6 ms |
1020 KB |
Output is correct |
19 |
Correct |
12 ms |
1124 KB |
Output is correct |
20 |
Correct |
29 ms |
1852 KB |
Output is correct |
21 |
Correct |
50 ms |
1768 KB |
Output is correct |
22 |
Correct |
47 ms |
1768 KB |
Output is correct |
23 |
Correct |
48 ms |
1376 KB |
Output is correct |
24 |
Correct |
49 ms |
1768 KB |
Output is correct |
25 |
Correct |
40 ms |
2912 KB |
Output is correct |
26 |
Correct |
46 ms |
4952 KB |
Output is correct |
27 |
Correct |
44 ms |
2916 KB |
Output is correct |
28 |
Correct |
40 ms |
2916 KB |
Output is correct |
29 |
Correct |
44 ms |
2908 KB |
Output is correct |
30 |
Correct |
47 ms |
2908 KB |
Output is correct |
31 |
Correct |
49 ms |
1768 KB |
Output is correct |
32 |
Correct |
41 ms |
1304 KB |
Output is correct |
33 |
Correct |
46 ms |
2916 KB |
Output is correct |
34 |
Correct |
47 ms |
4936 KB |
Output is correct |
35 |
Correct |
36 ms |
4952 KB |
Output is correct |
36 |
Correct |
0 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
768 KB |
Output is correct |
43 |
Correct |
6 ms |
1088 KB |
Output is correct |
44 |
Correct |
10 ms |
1412 KB |
Output is correct |
45 |
Correct |
15 ms |
1404 KB |
Output is correct |
46 |
Correct |
74 ms |
6252 KB |
Output is correct |
47 |
Correct |
38 ms |
3576 KB |
Output is correct |
48 |
Correct |
60 ms |
4720 KB |
Output is correct |
49 |
Correct |
79 ms |
6244 KB |
Output is correct |
50 |
Correct |
94 ms |
7272 KB |
Output is correct |
51 |
Correct |
68 ms |
7528 KB |
Output is correct |
52 |
Correct |
35 ms |
4872 KB |
Output is correct |
53 |
Correct |
61 ms |
8468 KB |
Output is correct |
54 |
Correct |
65 ms |
9700 KB |
Output is correct |
55 |
Correct |
39 ms |
5224 KB |
Output is correct |
56 |
Correct |
113 ms |
2104 KB |
Output is correct |
57 |
Correct |
305 ms |
5864 KB |
Output is correct |
58 |
Correct |
536 ms |
18828 KB |
Output is correct |
59 |
Correct |
931 ms |
36152 KB |
Output is correct |
60 |
Correct |
1091 ms |
69568 KB |
Output is correct |
61 |
Correct |
1563 ms |
37144 KB |
Output is correct |
62 |
Correct |
2031 ms |
14052 KB |
Output is correct |
63 |
Correct |
2275 ms |
10436 KB |
Output is correct |
64 |
Correct |
2515 ms |
9724 KB |
Output is correct |
65 |
Correct |
2430 ms |
10116 KB |
Output is correct |
66 |
Correct |
3015 ms |
13024 KB |
Output is correct |
67 |
Correct |
3843 ms |
17508 KB |
Output is correct |
68 |
Execution timed out |
4085 ms |
74904 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |