Submission #56562177
Source Code Expand
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#ifdef EMT
#include "Header/stdc++.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#ifdef EMT
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T, typename T2> ostream& operator<<(ostream &os, const pair<T, T2> &obj) {
return os << '{' << obj.first << ',' << obj.second << '}';
}
template<class TupType, size_t... I> void lamy_kawaii(ostream& os, const TupType& _tup, index_sequence<I...>) {
// source: https://stackoverflow.com/a/41171552
os << '{';
(..., (cerr << (I == 0? "" : ",") << get<I>(_tup)));
os << '}';
}
template<class... T> ostream& operator<<(ostream &os, const tuple<T...>& _tup) {
lamy_kawaii(os, _tup, make_index_sequence<sizeof...(T)>());
return os;
}
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
cerr << "\e[1;33m" << s << " = [";
while (l != r) {
cerr << *l;
cerr << (++l == r ? ']' : ',');
}
cerr << "\e[0m\n";
}
#else
#define debug(x) 48763
#define print(x) 48763
#endif
template<typename T, typename T2> istream& operator>>(istream &is, pair<T, T2> &obj) {
is >> obj.first >> obj.second;
return is;
}
template<typename T> istream& operator>>(istream &is, vector<T> &obj) {
for (auto &x : obj)
is >> x;
return is;
}
#define YN(x) ((x) ? "YES" : "NO")
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define emilia_my_wife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
template<typename T>
using base_type = remove_cv_t<remove_reference_t<T>>;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
static int Lamy_is_cute = []() {
emilia_my_wife
return 48763;
}();
/*--------------------------------------------------------------------------------------*/
signed main() {
int n;
ll d;
cin >> n >> d;
vector<ll> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
sort(x.begin(), x.end());
sort(y.begin(), y.end());
const int N = 4e6 + 25, C = 2e6 + 5;
vector<ll> cost_x(N), cost_y(N);
for (auto &a : x)
a += C;
for (auto &a : y)
a += C;
{
ll sum = accumulate(x.begin(), x.end(), 0LL), sum2 = 0;
ll cnt = n, cnt2 = 0;
for (int i = 0, it = 0; i < N; i++) {
while (it < n && x[it] <= i) {
sum -= x[it];
sum2 += x[it];
cnt--;
cnt2++;
it++;
}
cost_x[i] = (sum - cnt * i) + (cnt2 * i - sum2);
}
}
{
ll sum = accumulate(y.begin(), y.end(), 0LL), sum2 = 0;
ll cnt = n, cnt2 = 0;
for (int i = 0, it = 0; i < N; i++) {
while (it < n && y[it] <= i) {
sum -= y[it];
sum2 += y[it];
cnt--;
cnt2++;
it++;
}
cost_y[i] = (sum - cnt * i) + (cnt2 * i - sum2);
}
}
int base = 0;
while (cost_y[base + 1] < cost_y[base])
base++;
int l = base, r = base;
debug(pair(l, r));
ll ans = 0;
for (int i = 0; i < N; i++) {
if (cost_y[base] + cost_x[i] > d)
continue;
while (cost_y[l - 1] + cost_x[i] <= d)
l--;
while (cost_y[r + 1] + cost_x[i] <= d)
r++;
while (l + 1 <= base && cost_y[l] + cost_x[i] > d)
l++;
while (r - 1 >= base && cost_y[r] + cost_x[i] > d)
r--;
ans += r - l + 1;
debug(pair(l - C, r - C));
debug(tuple(cost_x[i], cost_y[l], cost_y[r]));
}
cout << ans << '\n';
}
Submission Info
Submission Time |
|
Task |
E - Manhattan Multifocal Ellipse |
User |
JiKuai |
Language |
C++ 20 (gcc 12.2) |
Score |
475 |
Code Size |
4535 Byte |
Status |
AC |
Exec Time |
80 ms |
Memory |
68840 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:44:18: warning: statement has no effect [-Wunused-value]
44 | #define debug(x) 48763
| ^~~~~
Main.cpp:129:5: note: in expansion of macro ‘debug’
129 | debug(pair(l, r));
| ^~~~~
Main.cpp:44:18: warning: statement has no effect [-Wunused-value]
44 | #define debug(x) 48763
| ^~~~~
Main.cpp:144:9: note: in expansion of macro ‘debug’
144 | debug(pair(l - C, r - C));
| ^~~~~
Main.cpp:44:18: warning: statement has no effect [-Wunused-value]
44 | #define debug(x) 48763
| ^~~~~
Main.cpp:145:9: note: in expansion of macro ‘debug’
145 | debug(tuple(cost_x[i], cost_y[l], cost_y[r]));
| ^~~~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
475 / 475 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
All |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_01.txt |
AC |
41 ms |
65616 KiB |
00_sample_02.txt |
AC |
41 ms |
65768 KiB |
00_sample_03.txt |
AC |
42 ms |
65568 KiB |
01_random_01.txt |
AC |
42 ms |
65628 KiB |
01_random_02.txt |
AC |
41 ms |
65676 KiB |
01_random_03.txt |
AC |
41 ms |
65620 KiB |
01_random_04.txt |
AC |
41 ms |
65568 KiB |
01_random_05.txt |
AC |
41 ms |
65628 KiB |
01_random_06.txt |
AC |
79 ms |
68840 KiB |
01_random_07.txt |
AC |
80 ms |
68788 KiB |
01_random_08.txt |
AC |
41 ms |
65588 KiB |
01_random_09.txt |
AC |
41 ms |
65584 KiB |
01_random_10.txt |
AC |
41 ms |
65532 KiB |
01_random_11.txt |
AC |
41 ms |
65776 KiB |
01_random_12.txt |
AC |
41 ms |
65584 KiB |
01_random_13.txt |
AC |
43 ms |
65604 KiB |
01_random_14.txt |
AC |
42 ms |
65672 KiB |
01_random_15.txt |
AC |
41 ms |
65596 KiB |
01_random_16.txt |
AC |
42 ms |
65620 KiB |
01_random_17.txt |
AC |
42 ms |
65680 KiB |
01_random_18.txt |
AC |
42 ms |
65608 KiB |
01_random_19.txt |
AC |
41 ms |
65576 KiB |
01_random_20.txt |
AC |
42 ms |
65608 KiB |
02_handmade_01.txt |
AC |
41 ms |
65644 KiB |
02_handmade_02.txt |
AC |
42 ms |
65696 KiB |
02_handmade_03.txt |
AC |
45 ms |
65572 KiB |
02_handmade_04.txt |
AC |
46 ms |
65636 KiB |
02_handmade_05.txt |
AC |
47 ms |
65532 KiB |
02_handmade_06.txt |
AC |
47 ms |
65604 KiB |