Submission #259652

# Submission time Handle Problem Language Result Execution time Memory
259652 2020-08-08T06:38:33 Z 임성재(#5054) 역사적 조사 (JOI14_historical) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>  
using namespace std;  
  
#define fast ios::sync_with_stdio(false);cin.tie(NULL)  
#define fi first  
#define se second  
#define all(v) (v).begin(),(v).end()  
#define pb push_back  
#define eb emplace_back
#define em emplace
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair
  
typedef long long ll;  
typedef pair<int,int> pii;  
typedef pair<ll,ll> pll;  
const ll INF = 1e18;
const int inf = 1e9;
const ll sz = 317;

ll n, q;
ll x[100010];
ll cnt[100010];
ll ans[100010];
vector<ll> v;
vector<pair<pll, ll>> qr;
priority_queue<ll> pQ, rQ;

void cl() {
	while(pQ.size() && rQ.size() && pQ.top() == rQ.top()) pQ.pop(), rQ.pop();
}

void add(int k) {
	rQ.em(cnt[k] * v[k]);
	cl();
	cnt[k]++;
	pQ.em(cnt[k] * v[k]);
}

void erase(int k) {
	rQ.em(cnt[k] * v[k]);
	cl();
	cnt[k]--;
	pQ.em(cnt[k] * v[k]);
}

ll cal() {
	cl();
	return pQ.top().fi;
}

int main() {
	fast;

	cin >> n >> q;

	for(int i=0; i<n; i++) {
		cin >> x[i];
		v.eb(x[i]);
	}

	sort(all(v));
	v.erase(unique(all(v)), v.end());

	for(int i=0; i<n; i++) {
		x[i] = lower_bound(all(v), x[i]) - v.begin();
	}

	for(int i=1; i<=q; i++) {
		ll a, b;
		cin >> a >> b;
		a--, b--;

		qr.eb(mp(a, b), i);
	}

	sort(all(qr), [](pair<pll, ll> i, pair<pll, ll> j) {
		if(i.fi.fi / sz == j.fi.fi / sz) return i.fi.se < j.fi.se;
		return i.fi.fi < j.fi.fi;
	});

	int s = qr[0].fi.fi;
	int e = qr[0].fi.se;

	for(int i=s; i<=e; i++) {
		add(x[i]);
	}

	ans[qr[0].se] = cal();

	for(int i=1; i<q; i++) {
		while(s < qr[i].fi.fi) erase(x[s++]);
		while(s > qr[i].fi.fi) add(x[--s]);
		while(e < qr[i].fi.se) add(x[++e]);
		while(e > qr[i].fi.se) erase(x[e--]);

		ans[qr[i].se] = cal();
	}

	for(int i=1; i<=q; i++) {
		cout << ans[i] << "\n";
	}
}

Compilation message

historic.cpp: In function 'll cal()':
historic.cpp:5:12: error: request for member 'first' in 'pQ.std::priority_queue<long long int>::top()', which is of non-class type 'const value_type {aka const long long int}'
 #define fi first  
            ^
historic.cpp:49:18: note: in expansion of macro 'fi'
  return pQ.top().fi;
                  ^~