QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#849336#4405. 普罗霍洛夫卡peaneval_kala100 ✓10297ms31784kbC++2310.9kb2025-01-09 14:41:562025-01-09 14:41:56

Judging History

你现在查看的是最新测评结果

  • [2025-01-09 14:41:56]
  • 评测
  • 测评结果:100
  • 用时:10297ms
  • 内存:31784kb
  • [2025-01-09 14:41:56]
  • 提交

answer

#pragma GCC optimize(3, "unroll-loops", "no-stack-protector")
#define atsum(l, r) accumulate(l, r, 0)
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void chkmin(T &x, T y) {
    x = min(x, y);
}
template <typename T>
inline void chkmax(T &x, T y) {
    x = max(x, y);
}
namespace FastIO {
// ------------------------------
#define IN_HAS_NEG
#define OUT_HAS_NEG
#define CHK_EOF
#define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if (defined(LOCAL) || defined(_WIN32)) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include <sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr,
                                               *_read_ptr_end = nullptr;
inline char gc() {
    if (__builtin_expect(_read_ptr == _read_ptr_end, false)) {
        _read_ptr = _read_buffer;
        _read_ptr_end =
            _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
        if (__builtin_expect(_read_ptr == _read_ptr_end, false)) return EOF;
#endif
    }
    return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr =
    (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c) {
    *_write_ptr++ = c;
    if (__builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false)) {
        fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
        _write_ptr = _write_buffer;
    }
}
INLINE_V struct _auto_flush {
    ~_auto_flush() {
        fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
    }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline bool _isdigit(char c) { return (c & 16) && c != EOF; }
inline bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline bool _isdigit(char c) { return c & 16; }
inline bool _isgraph(char c) { return c > 32; }
#endif
template <class T>
INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <class T>
INLINE_V constexpr bool _is_signed = numeric_limits<T>::is_signed;
template <class T>
INLINE_V constexpr bool _is_unsigned = _is_integer<T> && !_is_signed<T>;
template <>
INLINE_V constexpr bool _is_integer<__int128> = true;
template <>
INLINE_V constexpr bool _is_integer<__uint128_t> = true;
template <>
INLINE_V constexpr bool _is_signed<__int128> = true;
template <>
INLINE_V constexpr bool _is_unsigned<__uint128_t> = true;
#undef INLINE_V
inline void read(char &c) {
    do c = gc();
    while (!_isgraph(c));
}
inline void read_cstr(char *s) {
    char c = gc();
    while (!_isgraph(c)) c = gc();
    while (_isgraph(c)) *s++ = c, c = gc();
    *s = 0;
}
inline void read(string &s) {
    char c = gc();
    s.clear();
    while (!_isgraph(c)) c = gc();
    while (_isgraph(c)) s.push_back(c), c = gc();
}
#ifdef IN_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void read(T &x) {
    char c = gc();
    bool f = true;
    x = 0;
    while (!_isdigit(c)) {
        if (c == 45) f = false;
        c = gc();
    }
    if (f)
        while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
    else
        while (_isdigit(c)) x = x * 10 - (c & 15), c = gc();
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void read(T &x) {
    char c = gc();
    while (!_isdigit(c)) c = gc();
    x = 0;
    while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) {
    while (*s) pc(*s++);
}
inline void write(const string &s) {
    for (char c : s) pc(c);
}
#ifdef OUT_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void write(T x) {
    char buffer[numeric_limits<T>::digits10 + 1];
    int digits = 0;
    if (x >= 0) do
            buffer[digits++] = (x % 10) | 48, x /= 10;
        while (x);
    else {
        pc(45);
        do buffer[digits++] = -(x % 10) | 48, x /= 10;
        while (x);
    }
    while (digits) pc(buffer[--digits]);
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void write(T x) {
    char buffer[numeric_limits<T>::digits10 + 1];
    int digits = 0;
    do buffer[digits++] = (x % 10) | 48, x /= 10;
    while (x);
    while (digits) pc(buffer[--digits]);
}
template <int N>
struct _tuple_io_helper {
    template <class... T>
    static inline void _read(tuple<T...> &x) {
        _tuple_io_helper<N - 1>::_read(x), read(get<N - 1>(x));
    }
    template <class... T>
    static inline void _write(const tuple<T...> &x) {
        _tuple_io_helper<N - 1>::_write(x), pc(32), write(get<N - 1>(x));
    }
};
template <>
struct _tuple_io_helper<1> {
    template <class... T>
    static inline void _read(tuple<T...> &x) {
        read(get<0>(x));
    }
    template <class... T>
    static inline void _write(const tuple<T...> &x) {
        write(get<0>(x));
    }
};
template <class... T>
inline void read(tuple<T...> &x) {
    _tuple_io_helper<sizeof...(T)>::_read(x);
}
template <class... T>
inline void write(const tuple<T...> &x) {
    _tuple_io_helper<sizeof...(T)>::_write(x);
}
template <class T1, class T2>
inline void read(pair<T1, T2> &x) {
    read(x.first), read(x.second);
}
template <class T1, class T2>
inline void write(const pair<T1, T2> &x) {
    write(x.first), pc(32), write(x.second);
}
template <class T1, class... T2>
inline void read(T1 &x, T2 &...y) {
    read(x), read(y...);
}
template <class... T>
inline void read_cstr(char *x, T *...y) {
    read_cstr(x), read_cstr(y...);
}
template <class T1, class... T2>
inline void write(const T1 &x, const T2 &...y) {
    write(x), write(y...);
}
template <class... T>
inline void write_cstr(const char *x, const T *...y) {
    write_cstr(x), write_cstr(y...);
}
template <class T>
inline void print(const T &x) {
    write(x);
}
inline void print_cstr(const char *x) { write_cstr(x); }
template <class T1, class... T2>
inline void print(const T1 &x, const T2 &...y) {
    print(x), pc(32), print(y...);
}
template <class... T>
inline void print_cstr(const char *x, const T *...y) {
    print_cstr(x), pc(32), print_cstr(y...);
}
inline void println() { pc(10); }
inline void println_cstr() { pc(10); }
template <class... T>
inline void println(const T &...x) {
    print(x...), pc(10);
}
template <class... T>
inline void println_cstr(const T *...x) {
    print_cstr(x...), pc(10);
}
}  // namespace FastIO
using namespace FastIO;
template <typename T>
inline void clear(T &x) {
    T y;
    swap(x, y);
}
const int N = 4e5 + 10;
int a[N], n, pre[N], q;
__uint128_t x[N], y[N];
int nod[N];
inline int get(__uint128_t x, int y) {
    return (x >> (18 * y)) & ((1 << 18) - 1);
}
inline void add(__uint128_t &x, int y, int v) {
    // return (x >> (18 * y)) & ((1 << 18) - 1);
    x += __int128(v) << (18 * y);
}
vector<pair<int, int> > vec[N];
inline int calc(__uint128_t x) {
    int res = 0;
    for (int i = 0; i < 7; i++) res ^= get(x, i);
    return res;
}
int kl;
inline int query(int l, int r) {
    int v = 0;
    __uint128_t jcun = 0;
    if (kl) {
        if (l / 7 != r / 7) {
            while (l % 7) v ^= get(y[l / 7] ^ x[l / 7], l % 7), l++;
            while (r % 7 != 6) v ^= get(y[r / 7] ^ x[r / 7], r % 7), r--;
            l /= 7, r /= 7;
#pragma GCC unroll 8
            for (int t = l; t <= r; t++) jcun ^= y[t] ^ x[t];
            v ^= calc(jcun);
        } else {
            for (int j = l; j <= r; j++) v ^= get(y[j / 7] ^ x[l / 7], j % 7);
        }
    } else {
        if (l / 7 != r / 7) {
            while (l % 7) v ^= get(y[l / 7], l % 7), l++;
            while (r % 7 != 6) v ^= get(y[r / 7], r % 7), r--;
            l /= 7, r /= 7;
#pragma GCC unroll 8
            for (int t = l; t <= r; t++) jcun ^= y[t];
            v ^= calc(jcun);
        } else {
            for (int j = l; j <= r; j++) v ^= get(y[j / 7], j % 7);
        }
    }
    return v;
}
inline pair<int, int> add(int l, int r, int v) {
    if (l > r) return {0, 0};
    __uint128_t jcun = 0;
    if (l / 7 != r / 7) {
        while (l % 7) {
            __uint128_t pre = x[l / 7];
            add(x[l / 7], l % 7, v);
            if (!kl) y[l / 7] ^= x[l / 7] ^ pre;
            l++;
        }
        while (r % 7 != 6) {
            __uint128_t pre = x[r / 7];
            add(x[r / 7], r % 7, v);
            if (!kl) y[r / 7] ^= x[r / 7] ^ pre;
            r--;
        }
        for (int i = 0; i < 7; i++) add(jcun, i, v);
        l /= 7, r /= 7;
        if (kl)
#pragma GCC unroll 8
            for (int t = l; t <= r; t++) x[t] += jcun;
        else
#pragma GCC unroll 8
            for (int t = l; t <= r; t++)
                y[t] ^= x[t], x[t] += jcun, y[t] ^= x[t];
        return make_pair(l - 1, r + 1);
    } else {
        for (int j = l; j <= r; j++) {
            __uint128_t pre = x[j / 7];
            add(x[j / 7], j % 7, v);
            if (!kl) y[j / 7] ^= x[j / 7] ^ pre;
        }
    }
    return make_pair(0, 0);
}

int main() {
    read(n, q);
    assert(n <= 400000);
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = 1; i <= q; i++) {
        int u, v;
        read(u, v), vec[v].emplace_back(u, i);
    }

