답안 #255561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255561 2020-08-01T08:46:07 Z islingr Examination (JOI19_examination) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define lb(x...) lower_bound(x)
#define all(x) begin(x), end(x)

const int N = 1 << 17;
 
int n, m;
int t[4 * N];
int query(int l, int r) {
	int sum = 0;
	for (l += m, r += m; l < r; l >>= 1, r >>= 1) {
		if (l & 1) sum += t[l++];
		if (r & 1) sum += t[--r];
	}
	return sum;
}
void update(int p, int x) {
	for (t[p += m] += x; p >>= 1; ) t[p] = t[p << 1] + t[p << 1|1];
}

struct P {
	int x, y, z, i;
	bool operator<(const P &p) { return pair(-x, -y) < pair(-p.x, -p.y); }
} a[2 * N], tmp[2 * N];
int ans[N];

void cdq(int l, int r) {
	if (r - l == 1) return;
	int m = (l + r) / 2;
	cdq(l, m); cdq(m, r);
	vector<int> op;
	int i = l, j = m, k = l, cnt = 0;
	while (i < m && j < r)
		if (a[j].y < a[i].y) {
			if (!a[i].i) ++cnt, update(a[i].z, 1), op.eb(a[i].z);
			tmp[k++] = a[i++];
		} else {
			if (a[j].i) ans[a[j].i] += cnt - query(0, a[j].z);
			tmp[k++] = a[j++];
		}
	while (i < m) tmp[k++] = a[i++];
	while (j < r) {
		if (a[j].i) ans[a[j].i] += cnt - query(0, a[j].z);
		tmp[k++] = a[j++];
	}
	rep(i, l, r) a[i] = tmp[i];
	for (int p : op) update(p, -1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	vector<int> cmp;
	int q; cin >> n >> q;
	rep(i, 0, n) {
		int x, y; cin >> x >> y;
		a[i + q] = {x, y, x + y, 0};
		cmp.eb(x + y);
	}
	rep(i, 0, q) {
		int x, y, z; cin >> x >> y >> z; --x; --y;
		a[i] = {x, y, z, i + 1};
		cmp.eb(z);
	}
	sort(all(cmp)); cmp.resize(m = unique(all(cmp)) - begin(cmp));
	rep(i, 0, n + q) a[i].z = lb(all(cmp), a[i].z) - begin(cmp);
	sort(a, a + n + q); cdq(0, n + q);
	rep(i, 0, q) cout << ans[i + 1] << '\n';
}

Compilation message

examination.cpp: In member function 'bool P::operator<(const P&)':
examination.cpp:28:42: error: missing template arguments before '(' token
  bool operator<(const P &p) { return pair(-x, -y) < pair(-p.x, -p.y); }
                                          ^
examination.cpp:28:57: error: missing template arguments before '(' token
  bool operator<(const P &p) { return pair(-x, -y) < pair(-p.x, -p.y); }
                                                         ^