提出 #56803719


ソースコード 拡げる

// #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;

template<int MOD>
class generic_mint {
public:
    static_assert(MOD > 1 && MOD < std::numeric_limits<int>::max() / 2);

    generic_mint() {
        value = 0;
    }

    generic_mint(int _value) {
        if (_value >= 0 && _value < MOD) {
            value = _value;
        } else {
            value = _value % MOD;
            if (value < 0) {
                value += MOD;
            }
        }
    }

    generic_mint(ll _value) {
        if (_value >= 0 && _value < MOD) {
            value = _value;
        } else {
            value = _value % MOD;
            if (value < 0) {
                value += MOD;
            }
        }
    }

    generic_mint(int _value, bool ignored) {
        assert(ignored);
        value = _value;
    }

    generic_mint(ll _value, bool ignored) {
        assert(ignored);
        value = _value;
    }

    generic_mint<MOD> operator+() const {
        return *this;
    }

    generic_mint<MOD> operator-() const {
        return generic_mint<MOD>(MOD - value, true);
    }

    generic_mint<MOD> operator+(const generic_mint<MOD>& other) const {
        if (value + other.value >= MOD) {
            return generic_mint<MOD>(value + other.value - MOD, true);
        }
        return generic_mint<MOD>(value + other.value, true);
    }

    generic_mint<MOD> operator-(const generic_mint<MOD>& other) const {
        if (value - other.value < 0) {
            return generic_mint<MOD>(value - other.value + MOD, true);
        }
        return generic_mint<MOD>(value - other.value, true);
    }

    generic_mint<MOD> operator*(const generic_mint<MOD>& other) const {
        return generic_mint<MOD>((int)(1ll * value * other.value % MOD), true);
    }

    generic_mint<MOD> operator/(const generic_mint<MOD>& other) const {
        return (*this) * other.pow(MOD - 2);
    }

    generic_mint<MOD>& operator+=(const generic_mint<MOD>& other) {
        *this = (*this) + other;
        return *this;
    }

    generic_mint<MOD>& operator-=(const generic_mint<MOD>& other) {
        *this = (*this) - other;
        return *this;
    }

    generic_mint<MOD>& operator*=(const generic_mint<MOD>& other) {
        *this = (*this) * other;
        return *this;
    }

    generic_mint<MOD>& operator/=(const generic_mint<MOD>& other) {
        *this = (*this) / other;
        return *this;
    }

    generic_mint<MOD> operator++(int) {
        auto result = *this;
        *this += generic_mint<MOD>(1, true);
        return result;
    }

    generic_mint<MOD>& operator++() {
        *this += generic_mint<MOD>(1, true);
        return *this;
    }

    generic_mint<MOD> operator--(int) {
        auto result = *this;
        *this -= generic_mint<MOD>(1, true);
        return result;
    }

    generic_mint<MOD>& operator--() {
        *this -= generic_mint<MOD>(1, true);
        return *this;
    }

    generic_mint<MOD> pow(ll n) const {
        assert(n >= 0);

        generic_mint<MOD> result(1, true);
        generic_mint<MOD> cur = *this;
        while (n != 0) {
            if (n % 2 == 1) {
                result *= cur;
            }
            cur *= cur;
            n /= 2;
        }

        return result;
    }

    generic_mint<MOD> inv() const {
        return pow(MOD - 2);
    }

    int get_value() const {
        return value;
    }

    explicit operator int() const {
        return value;
    }

    explicit operator ll() const {
        return value;
    }

    bool operator==(const generic_mint<MOD>& other) const {
    	return value == other.value;
    }
private:
    int value;
};

using mint1 = generic_mint<998244353>;
using mint2 = generic_mint<(int)1e9 + 7>;

const int N = 200100;

struct hash {
	mint1 x;
	mint2 y;

	hash() : x(0, true), y(0, true) {}

	hash(int val) : x(val), y(val) {}

	hash(mint1 _x, mint2 _y) : x(_x), y(_y) {}

	hash operator+(const hash& other) const {
		return hash(x + other.x, y + other.y);
	}

	hash operator-(const hash& other) const {
		return hash(x - other.x, y - other.y);
	}

	bool operator==(const hash& other) const {
		return x == other.x && y == other.y;
	}
};

