Submission #259244

# Submission time Handle Problem Language Result Execution time Memory
259244 2020-08-07T13:02:20 Z 문홍윤(#5063) 역사적 조사 (JOI14_historical) C++17
0 / 100
11 ms 768 KB
#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)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;

int n, q;
vector<pair<pii, int> > cmp;
pii qu[100010];
int arr[100010], cha[100010];
vector<int> id;
LL ans[100010];
int cnt[100010];
multiset<LL> ms;

void ins(int num){
    num=arr[num];
    ms.erase(ms.find(cha[num]*cnt[num]));
    cnt[num]++;
    ms.insert(cha[num]*cnt[num]);
}
void er(int num){
    num=arr[num];
    ms.erase(ms.find(cha[num]*cnt[num]));
    cnt[num]--;
    ms.insert(cha[num]*cnt[num]);
}

int main(){
    scanf("%d %d", &n, &q);
    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++){
        scanf("%d %d", &qu[i].F, &qu[i].S);
        cmp.eb(mp(qu[i].F/sq, qu[i].S), i);
    }
    for(int i=1; i<=id.size(); i++)ms.insert(0);
    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]=*ms.rbegin();
    }
    for(int i=1; i<=q; i++)printf("%lld\n", ans[i]);
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:61:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=id.size(); i++)ms.insert(0);
                  ~^~~~~~~~~~~
historic.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
historic.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &qu[i].F, &qu[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 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 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Incorrect 11 ms 768 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -