QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500441 | #7463. y-fast trie | Xiaohuba | 10 | 73ms | 9284kb | C++23 | 3.9kb | 2024-08-01 11:52:05 | 2024-08-01 11:52:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define LOCK_GETCHAR
// #define USE_INT_128
#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif
#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif
#define il inline
#define mkp make_pair
#define fi first
#define se second
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k) \
for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename) \
freopen(filename ".in", "r", stdin); \
freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif
// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on
// File head end
namespace {
constexpr ll MAXN = 5e5 + 5;
int n, C, lst = 0;
map<int, int> mp;
multiset<int> pool, match;
il void Main() {
read(n, C);
while (n--) {
int op, x;
read(op, x), x ^= lst;
if (op == 1) {
x %= C;
auto it = pool.upper_bound(C - x - 1);
if (it != pool.begin()) {
int y = *prev(it);
if (!mp.count(y)) {
mp[y] = x, mp[x] = y;
match.emplace(x + y);
} else if (mp[y] + y < x + y) {
match.erase(match.find(y + mp[y]));
mp.erase(mp[y]);
mp[y] = x, mp[x] = y;
match.emplace(x + y);
}
}
pool.emplace(x);
} else {
x %= C;
pool.erase(pool.find(x));
if (mp.count(x)) {
int y = mp[x];
mp.erase(x), match.erase(match.find(x + y));
auto it = pool.lower_bound(C - 1 - y);
if (it != pool.begin()) {
int z = *prev(it);
if (!mp.count(z)) {
mp[y] = z, mp[z] = y, match.emplace(y + z);
} else if (mp[z] + z < y + z) {
match.erase(match.find(mp[z] + z));
mp.erase(mp[z]);
mp[y] = z, mp[z] = y, match.emplace(y + z);
}
}
}
}
if (pool.size() < 2)
cout << "EE\n", lst = 0;
else {
auto it = --pool.end();
lst = (*prev(it) + *it) % C;
if (!match.empty())
cmax(lst, *--match.end());
cout << lst << '\n';
}
}
}
} // namespace
signed main() { return Main(), 0; }
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 3572kb
input:
7 9 1 2 1 3 1 0 1 14 2 14 2 13 1 1
output:
EE 5 8 8 8 5 7
result:
ok 7 lines
Subtask #2:
score: 9
Accepted
Test #2:
score: 9
Accepted
time: 0ms
memory: 3700kb
input:
1 14514 1 919810
output:
EE
result:
ok single line: 'EE'
Subtask #3:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #3:
score: 0
Runtime Error
input:
500 220272175 1 80468911 1 374715656 1 650827856 1 7251764 1 157269409 1 366819034 1 140735482 1 697504163 1 580976911 1 260541431 1 177420127 1 143366977 1 131630540 1 8608588 1 146296849 2 190433980 2 143366977 1 335589270 1 692591740 1 8739082 1 805227819 1 732996602 2 585274048 1 250142592 1 382...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #8:
score: 19
Accepted
time: 73ms
memory: 9284kb
input:
100000 12857 1 414055374 1 152349753 1 1103688 1 145350958 1 27448470 1 19646236 1 45006304 1 683004750 1 528225274 1 29635645 1 532397907 1 112630487 1 512377610 1 687365005 1 28369804 1 4032175 1 58622664 1 102365588 1 121463552 1 639691984 1 226589268 1 416004496 1 22148247 1 101368844 1 42815922...
output:
EE 2849 7845 9645 9645 9645 9645 10747 12324 12324 12324 12455 12455 12455 12455 12455 12455 12455 12455 12777 12777 12777 12777 12777 12808 12808 12808 12843 12843 12843 12852 12852 12852 12852 12852 12852 12852 12852 12852 12852 12852 12853 12853 12853 12853 12853 12853 12853 12853 12853 12853 128...
result:
ok 100000 lines
Test #9:
score: 0
Runtime Error
input:
100000 3256 1 740810773 1 968676353 1 53739128 1 571957394 1 446452179 1 545471035 1 57549899 1 166575131 1 20445551 1 297214843 1 74831111 1 160891923 1 44348463 1 11032297 1 51468347 1 162145999 1 337957720 1 228487389 1 682661313 1 58715811 2 20445551 1 169095903 1 274045967 2 58715811 1 29499843...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%