Submission #259257

# Submission time Handle Problem Language Result Execution time Memory
259257 2020-08-07T13:16:25 Z 문홍윤(#5063) 역사적 조사 (JOI14_historical) C++17
0 / 100
27 ms 2200 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++){
        scanf("%d", &arr[i]);
        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);
                  ~^~~~~~~~~~~
historic.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -