提出 #56542828


ソースコード 拡げる

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x...) std::cerr << "[DEBUG]\t" << __LINE__ << ":\t" << (#x) << " = "; print_debug(x)
#else
    #define debug(x...) 238
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(nullptr)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::pair<T1, T2>& p) {
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}

template<size_t index, typename T>
std::ostream& print_tuple(std::ostream& out, const T& t) {
    if constexpr (index == std::tuple_size<T>::value) {
        out << ")";
        return out;
    } else {
        if (index > 0) {
            out << ", ";
        } else {
            out << "(";
        }
        out << std::get<index>(t);
        return print_tuple<index + 1, T>(out, t);
    }
}

template<typename ...T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& t) {
    return print_tuple<0, std::tuple<T...>>(out, t);
}

template<typename Container, typename = decltype(std::begin(std::declval<Container>()))>
typename std::enable_if<!std::is_same<Container, std::string>::value, std::ostream&>::type
operator<<(std::ostream& out, const Container& container) {
    out << "{";
    for (auto it = container.begin(); it != container.end(); ++it) {
        if (it != container.begin()) {
            out << ", ";
        }
        out << *it;
    }
    out << "}";
    return out;
}

void print_debug() {
    std::cerr << std::endl;
}

template<typename T, typename... V>
void print_debug(const T& value, const V&... others) {
    std::cerr << value;
    if (sizeof...(others) != 0) {
        std::cerr << ", ";
        print_debug(others...);
    } else {
        std::cerr << std::endl;
    }
}

template<typename T>
bool smin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool smax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 200100;
const int X = 2000100;

ll sumX[2 * X + 1], sumY[2 * X + 1];

void run() {
	int n, d;
	scanf("%d%d", &n, &d);

	std::vector<ll> allX, allY, prefX, prefY;
	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		allX.push_back(x);
		allY.push_back(y);
	}

	std::sort(allX.begin(), allX.end());
	std::sort(allY.begin(), allY.end());

	for (int i = 0; i < n; ++i) {
		prefX.push_back(allX[i]);
		prefY.push_back(allY[i]);
		if (i != 0) {
			prefX[i] += prefX[i - 1];
			prefY[i] += prefY[i - 1];
		}
	}

	for (int x = -X; x <= X; ++x) {
		auto i = std::lower_bound(allX.begin(), allX.end(), x) - allX.begin();
		// < i <=> < x
		// >= i <=> >= x

		if (i != 0) {
			sumX[x + X] += 1ll * i * x - prefX[i - 1];
		}
		if (i != n) {
			sumX[x + X] += prefX[n - 1];
			if (i != 0) {
				sumX[x + X] -= prefX[i - 1];
			}
			sumX[x + X] -= 1ll * (n - i) * x;
		}
	}
	for (int y = -X; y <= X; ++y) {
		auto j = std::lower_bound(allY.begin(), allY.end(), y) - allY.begin();
		if (j != 0) {
			sumY[y + X] += 1ll * j * y - prefY[j - 1];
		}
		if (j != n) {
			sumY[y + X] += prefY[n - 1];
			if (j != 0) {
				sumY[y + X] -= prefY[j - 1];
			}
			sumY[y + X] -= 1ll * (n - j) * y;
		}
	}

	std::sort(sumY, sumY + 2 * X + 1);

	ll ans = 0;
	for (int x = -X; x <= X; ++x) {
		ll curS = sumX[x + X];
		ll rest = d - curS;
		if (rest < 0) {
			continue;
		}

		auto it = std::upper_bound(sumY, sumY + 2 * X + 1, rest);
		ans += it - sumY;
	}

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

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    #ifdef PERVEEVM_LOCAL
        auto start = std::chrono::high_resolution_clock::now();
    #endif

    run();

    #ifdef PERVEEVM_LOCAL
        auto end = std::chrono::high_resolution_clock::now();
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}

提出情報

提出日時
問題 E - Manhattan Multifocal Ellipse
ユーザ DishonoredR
言語 C++ 20 (gcc 12.2)
得点 475
コード長 4806 Byte
結果 AC
実行時間 488 ms
メモリ 74024 KiB

コンパイルエラー

Main.cpp: In function ‘void run()’:
Main.cpp:111:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  111 |         scanf("%d%d", &n, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:116:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  116 |                 scanf("%d%d", &x, &y);
      |                 ~~~~~^~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 3
AC × 29
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 356 ms 66128 KiB
00_sample_02.txt AC 359 ms 66324 KiB
00_sample_03.txt AC 357 ms 66328 KiB
01_random_01.txt AC 369 ms 66188 KiB
01_random_02.txt AC 355 ms 66144 KiB
01_random_03.txt AC 368 ms 66384 KiB
01_random_04.txt AC 359 ms 66252 KiB
01_random_05.txt AC 345 ms 66264 KiB
01_random_06.txt AC 488 ms 74024 KiB
01_random_07.txt AC 485 ms 73936 KiB
01_random_08.txt AC 381 ms 66268 KiB
01_random_09.txt AC 397 ms 66308 KiB
01_random_10.txt AC 387 ms 66304 KiB
01_random_11.txt AC 384 ms 66264 KiB
01_random_12.txt AC 401 ms 66296 KiB
01_random_13.txt AC 378 ms 66396 KiB
01_random_14.txt AC 396 ms 66300 KiB
01_random_15.txt AC 391 ms 66172 KiB
01_random_16.txt AC 401 ms 66180 KiB
01_random_17.txt AC 386 ms 66148 KiB
01_random_18.txt AC 380 ms 66272 KiB
01_random_19.txt AC 390 ms 66172 KiB
01_random_20.txt AC 390 ms 66180 KiB
02_handmade_01.txt AC 403 ms 66348 KiB
02_handmade_02.txt AC 333 ms 66428 KiB
02_handmade_03.txt AC 303 ms 66264 KiB
02_handmade_04.txt AC 303 ms 66256 KiB
02_handmade_05.txt AC 297 ms 66188 KiB
02_handmade_06.txt AC 297 ms 66144 KiB