int a[N], b[N];
int num[N];
hash h1[N], h2[N];

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

    for (int i = 0; i < n; ++i) {
    	scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i) {
    	scanf("%d", &b[i]);
    }

    for (int i = 0; i < N; ++i) {
    	num[i] = rnd();
    }

    for (int i = 0; i < n; ++i) {
    	h1[i] = hash(num[a[i]]);
    	h2[i] = hash(num[b[i]]);

    	if (i != 0) {
    		h1[i] = h1[i] + h1[i - 1];
    		h2[i] = h2[i] + h2[i - 1];
    	}
    }

    while (q--) {
    	int l1, r1, l2, r2;
    	scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
    	--l1;
    	--r1;
    	--l2;
    	--r2;

    	if (r1 - l1 != r2 - l2) {
    		printf("No\n");
    		continue;
    	}

    	auto val1 = h1[r1];
    	auto val2 = h2[r2];
    	if (l1 != 0) {
    		val1 = val1 - h1[l1 - 1];
    	}
    	if (l2 != 0) {
    		val2 = val2 - h2[l2 - 1];
    	}

    	if (val1 == val2) {
    		printf("Yes\n");
    	} else {
    		printf("No\n");
    	}
    }
}

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;
}

提出情報

提出日時
問題 F - Rearrange Query
ユーザ DishonoredR
言語 C++ 20 (gcc 12.2)
得点 500
コード長 8557 Byte
結果 AC
実行時間 109 ms
メモリ 9356 KiB

コンパイルエラー

Main.cpp: In function ‘void run()’:
Main.cpp:291:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  291 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:294:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  294 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:297:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  297 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:316:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  316 |         scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 60
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.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, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 3 ms 7568 KiB
00_sample_01.txt AC 3 ms 7488 KiB
01_random_00.txt AC 14 ms 7576 KiB
01_random_01.txt AC 32 ms 7576 KiB
01_random_02.txt AC 25 ms 7556 KiB
01_random_03.txt AC 32 ms 7620 KiB
01_random_04.txt AC 28 ms 7576 KiB
01_random_05.txt AC 32 ms 7632 KiB
01_random_06.txt AC 34 ms 7676 KiB
01_random_07.txt AC 32 ms 7432 KiB
01_random_08.txt AC 93 ms 9168 KiB
01_random_09.txt AC 95 ms 9108 KiB
01_random_10.txt AC 97 ms 9100 KiB
01_random_11.txt AC 96 ms 9216 KiB
01_random_12.txt AC 99 ms 9220 KiB
01_random_13.txt AC 97 ms 9232 KiB
01_random_14.txt AC 97 ms 9232 KiB
01_random_15.txt AC 97 ms 9168 KiB
01_random_16.txt AC 96 ms 9160 KiB
01_random_17.txt AC 97 ms 9044 KiB
01_random_18.txt AC 96 ms 9168 KiB
01_random_19.txt AC 96 ms 9356 KiB
01_random_20.txt AC 96 ms 9240 KiB
01_random_21.txt AC 96 ms 9124 KiB
01_random_22.txt AC 98 ms 9236 KiB
01_random_23.txt AC 99 ms 9112 KiB
01_random_24.txt AC 98 ms 9184 KiB
01_random_25.txt AC 99 ms 9184 KiB
01_random_26.txt AC 107 ms 9164 KiB
01_random_27.txt AC 108 ms 9172 KiB
01_random_28.txt AC 109 ms 9168 KiB
01_random_29.txt AC 106 ms 9044 KiB
01_random_30.txt AC 106 ms 9236 KiB
01_random_31.txt AC 107 ms 9040 KiB
01_random_32.txt AC 107 ms 9356 KiB
01_random_33.txt AC 106 ms 9044 KiB
01_random_34.txt AC 106 ms 9200 KiB
01_random_35.txt AC 106 ms 9236 KiB
01_random_36.txt AC 107 ms 9228 KiB
01_random_37.txt AC 109 ms 9100 KiB
01_random_38.txt AC 108 ms 9356 KiB
01_random_39.txt AC 107 ms 8980 KiB
01_random_40.txt AC 107 ms 9224 KiB
01_random_41.txt AC 109 ms 9104 KiB
01_random_42.txt AC 107 ms 9100 KiB
01_random_43.txt AC 106 ms 9220 KiB
01_random_44.txt AC 108 ms 9348 KiB
01_random_45.txt AC 107 ms 9168 KiB
01_random_46.txt AC 3 ms 7620 KiB
01_random_47.txt AC 3 ms 7612 KiB
01_random_48.txt AC 94 ms 9236 KiB
01_random_49.txt AC 96 ms 9048 KiB
01_random_50.txt AC 94 ms 9200 KiB
01_random_51.txt AC 93 ms 9172 KiB
01_random_52.txt AC 100 ms 9168 KiB
01_random_53.txt AC 100 ms 9236 KiB
01_random_54.txt AC 101 ms 8984 KiB
01_random_55.txt AC 103 ms 9220 KiB
01_random_56.txt AC 102 ms 9236 KiB
01_random_57.txt AC 31 ms 7492 KiB