    for (int i = 1; i <= n; i++) {
        sort(vec[i].begin(), vec[i].end(), greater<>());
        kl = i & 1;
        int k = pre[a[i]];
        auto [l, r] = add(k + 1, i, 1);
        pre[a[i]] = i;
        int pr = i / 7;
        // cerr << "find qwq:" << l << ' ' << r << ' ' << pr << ' ' << get(x[1],
        // 1) << ' ' << get(y[1], 1) << endl;
        //         if (r == 0) {
        // #pragma GCC unroll 8
        //         for (int t = 0; t <= pr; t++) y[t] ^= x[t];
        //         } else {
        // #pragma GCC unroll 8
        //         for (int t = 0; t <= l; t++) y[t] ^= x[t];
        // #pragma GCC unroll 8
        //         for (int t = r; t <= pr; t++) y[t] ^= x[t];
        //         }
        int cr = i + 1;
        int curans = 0;
        for (auto [v, id] : vec[i])
            nod[id] = (curans ^= query(v, cr - 1)), cr = v;
    }
    for (int i = 1; i <= q; i++) println(nod[i]);
    return 0;
}

Details

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 11804kb

Test #2:

score: 5
Accepted
time: 2ms
memory: 9876kb

Test #3:

score: 5
Accepted
time: 0ms
memory: 11808kb

