답안 #259259

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

priority_queue<LL> pq, del;
inline void dlt(LL a){del.push(a);}
inline void in(LL a){pq.push(a);}
inline LL tp(){
    while(!del.empty()){
        if(del.top()==pq.top()){
            del.pop(); pq.pop();
        }
        else break;
    }
    return pq.top();
}

inline void ins(int num){
    num=arr[num];
    dlt((LL)cha[num]*cnt[num]);
    cnt[num]++;
    in((LL)cha[num]*cnt[num]);
}
inline void er(int num){
    num=arr[num];
    dlt((LL)cha[num]*cnt[num]);
    cnt[num]--;
    in((LL)cha[num]*cnt[num]);
}

int main(){
    n=readInt();
    q=readInt();
    int sq=sqrt(n);
    for(int i=1; i<=n; i++){
        arr[i]=readInt();
        id.eb(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;
    }
    for(int i=1; i<=q; i++){
        qu[i].F=readInt();
        qu[i].S=readInt();
        cmp.eb(mp(qu[i].F/sq, qu[i].S), i);
    }
    for(int i=1; i<=id.size(); i++)in(0ll);
    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]=tp();
    }
    for(int i=1; i<=q; i++)printf("%lld\n", ans[i]);
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:95:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=id.size(); i++)in(0ll);
                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 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 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 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 0 ms 384 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 0 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 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 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 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 16 ms 1020 KB Output is correct
20 Correct 52 ms 1472 KB Output is correct
21 Correct 112 ms 1616 KB Output is correct
22 Correct 111 ms 2432 KB Output is correct
23 Correct 108 ms 1092 KB Output is correct
24 Correct 107 ms 1268 KB Output is correct
25 Correct 73 ms 4684 KB Output is correct
26 Correct 87 ms 4692 KB Output is correct
27 Correct 91 ms 3924 KB Output is correct
28 Correct 78 ms 4560 KB Output is correct
29 Correct 88 ms 4056 KB Output is correct
30 Correct 93 ms 3812 KB Output is correct
31 Correct 106 ms 1228 KB Output is correct
32 Correct 89 ms 896 KB Output is correct
33 Correct 90 ms 3812 KB Output is correct
34 Correct 112 ms 7108 KB Output is correct
35 Correct 64 ms 6992 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 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 1116 KB Output is correct
9 Correct 9 ms 1528 KB Output is correct
10 Correct 21 ms 896 KB Output is correct
11 Correct 75 ms 5608 KB Output is correct
12 Correct 52 ms 3820 KB Output is correct
13 Correct 60 ms 5608 KB Output is correct
14 Correct 71 ms 5736 KB Output is correct
15 Correct 101 ms 8292 KB Output is correct
16 Correct 44 ms 8036 KB Output is correct
17 Correct 29 ms 4536 KB Output is correct
18 Correct 37 ms 8200 KB Output is correct
19 Correct 44 ms 9520 KB Output is correct
20 Correct 25 ms 6256 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 0 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 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 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 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 16 ms 1020 KB Output is correct
20 Correct 52 ms 1472 KB Output is correct
21 Correct 112 ms 1616 KB Output is correct
22 Correct 111 ms 2432 KB Output is correct
23 Correct 108 ms 1092 KB Output is correct
24 Correct 107 ms 1268 KB Output is correct
25 Correct 73 ms 4684 KB Output is correct
26 Correct 87 ms 4692 KB Output is correct
27 Correct 91 ms 3924 KB Output is correct
28 Correct 78 ms 4560 KB Output is correct
29 Correct 88 ms 4056 KB Output is correct
30 Correct 93 ms 3812 KB Output is correct
31 Correct 106 ms 1228 KB Output is correct
32 Correct 89 ms 896 KB Output is correct
33 Correct 90 ms 3812 KB Output is correct
34 Correct 112 ms 7108 KB Output is correct
35 Correct 64 ms 6992 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 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 1116 KB Output is correct
44 Correct 9 ms 1528 KB Output is correct
45 Correct 21 ms 896 KB Output is correct
46 Correct 75 ms 5608 KB Output is correct
47 Correct 52 ms 3820 KB Output is correct
48 Correct 60 ms 5608 KB Output is correct
49 Correct 71 ms 5736 KB Output is correct
50 Correct 101 ms 8292 KB Output is correct
51 Correct 44 ms 8036 KB Output is correct
52 Correct 29 ms 4536 KB Output is correct
53 Correct 37 ms 8200 KB Output is correct
54 Correct 44 ms 9520 KB Output is correct
55 Correct 25 ms 6256 KB Output is correct
56 Correct 327 ms 1724 KB Output is correct
57 Correct 1071 ms 8280 KB Output is correct
58 Correct 1974 ms 51208 KB Output is correct
59 Correct 3248 ms 101308 KB Output is correct
60 Correct 3731 ms 120364 KB Output is correct
61 Execution timed out 4088 ms 52632 KB Time limit exceeded
62 Halted 0 ms 0 KB -