QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283817 | #5113. Bridge | Xiaohuba | WA | 72ms | 13932kb | C++23 | 4.0kb | 2023-12-15 15:41:03 | 2023-12-15 15:41:04 |
Judging History
answer
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define INLINE_V
#define REGISTER_V register
#define CPP14CONSTEXPR
#define gcd __gcd
#define CPP14ENABLE_IF
#elif __cplusplus < 201700
#define INLINE_V
#define REGISTER_V
#define CPP14CONSTEXPR constexpr
#define gcd __gcd
#define CPP14ENABLE_IF ,enable_if_t<_is_integer<T>, int> = 0
#else
#define INLINE_V inline
#define REGISTER_V
#define CPP14CONSTEXPR constexpr
#define CPP14ENABLE_IF ,enable_if_t<_is_integer<T>, int> = 0
#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 For(i,j,k) for(REGISTER_V int i=(j);i<=(k);++i) // NOLINT
#define ForDown(i,j,k) for(REGISTER_V int i=(j);i>=(k);--i) // NOLINT
#define pb push_back
#define eb emplace_back
#define FileIO(filename) freopen(filename".in","r",stdin);freopen(filename".out","w",stdout)
using ll = long long;
// using lll = __int128_t;
using uint = unsigned int;
using ull = unsigned long long;
// using ulll = __uint128_t;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#if __cplusplus >= 201400
template <class T> INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer;
// 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_integer<bool> = false;
template <> INLINE_V constexpr bool _is_integer<char> = false;
template <class T CPP14ENABLE_IF>
INLINE_V constexpr T INF = numeric_limits<T>::max() >> 1;
#endif
template<typename T> constexpr il T sq(const T & x){return x*x;}
template<typename T> CPP14CONSTEXPR il void cmin(T & x, const T &y){x=min(x,y);}
template<typename T> CPP14CONSTEXPR il void cmax(T & x, const T &y){x=max(x,y);}
template<typename T> CPP14CONSTEXPR il T qpow(T x, ull y, T mod){T ans=1;x%=mod;while(y){if(y&1)(ans*=x)%=mod;(x*=x)%=mod;y>>=1;}return ans;}
template<typename T> CPP14CONSTEXPR il T qpow(T x, ull y){T ans=1;while(y){if(y&1)ans*=x;x*=x;y>>=1;}return ans;}
template<typename T CPP14ENABLE_IF> 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...); }
// File head end
// clang-format on
namespace {
constexpr ll MAXN = 1e5 + 5;
int B, n, m, q;
unordered_map<int, int> pool[MAXN];
pair<pii, bool> E[MAXN];
tuple<int, int, int> qry[MAXN];
map<pii, int> bl;
il void rebuild(int id) {
for (auto &[k, v] : pool[id])
v = k;
ForDown(i, (id + 1) * B - 1, id * B) {
auto cur = E[i];
if (!cur.se)
continue;
// cerr << cur.fi.se << ' ' << cur.fi.se + 1 << endl;
swap(pool[id][cur.fi.se], pool[id][cur.fi.se + 1]);
}
}
il void solver_main() {
read(n, m, q);
For(i, 1, q) {
int op, x, y = 0;
read(op, x);
if (op & 1) {
read(y);
bl.emplace(mkp(y, x), 0);
}
qry[i] = {op, x, y};
}
B = 0;
for (auto &i : bl)
i.se = ++B, E[i.se] = mkp(i.fi, 0);
B = sqrt(B);
for (auto &i : bl) {
// cerr << i.fi.se << ' ' << i.fi.fi << ' ' << i.se / B << endl;
pool[i.se / B][i.fi.se] = i.fi.se;
pool[i.se / B][i.fi.se + 1] = i.fi.se + 1;
}
For(i, 1, q) {
int op, x, y;
tie(op, x, y) = qry[i];
if (op & 1) {
E[bl[{y, x}]].se = 1;
// cerr << "rebuild " << bl[{y, x}] / B << endl;
rebuild(bl[{y, x}] / B);
} else {
For(i, 0, n / B) {
if (pool[i].count(x)) {
// cerr << x << " -> " << pool[i][x] << endl;
x = pool[i][x];
}
}
cout << x << '\n';
}
}
}
} // namespace
signed main() { return solver_main(), 0; }
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10812kb
input:
3 4 13 2 2 1 1 3 2 1 2 2 2 3 1 2 4 2 1 2 2 2 3 1 2 1 2 1 2 2 2 3
output:
2 2 1 3 3 1 2 3 2 1
result:
ok 10 numbers
Test #2:
score: -100
Wrong Answer
time: 72ms
memory: 13932kb
input:
3 100000 99997 2 2 2 2 2 3 2 3 2 3 2 3 2 3 1 2 11047 1 1 98732 1 2 90045 1 1 43556 2 1 2 3 1 2 17242 1 1 17027 2 1 1 1 94195 2 1 2 2 2 1 2 3 1 1 34124 1 2 14354 1 2 673 1 2 39812 1 2 35520 1 2 16046 2 3 2 2 1 1 25410 2 3 2 1 2 3 2 2 1 2 55684 2 1 1 2 24811 1 2 92268 1 2 60268 2 2 1 1 89272 1 2 19232...
output:
2 2 3 3 3 3 3 1 3 1 1 2 1 3 3 2 3 1 3 2 1 2 2 1 2 3 1 1 2 3 3 1 3 3 1 2 3 1 2 3 1 2 2 1 1 2 3 3 1 3 2 3 1 1 3 3 1 2 1 2 1 3 1 3 1 1 1 1 2 3 2 3 1 2 1 1 1 2 2 2 1 3 2 3 3 1 1 1 3 3 2 1 1 3 1 1 2 2 1 3 1 3 1 2 2 3 2 1 2 2 1 2 2 1 1 3 2 3 2 3 3 2 2 1 2 2 1 1 2 3 1 1 1 2 3 3 3 3 2 3 3 2 3 2 3 2 3 2 3 2 ...
result:
wrong answer 8th numbers differ - expected: '3', found: '1'