답안 #259279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259279 2020-08-07T13:42:09 Z 문홍윤(#5063) 역사적 조사 (JOI14_historical) C++17
0 / 100
4000 ms 384 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();
    for(base=1; base<=n; base<<=1);
    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 Execution timed out 4008 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4008 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4054 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4008 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -