# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259255 | admin | 역사적 조사 (JOI14_historical) | C++14 | 4090 ms | 101508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
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(){
scanf("%d %d", &n, &q);
int sq=800;
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++)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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |