답안 #201653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201653 2020-02-11T16:05:47 Z Saboon San (COCI17_san) C++14
96 / 120
624 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 300000 + 10;
const ll N = 1e18;

map<ll,int> fen;

int get(ll x){
	int ret = 0;
	x ++;
	if (x < 0)
		x = 0;
	for (; x; x -= x & -x)
		ret += fen[x];
	return ret;
}

void add(ll x){
	for (x ++; x <= N; x += x & -x)
		fen[x] ++;
}

vector<pair<ll,ll> > get(vector<pair<ll,ll> > &a, bool wh){
	vector<pair<ll,ll>> c;
	int n = a.size();
	for (int mask = 1; mask < (1 << n); mask++){
		ll last = -1, first = -1;
		bool flag = 1;
		ll sum = 0;
		for (int i = 0; i < n; i++){
			if (!(mask & (1 << i)))
				continue;
			if (last > a[i].first){
				flag = 0;
				break;
			}
			if (first == -1)
				first = a[i].first;
			last = a[i].first;
			sum += a[i].second;
		}
		if (flag == 0)
			continue;
		if (wh == 0)
			c.push_back({last, sum});
		else
			c.push_back({first, sum});
	}
	if (wh == 0)
		c.push_back({1, 0});
	else
		c.push_back({1000*1000*1000, 0});
	return c;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	ll k;
	cin >> n >> k;
	vector<pair<ll,ll> > a, b;
	for (int i = 0; i < n; i++){
		ll h, g;
		cin >> h >> g;
		if (i < n / 2)
			a.push_back({h, g});
		else
			b.push_back({h, g});
	}
	vector<pair<ll,ll>> c = get(a, 0);
	vector<pair<ll,ll>> d = get(b, 1);
	sort(c.begin(), c.end());
	sort(d.begin(), d.end());
	int ptr = 0;
	n = c.size();
	int m = d.size();
	ll answer = 0;

	for (int i = 0; i < d.size(); i++){
		while (ptr < n and c[ptr].first <= d[i].first)
			add(c[ptr ++].second);
		answer += ptr - get(k - d[i].second - 1);
	}
	cout << answer << endl;
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:81:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < d.size(); i++){
                  ~~^~~~~~~~~~
san.cpp:78:6: warning: unused variable 'm' [-Wunused-variable]
  int m = d.size();
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 21104 KB Output is correct
2 Correct 12 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 17596 KB Output is correct
2 Correct 91 ms 10996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 624 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -