Submission #250253

# Submission time Handle Problem Language Result Execution time Memory
250253 2020-07-17T10:17:14 Z mode149256 Fortune Telling 2 (JOI14_fortune_telling2) C++14
0 / 100
3 ms 1664 KB
/*input
5 3
4 6
9 1
8 8
4 2
3 7
8
2
9
*/
#include <bits/stdc++.h>
using namespace std;

namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}
}
using namespace my_template;

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;

struct FENWICK {
	vi sk;
	int N;
	FENWICK(int n) : N(n) {
		sk.resize(N + 1, 0);
	}

	void add(int i, int val) {
		for (; i <= N; i += (i) & (-i))
			sk[i] += val;
	}

	int get(int i) {
		int ret = 0;
		for (; i > 0; i -= (i) & (-i))
			ret += sk[i];
		return ret;
	}
};

struct node {
	int l, r;
	int did;
	node *left = nullptr;
	node *right = nullptr;
	node(int a, int b): l(a), r(b), did(-1) { }
	inline void add_left() { if (!left) left = new node(l, (l + r) / 2); }
	inline void add_right() { if (!right) right = new node((l + r) / 2 + 1, r); }

	void add(int pos, int val) {
		if (l == r) {
			did = max(did, val);
			return;
		}

		if (pos <= (l + r) / 2) {
			add_left(); left->add(pos, val);
		} else {
			add_right(); right->add(pos, val);
		}

		did = max((left ? left->did : -1), (right ? right->did : -1));
	}

	int get(int a, int b) {
		if (r < a or b < l) return -1;
		else if (a <= l and r <= b) return did;
		else {
			add_left();
			add_right();
			return max(left->get(a, b), right->get(a, b));
		}
	}
};

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N, K;
	cin >> N >> K;
	vpi sk(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> sk[i].x >> sk[i].y;
	}

	node inds(0, MOD);
	vi qr(K);
	vpi suInd(K);
	for (int i = 0; i < K; ++i) {
		cin >> qr[i];
		inds.add(qr[i], i);
		suInd[i] = {qr[i], i};
	}

	sort(suInd.rbegin(), suInd.rend());
	sort(sk.begin(), sk.end(), [](const pi & a, const pi & b) {
		return max(a.x, a.y) > max(b.x, b.y);
	});

	FENWICK fen(K);

	ll ats = 0;
	int j = 0;
	for (int i = 0; i < N; ++i)
	{
		int a = max(sk[i].x, sk[i].y);
		int b = min(sk[i].x, sk[i].y);
		int k = inds.get(b, a - 1);

		while (j < (int)suInd.size() and suInd[j].x >= a) {
			fen.add(suInd[j].y + 1, 1);
			j++;
		}

		int kiek;
		if (k == -1) {
			kiek = fen.get(K);
		} else {
			kiek = fen.get(K) - fen.get(k + 1);
		}
		if (kiek & 1) ats += (ll)sk[i].y;
		else ats += (ll)sk[i].x;
	}

	printf("%lld\n", ats);
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1664 KB Output isn't correct
2 Halted 0 ms 0 KB -