# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259316 |
2020-08-07T14:30:53 Z |
최은수(#5042) |
역사적 조사 (JOI14_historical) |
C++17 |
|
4000 ms |
105580 KB |
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
const int bk=420;
int cnt[100010];
vector<int>sv;
priority_queue<ll>pq,del;
inline void add(int x,int p)
{
del.ep((ll)sv[x]*cnt[x]);
cnt[x]+=p;
pq.ep((ll)sv[x]*cnt[x]);
return;
}
ll ans[100010];
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,q;
cin>>n>>q;
vector<int>v(n);
for(int&t:v)
cin>>t,sv.eb(t);
sort(all(sv));
sv.erase(unique(all(sv)),sv.end());
v.insert(v.begin(),v[0]);
for(int&t:v)
t=lower_bound(all(sv),t)-sv.begin();
vector<pair<pi,int> >qv;
for(int i=0;i<q;i++)
{
int s,e;
cin>>s>>e;
qv.eb(pi(s,e),i);
}
sort(all(qv),[](const pair<pi,int>&x,const pair<pi,int>&y)
{
return x.fi.fi/bk==y.fi.fi/bk?x.fi.se<y.fi.se:x.fi.fi<y.fi.fi;
});
int cl=qv[0].fi.fi;
int cr=qv[0].fi.fi-1;
for(int&t:sv)
pq.ep(0);
for(auto&t:qv)
{
int l=t.fi.fi;
int r=t.fi.se;
while(cl<l)
add(v[cl++],-1);
while(cl>l)
add(v[--cl],1);
while(cr<r)
add(v[++cr],1);
while(cr>r)
add(v[cr--],-1);
while(!del.empty()&&pq.top()==del.top())
pq.pop(),del.pop();
ans[t.se]=pq.top();
}
for(int i=0;i<q;i++)
cout<<ans[i]<<'\n';
cout.flush();
return 0;
}
Compilation message
historic.cpp: In function 'int32_t main()':
historic.cpp:55:13: warning: unused variable 't' [-Wunused-variable]
for(int&t:sv)
^
# |
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 |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 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 |
416 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 |
# |
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 |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 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 |
416 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 |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
640 KB |
Output is correct |
18 |
Correct |
18 ms |
1524 KB |
Output is correct |
19 |
Correct |
44 ms |
2128 KB |
Output is correct |
20 |
Correct |
114 ms |
2604 KB |
Output is correct |
21 |
Correct |
194 ms |
2648 KB |
Output is correct |
22 |
Correct |
181 ms |
3808 KB |
Output is correct |
23 |
Correct |
191 ms |
2396 KB |
Output is correct |
24 |
Correct |
191 ms |
2536 KB |
Output is correct |
25 |
Correct |
129 ms |
7084 KB |
Output is correct |
26 |
Correct |
150 ms |
7232 KB |
Output is correct |
27 |
Correct |
159 ms |
6868 KB |
Output is correct |
28 |
Correct |
166 ms |
6984 KB |
Output is correct |
29 |
Correct |
250 ms |
6864 KB |
Output is correct |
30 |
Correct |
159 ms |
6996 KB |
Output is correct |
31 |
Correct |
198 ms |
2512 KB |
Output is correct |
32 |
Correct |
182 ms |
2288 KB |
Output is correct |
33 |
Correct |
220 ms |
6860 KB |
Output is correct |
34 |
Correct |
192 ms |
7724 KB |
Output is correct |
35 |
Correct |
152 ms |
8516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 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 |
2 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 |
5 ms |
1148 KB |
Output is correct |
9 |
Correct |
11 ms |
1556 KB |
Output is correct |
10 |
Correct |
27 ms |
1152 KB |
Output is correct |
11 |
Correct |
95 ms |
4964 KB |
Output is correct |
12 |
Correct |
56 ms |
3816 KB |
Output is correct |
13 |
Correct |
73 ms |
5600 KB |
Output is correct |
14 |
Correct |
91 ms |
5224 KB |
Output is correct |
15 |
Correct |
102 ms |
7396 KB |
Output is correct |
16 |
Correct |
62 ms |
7264 KB |
Output is correct |
17 |
Correct |
34 ms |
4840 KB |
Output is correct |
18 |
Correct |
67 ms |
7652 KB |
Output is correct |
19 |
Correct |
62 ms |
8540 KB |
Output is correct |
20 |
Correct |
34 ms |
5996 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 |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 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 |
416 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 |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
640 KB |
Output is correct |
18 |
Correct |
18 ms |
1524 KB |
Output is correct |
19 |
Correct |
44 ms |
2128 KB |
Output is correct |
20 |
Correct |
114 ms |
2604 KB |
Output is correct |
21 |
Correct |
194 ms |
2648 KB |
Output is correct |
22 |
Correct |
181 ms |
3808 KB |
Output is correct |
23 |
Correct |
191 ms |
2396 KB |
Output is correct |
24 |
Correct |
191 ms |
2536 KB |
Output is correct |
25 |
Correct |
129 ms |
7084 KB |
Output is correct |
26 |
Correct |
150 ms |
7232 KB |
Output is correct |
27 |
Correct |
159 ms |
6868 KB |
Output is correct |
28 |
Correct |
166 ms |
6984 KB |
Output is correct |
29 |
Correct |
250 ms |
6864 KB |
Output is correct |
30 |
Correct |
159 ms |
6996 KB |
Output is correct |
31 |
Correct |
198 ms |
2512 KB |
Output is correct |
32 |
Correct |
182 ms |
2288 KB |
Output is correct |
33 |
Correct |
220 ms |
6860 KB |
Output is correct |
34 |
Correct |
192 ms |
7724 KB |
Output is correct |
35 |
Correct |
152 ms |
8516 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
2 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 |
5 ms |
1148 KB |
Output is correct |
44 |
Correct |
11 ms |
1556 KB |
Output is correct |
45 |
Correct |
27 ms |
1152 KB |
Output is correct |
46 |
Correct |
95 ms |
4964 KB |
Output is correct |
47 |
Correct |
56 ms |
3816 KB |
Output is correct |
48 |
Correct |
73 ms |
5600 KB |
Output is correct |
49 |
Correct |
91 ms |
5224 KB |
Output is correct |
50 |
Correct |
102 ms |
7396 KB |
Output is correct |
51 |
Correct |
62 ms |
7264 KB |
Output is correct |
52 |
Correct |
34 ms |
4840 KB |
Output is correct |
53 |
Correct |
67 ms |
7652 KB |
Output is correct |
54 |
Correct |
62 ms |
8540 KB |
Output is correct |
55 |
Correct |
34 ms |
5996 KB |
Output is correct |
56 |
Correct |
435 ms |
2924 KB |
Output is correct |
57 |
Correct |
1138 ms |
8748 KB |
Output is correct |
58 |
Correct |
1726 ms |
51000 KB |
Output is correct |
59 |
Correct |
3010 ms |
100984 KB |
Output is correct |
60 |
Correct |
3364 ms |
105580 KB |
Output is correct |
61 |
Execution timed out |
4062 ms |
52320 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |