답안 #259275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259275 2020-08-07T13:32:32 Z 문홍윤(#5063) 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 7676 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;
}

LL tree[400010];
void upd(int point, int s, int e, int num, LL val){
    if(s==e){
        tree[point]=val;
        return;
    }
    if(num<=(s+e)/2)upd(point*2, s, (s+e)/2, num, val);
    else upd(point*2+1, (s+e)/2+1, e, num, val);
    tree[point]=max(tree[point*2], tree[point*2+1]);
}

inline void ins(int num){
    num=arr[num];
    cnt[num]++;
    upd(1, 1, n, num, (LL)cha[num]*cnt[num]);
}
inline void er(int num){
    num=arr[num];
    cnt[num]--;
    upd(1, 1, n, num, (LL)cha[num]*cnt[num]);
}

int main(){
    n=readInt();
    q=readInt();
    int sq=sqrt(n);
    id.resize(n);
    for(int i=1; i<=n; i++){
        arr[i]=readInt();
        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();
        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]);
}
# 결과 실행 시간 메모리 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 0 ms 384 KB Output is correct
6 Correct 0 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 0 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 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 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 1 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 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 0 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 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 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 7 ms 512 KB Output is correct
20 Correct 17 ms 512 KB Output is correct
21 Correct 34 ms 640 KB Output is correct
22 Correct 35 ms 640 KB Output is correct
23 Correct 31 ms 640 KB Output is correct
24 Correct 30 ms 640 KB Output is correct
25 Correct 43 ms 760 KB Output is correct
26 Correct 40 ms 760 KB Output is correct
27 Correct 40 ms 760 KB Output is correct
28 Correct 40 ms 760 KB Output is correct
29 Correct 40 ms 764 KB Output is correct
30 Correct 39 ms 760 KB Output is correct
31 Correct 31 ms 640 KB Output is correct
32 Correct 27 ms 640 KB Output is correct
33 Correct 39 ms 760 KB Output is correct
34 Correct 44 ms 748 KB Output is correct
35 Correct 47 ms 756 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 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 12 ms 1024 KB Output is correct
10 Correct 10 ms 1152 KB Output is correct
11 Correct 48 ms 4728 KB Output is correct
12 Correct 46 ms 1792 KB Output is correct
13 Correct 53 ms 2808 KB Output is correct
14 Correct 67 ms 4860 KB Output is correct
15 Correct 86 ms 7160 KB Output is correct
16 Correct 62 ms 6520 KB Output is correct
17 Correct 28 ms 2808 KB Output is correct
18 Correct 42 ms 4472 KB Output is correct
19 Correct 46 ms 7676 KB Output is correct
20 Correct 27 ms 5368 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 0 ms 384 KB Output is correct
6 Correct 0 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 0 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 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 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 7 ms 512 KB Output is correct
20 Correct 17 ms 512 KB Output is correct
21 Correct 34 ms 640 KB Output is correct
22 Correct 35 ms 640 KB Output is correct
23 Correct 31 ms 640 KB Output is correct
24 Correct 30 ms 640 KB Output is correct
25 Correct 43 ms 760 KB Output is correct
26 Correct 40 ms 760 KB Output is correct
27 Correct 40 ms 760 KB Output is correct
28 Correct 40 ms 760 KB Output is correct
29 Correct 40 ms 764 KB Output is correct
30 Correct 39 ms 760 KB Output is correct
31 Correct 31 ms 640 KB Output is correct
32 Correct 27 ms 640 KB Output is correct
33 Correct 39 ms 760 KB Output is correct
34 Correct 44 ms 748 KB Output is correct
35 Correct 47 ms 756 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 1 ms 384 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 6 ms 640 KB Output is correct
44 Correct 12 ms 1024 KB Output is correct
45 Correct 10 ms 1152 KB Output is correct
46 Correct 48 ms 4728 KB Output is correct
47 Correct 46 ms 1792 KB Output is correct
48 Correct 53 ms 2808 KB Output is correct
49 Correct 67 ms 4860 KB Output is correct
50 Correct 86 ms 7160 KB Output is correct
51 Correct 62 ms 6520 KB Output is correct
52 Correct 28 ms 2808 KB Output is correct
53 Correct 42 ms 4472 KB Output is correct
54 Correct 46 ms 7676 KB Output is correct
55 Correct 27 ms 5368 KB Output is correct
56 Correct 97 ms 896 KB Output is correct
57 Correct 338 ms 1644 KB Output is correct
58 Correct 732 ms 2424 KB Output is correct
59 Correct 1233 ms 3340 KB Output is correct
60 Correct 1725 ms 3500 KB Output is correct
61 Correct 2160 ms 3512 KB Output is correct
62 Correct 2322 ms 5120 KB Output is correct
63 Correct 2449 ms 5976 KB Output is correct
64 Correct 2702 ms 6676 KB Output is correct
65 Correct 2705 ms 6720 KB Output is correct
66 Correct 3542 ms 6812 KB Output is correct
67 Execution timed out 4035 ms 6904 KB Time limit exceeded
68 Halted 0 ms 0 KB -