# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259282 |
2020-08-07T13:44:32 Z |
문홍윤(#5063) |
역사적 조사 (JOI14_historical) |
C++17 |
|
3619 ms |
8432 KB |
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<pair<pii, int> > cmp;
pii qu[100010];
int n, q, arr[100010], cha[100010], cnt[100010];
vector<int> id;
LL ans[100010];
inline int readChar();
template<class T=int> inline T readInt();
template<class T> inline void writeInt(T x, char end=0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size=4096;
inline int getChar(){
static char buf[buf_size];
static int len=0, pos=0;
if(pos==len)pos=0, len=fread(buf, 1, buf_size, stdin);
if(pos==len)return -1;
return buf[pos++];
}
inline int readChar(){
int c=getChar();
while(c<=32)c=getChar();
return c;
}
template <class T>
inline T readInt(){
int s=1, c=readChar();
T x=0;
if(c=='-')s=-1, c=getChar();
while('0'<= c&&c<='9')x=x*10+c-'0', c=getChar();
return s==1?x:-x;
}
int base;
LL tree[400010];
void upd(int num, LL val){
num|=base; tree[num]=val;
while(num>>=1)tree[num]=max(tree[num<<1], tree[num<<1|1]);
}
inline void ins(int num){
num=arr[num];
cnt[num]++;
upd(num, (LL)cha[num]*cnt[num]);
}
inline void er(int num){
num=arr[num];
cnt[num]--;
upd(num, (LL)cha[num]*cnt[num]);
}
int main(){
n=readInt();
q=readInt();
//scanf("%d %d", &n, &q);
for(base=1; base<=n; base<<=1);
int sq=sqrt(n);
id.resize(n);
for(int i=1; i<=n; i++){
arr[i]=readInt();
//scanf("%d", &arr[i]);
id[i-1]=arr[i];
}
svec(id); press(id);
for(int i=1; i<=n; i++){
int tmp=lb(id, arr[i])-id.begin()+1;
cha[tmp]=arr[i];
arr[i]=tmp;
}
cmp.resize(q);
for(int i=1; i<=q; i++){
qu[i].F=readInt();
qu[i].S=readInt();
//scanf("%d %d", &qu[i].F, &qu[i].S);
cmp[i-1]=mp(mp(qu[i].F/sq, qu[i].S), i);
}
svec(cmp);
int l=1, r=0;
for(auto i:cmp){
while(qu[i.S].F<l)ins(--l);
while(qu[i.S].S>r)ins(++r);
while(qu[i.S].F>l)er(l++);
while(qu[i.S].S<r)er(r--);
ans[i.S]=tree[1];
}
for(int i=1; i<=q; i++)printf("%lld\n", ans[i]);
}
# |
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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 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 |
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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
8 ms |
512 KB |
Output is correct |
21 |
Correct |
20 ms |
640 KB |
Output is correct |
22 |
Correct |
19 ms |
632 KB |
Output is correct |
23 |
Correct |
17 ms |
512 KB |
Output is correct |
24 |
Correct |
26 ms |
512 KB |
Output is correct |
25 |
Correct |
18 ms |
640 KB |
Output is correct |
26 |
Correct |
18 ms |
640 KB |
Output is correct |
27 |
Correct |
17 ms |
640 KB |
Output is correct |
28 |
Correct |
18 ms |
640 KB |
Output is correct |
29 |
Correct |
18 ms |
632 KB |
Output is correct |
30 |
Correct |
18 ms |
640 KB |
Output is correct |
31 |
Correct |
17 ms |
640 KB |
Output is correct |
32 |
Correct |
17 ms |
640 KB |
Output is correct |
33 |
Correct |
19 ms |
640 KB |
Output is correct |
34 |
Correct |
21 ms |
640 KB |
Output is correct |
35 |
Correct |
19 ms |
768 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 |
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 |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
10 ms |
896 KB |
Output is correct |
10 |
Correct |
9 ms |
768 KB |
Output is correct |
11 |
Correct |
45 ms |
4008 KB |
Output is correct |
12 |
Correct |
25 ms |
1152 KB |
Output is correct |
13 |
Correct |
35 ms |
2040 KB |
Output is correct |
14 |
Correct |
49 ms |
4088 KB |
Output is correct |
15 |
Correct |
64 ms |
6180 KB |
Output is correct |
16 |
Correct |
44 ms |
5368 KB |
Output is correct |
17 |
Correct |
28 ms |
2176 KB |
Output is correct |
18 |
Correct |
36 ms |
3960 KB |
Output is correct |
19 |
Correct |
37 ms |
6520 KB |
Output is correct |
20 |
Correct |
22 ms |
4344 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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
8 ms |
512 KB |
Output is correct |
21 |
Correct |
20 ms |
640 KB |
Output is correct |
22 |
Correct |
19 ms |
632 KB |
Output is correct |
23 |
Correct |
17 ms |
512 KB |
Output is correct |
24 |
Correct |
26 ms |
512 KB |
Output is correct |
25 |
Correct |
18 ms |
640 KB |
Output is correct |
26 |
Correct |
18 ms |
640 KB |
Output is correct |
27 |
Correct |
17 ms |
640 KB |
Output is correct |
28 |
Correct |
18 ms |
640 KB |
Output is correct |
29 |
Correct |
18 ms |
632 KB |
Output is correct |
30 |
Correct |
18 ms |
640 KB |
Output is correct |
31 |
Correct |
17 ms |
640 KB |
Output is correct |
32 |
Correct |
17 ms |
640 KB |
Output is correct |
33 |
Correct |
19 ms |
640 KB |
Output is correct |
34 |
Correct |
21 ms |
640 KB |
Output is correct |
35 |
Correct |
19 ms |
768 KB |
Output is correct |
36 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
4 ms |
512 KB |
Output is correct |
44 |
Correct |
10 ms |
896 KB |
Output is correct |
45 |
Correct |
9 ms |
768 KB |
Output is correct |
46 |
Correct |
45 ms |
4008 KB |
Output is correct |
47 |
Correct |
25 ms |
1152 KB |
Output is correct |
48 |
Correct |
35 ms |
2040 KB |
Output is correct |
49 |
Correct |
49 ms |
4088 KB |
Output is correct |
50 |
Correct |
64 ms |
6180 KB |
Output is correct |
51 |
Correct |
44 ms |
5368 KB |
Output is correct |
52 |
Correct |
28 ms |
2176 KB |
Output is correct |
53 |
Correct |
36 ms |
3960 KB |
Output is correct |
54 |
Correct |
37 ms |
6520 KB |
Output is correct |
55 |
Correct |
22 ms |
4344 KB |
Output is correct |
56 |
Correct |
51 ms |
768 KB |
Output is correct |
57 |
Correct |
172 ms |
1400 KB |
Output is correct |
58 |
Correct |
286 ms |
1784 KB |
Output is correct |
59 |
Correct |
503 ms |
2532 KB |
Output is correct |
60 |
Correct |
683 ms |
2960 KB |
Output is correct |
61 |
Correct |
892 ms |
3448 KB |
Output is correct |
62 |
Correct |
1136 ms |
3704 KB |
Output is correct |
63 |
Correct |
1692 ms |
4344 KB |
Output is correct |
64 |
Correct |
2881 ms |
4764 KB |
Output is correct |
65 |
Correct |
3619 ms |
4980 KB |
Output is correct |
66 |
Correct |
2648 ms |
4976 KB |
Output is correct |
67 |
Correct |
2220 ms |
4992 KB |
Output is correct |
68 |
Correct |
2169 ms |
5140 KB |
Output is correct |
69 |
Correct |
2156 ms |
7928 KB |
Output is correct |
70 |
Correct |
2327 ms |
8432 KB |
Output is correct |
71 |
Correct |
2269 ms |
8132 KB |
Output is correct |
72 |
Correct |
2211 ms |
8036 KB |
Output is correct |
73 |
Correct |
2202 ms |
8056 KB |
Output is correct |
74 |
Correct |
2203 ms |
7932 KB |
Output is correct |
75 |
Correct |
2187 ms |
7920 KB |
Output is correct |
76 |
Correct |
2377 ms |
7876 KB |
Output is correct |
77 |
Correct |
2488 ms |
7860 KB |
Output is correct |
78 |
Correct |
2124 ms |
7824 KB |
Output is correct |
79 |
Correct |
2227 ms |
7784 KB |
Output is correct |
80 |
Correct |
3469 ms |
7544 KB |
Output is correct |