Submission #70438605


Source Code Expand

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
template <class T, class F>
T binarySearch(T ok, T ng, const F &f) {
	while (abs(ok - ng) > 1) {
		T mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	return ok;
}
// 関数ver
template<typename T>
std::pair<std::vector<T>, int> compression(std::vector<T> org) {
	auto copy = org;
	std::sort(copy.begin(), copy.end());
	copy.erase(unique(copy.begin(), copy.end()), copy.end());
	for (auto &e : org) {
		e = std::lower_bound(copy.begin(), copy.end(), e) - copy.begin();
	}
	return { org,copy.size() };
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n; cin >> n;
	long long m; cin >> m;
	int c; cin >> c;
	map<long long, int>mp;
	vector<long long>pos, eve;
	//	pos = { 0,m };
	rep(i, n) {
		long long a; cin >> a;
		pos.push_back(a);
		pos.push_back(a + m);
		eve.push_back(a);
	}
	sort(all(pos));

	//auto eve = pos;
	{
		eve.push_back(0);
		eve.push_back(m);
		std::sort(eve.begin(), eve.end());
		eve.erase(unique(eve.begin(), eve.end()), eve.end());
	}

	long long ans = 0;
	rep(i, eve.size() - 1) {
		long long l = eve[i];
		long long r = eve[i + 1];
		//以下の数
		int c0 = upper_bound(all(pos), l) - pos.begin();
		auto f = [&](const long long x)->bool {
			int c1 = upper_bound(all(pos), x) - pos.begin();
			return c1 - c0 >= c;
		};
		long long tar = binarySearch<long long>(2 * m + 1, 0, f);
		long long tmp = upper_bound(all(pos), tar) - pos.begin();
		tmp -= c0;
		//cout << l << " " << r << " " << tmp << endl;
		ans += (r - l) * tmp;
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - On AtCoder Conference
User kwm_t
Language C++ 23 (gcc 12.2)
Score 425
Code Size 2427 Byte
Status AC
Exec Time 657 ms
Memory 18892 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:11:37: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   11 | #define rep(i, n) for (int i = 0; i < (n); ++i)
      |                                     ^
Main.cpp:65:9: note: in expansion of macro ‘rep’
   65 |         rep(i, eve.size() - 1) {
      |         ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 32
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3484 KiB
example_01.txt AC 1 ms 3404 KiB
hand_00.txt AC 53 ms 18832 KiB
hand_01.txt AC 53 ms 18724 KiB
hand_02.txt AC 657 ms 18744 KiB
hand_03.txt AC 36 ms 18748 KiB
hand_04.txt AC 1 ms 3420 KiB
hand_05.txt AC 1 ms 3420 KiB
random_00.txt AC 76 ms 18816 KiB
random_01.txt AC 74 ms 18880 KiB
random_02.txt AC 79 ms 18740 KiB
random_03.txt AC 133 ms 18788 KiB
random_04.txt AC 144 ms 18820 KiB
random_05.txt AC 136 ms 18892 KiB
random_06.txt AC 273 ms 18816 KiB
random_07.txt AC 269 ms 18804 KiB
random_08.txt AC 258 ms 18720 KiB
random_09.txt AC 67 ms 18724 KiB
random_10.txt AC 60 ms 18892 KiB
random_11.txt AC 64 ms 18644 KiB
random_12.txt AC 65 ms 18792 KiB
random_13.txt AC 92 ms 18832 KiB
random_14.txt AC 89 ms 18724 KiB
random_15.txt AC 71 ms 18744 KiB
random_16.txt AC 115 ms 18720 KiB
random_17.txt AC 115 ms 18780 KiB
random_18.txt AC 100 ms 18880 KiB
random_19.txt AC 168 ms 18744 KiB
random_20.txt AC 160 ms 18804 KiB
random_21.txt AC 357 ms 18816 KiB
random_22.txt AC 389 ms 18876 KiB
random_23.txt AC 595 ms 18776 KiB