Test #4:

score: 5
Accepted
time: 2ms
memory: 11800kb

Test #5:

score: 5
Accepted
time: 2ms
memory: 11864kb

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 5
Accepted
time: 0ms
memory: 8120kb

Test #7:

score: 5
Accepted
time: 4ms
memory: 10204kb

Test #8:

score: 5
Accepted
time: 4ms
memory: 8100kb

Test #9:

score: 5
Accepted
time: 5ms
memory: 12232kb

Test #10:

score: 5
Accepted
time: 5ms
memory: 12092kb

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 10
Accepted
time: 639ms
memory: 16952kb

Test #12:

score: 10
Accepted
time: 636ms
memory: 15176kb

Test #13:

score: 10
Accepted
time: 638ms
memory: 17148kb

Test #14:

score: 10
Accepted
time: 641ms
memory: 16956kb

Test #15:

score: 10
Accepted
time: 636ms
memory: 15344kb

Subtask #4:

score: 10
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 10
Accepted
time: 2543ms
memory: 18876kb

Test #17:

score: 10
Accepted
time: 2529ms
memory: 21912kb

Test #18:

score: 10
Accepted
time: 2529ms
memory: 21188kb

Test #19:

score: 10
Accepted
time: 2527ms
memory: 21816kb

Test #20:

score: 10
Accepted
time: 2529ms
memory: 20116kb

Subtask #5:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #21:

score: 10
Accepted
time: 5698ms
memory: 25108kb

Test #22:

score: 10
Accepted
time: 5693ms
memory: 25984kb

Test #23:

score: 10
Accepted
time: 5743ms
memory: 24964kb

Test #24:

score: 10
Accepted
time: 5696ms
memory: 26208kb

Test #25:

score: 10
Accepted
time: 5680ms
memory: 24020kb

Subtask #6:

score: 10
Accepted

Dependency #5:

100%
Accepted

Test #26:

score: 10
Accepted
time: 7823ms
memory: 27664kb

Test #27:

score: 10
Accepted
time: 7802ms
memory: 27508kb

Test #28:

score: 10
Accepted
time: 7811ms
memory: 27528kb

Test #29:

score: 10
Accepted
time: 7795ms
memory: 28540kb

Test #30:

score: 10
Accepted
time: 7799ms
memory: 28404kb

Subtask #7:

score: 10
Accepted

Test #31:

score: 10
Accepted
time: 18ms
memory: 18008kb

Test #32:

score: 10
Accepted
time: 34ms
memory: 18160kb

Test #33:

score: 10
Accepted
time: 26ms
memory: 17588kb

Test #34:

score: 10
Accepted
time: 28ms
memory: 17704kb

Test #35:

score: 10
Accepted
time: 25ms
memory: 15052kb

Subtask #8:

score: 10
Accepted

Test #36:

score: 10
Accepted
time: 2957ms
memory: 29492kb

Test #37:

score: 10
Accepted
time: 2970ms
memory: 31124kb

Test #38:

score: 10
Accepted
time: 2959ms
memory: 29868kb

Test #39:

score: 10
Accepted
time: 2965ms
memory: 31464kb

Test #40:

score: 10
Accepted
time: 2955ms
memory: 29508kb

Subtask #9:

score: 10
Accepted

Dependency #8:

100%
Accepted

Test #41:

score: 10
Accepted
time: 2987ms
memory: 29168kb

Test #42:

score: 10
Accepted
time: 2981ms
memory: 31784kb

Test #43:

score: 10
Accepted
time: 3025ms
memory: 31740kb

Test #44:

score: 10
Accepted
time: 2988ms
memory: 30664kb

Test #45:

score: 10
Accepted
time: 2987ms
memory: 30344kb

Subtask #10:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #46:

score: 15
Accepted
time: 10285ms
memory: 29444kb

Test #47:

score: 15
Accepted
time: 10286ms
memory: 29756kb

Test #48:

score: 15
Accepted
time: 10297ms
memory: 29680kb

Test #49:

score: 15
Accepted
time: 10293ms
memory: 29468kb

Test #50:

score: 15
Accepted
time: 10232ms
memory: 30424kb