# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
259286 | 2020-08-07T13:46:19 Z | 문홍윤(#5063) | 역사적 조사 (JOI14_historical) | C++17 | 3702 ms | 6520 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]; 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]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 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 | 0 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 | 0 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 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 | 0 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 | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 384 KB | Output is correct |
20 | Correct | 10 ms | 512 KB | Output is correct |
21 | Correct | 20 ms | 512 KB | Output is correct |
22 | Correct | 20 ms | 640 KB | Output is correct |
23 | Correct | 19 ms | 512 KB | Output is correct |
24 | Correct | 18 ms | 512 KB | Output is correct |
25 | Correct | 20 ms | 632 KB | Output is correct |
26 | Correct | 20 ms | 640 KB | Output is correct |
27 | Correct | 20 ms | 640 KB | Output is correct |
28 | Correct | 20 ms | 640 KB | Output is correct |
29 | Correct | 19 ms | 640 KB | Output is correct |
30 | Correct | 19 ms | 640 KB | Output is correct |
31 | Correct | 19 ms | 640 KB | Output is correct |
32 | Correct | 19 ms | 640 KB | Output is correct |
33 | Correct | 20 ms | 632 KB | Output is correct |
34 | Correct | 21 ms | 640 KB | Output is correct |
35 | Correct | 19 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 512 KB | Output is correct |
9 | Correct | 12 ms | 768 KB | Output is correct |
10 | Correct | 14 ms | 768 KB | Output is correct |
11 | Correct | 71 ms | 4088 KB | Output is correct |
12 | Correct | 34 ms | 1152 KB | Output is correct |
13 | Correct | 53 ms | 2040 KB | Output is correct |
14 | Correct | 74 ms | 4088 KB | Output is correct |
15 | Correct | 96 ms | 6264 KB | Output is correct |
16 | Correct | 67 ms | 5368 KB | Output is correct |
17 | Correct | 37 ms | 2172 KB | Output is correct |
18 | Correct | 60 ms | 3872 KB | Output is correct |
19 | Correct | 58 ms | 6520 KB | Output is correct |
20 | Correct | 37 ms | 4216 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 | 0 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 | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 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 | 0 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 384 KB | Output is correct |
20 | Correct | 10 ms | 512 KB | Output is correct |
21 | Correct | 20 ms | 512 KB | Output is correct |
22 | Correct | 20 ms | 640 KB | Output is correct |
23 | Correct | 19 ms | 512 KB | Output is correct |
24 | Correct | 18 ms | 512 KB | Output is correct |
25 | Correct | 20 ms | 632 KB | Output is correct |
26 | Correct | 20 ms | 640 KB | Output is correct |
27 | Correct | 20 ms | 640 KB | Output is correct |
28 | Correct | 20 ms | 640 KB | Output is correct |
29 | Correct | 19 ms | 640 KB | Output is correct |
30 | Correct | 19 ms | 640 KB | Output is correct |
31 | Correct | 19 ms | 640 KB | Output is correct |
32 | Correct | 19 ms | 640 KB | Output is correct |
33 | Correct | 20 ms | 632 KB | Output is correct |
34 | Correct | 21 ms | 640 KB | Output is correct |
35 | Correct | 19 ms | 640 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 | 384 KB | Output is correct |
41 | Correct | 1 ms | 384 KB | Output is correct |
42 | Correct | 3 ms | 384 KB | Output is correct |
43 | Correct | 5 ms | 512 KB | Output is correct |
44 | Correct | 12 ms | 768 KB | Output is correct |
45 | Correct | 14 ms | 768 KB | Output is correct |
46 | Correct | 71 ms | 4088 KB | Output is correct |
47 | Correct | 34 ms | 1152 KB | Output is correct |
48 | Correct | 53 ms | 2040 KB | Output is correct |
49 | Correct | 74 ms | 4088 KB | Output is correct |
50 | Correct | 96 ms | 6264 KB | Output is correct |
51 | Correct | 67 ms | 5368 KB | Output is correct |
52 | Correct | 37 ms | 2172 KB | Output is correct |
53 | Correct | 60 ms | 3872 KB | Output is correct |
54 | Correct | 58 ms | 6520 KB | Output is correct |
55 | Correct | 37 ms | 4216 KB | Output is correct |
56 | Correct | 56 ms | 768 KB | Output is correct |
57 | Correct | 167 ms | 1292 KB | Output is correct |
58 | Correct | 316 ms | 1912 KB | Output is correct |
59 | Correct | 518 ms | 2520 KB | Output is correct |
60 | Correct | 744 ms | 2956 KB | Output is correct |
61 | Correct | 920 ms | 3320 KB | Output is correct |
62 | Correct | 1206 ms | 3704 KB | Output is correct |
63 | Correct | 1694 ms | 4496 KB | Output is correct |
64 | Correct | 3084 ms | 4856 KB | Output is correct |
65 | Correct | 3702 ms | 4984 KB | Output is correct |
66 | Correct | 2601 ms | 4976 KB | Output is correct |
67 | Correct | 2093 ms | 4988 KB | Output is correct |
68 | Correct | 2185 ms | 5140 KB | Output is correct |
69 | Correct | 2160 ms | 5788 KB | Output is correct |
70 | Correct | 2237 ms | 6392 KB | Output is correct |
71 | Correct | 2297 ms | 6008 KB | Output is correct |
72 | Correct | 2218 ms | 5944 KB | Output is correct |
73 | Correct | 2233 ms | 5880 KB | Output is correct |
74 | Correct | 2249 ms | 5752 KB | Output is correct |
75 | Correct | 2264 ms | 5752 KB | Output is correct |
76 | Correct | 2222 ms | 5752 KB | Output is correct |
77 | Correct | 2185 ms | 5624 KB | Output is correct |
78 | Correct | 2165 ms | 5704 KB | Output is correct |
79 | Correct | 2159 ms | 5752 KB | Output is correct |
80 | Correct | 3574 ms | 5368 KB | Output is correct |