QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419785 | #6533. Traveling in Cells | XiaoretaW | WA | 128ms | 3616kb | C++20 | 3.7kb | 2024-05-24 11:15:10 | 2024-05-24 11:15:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, l, r) for (int i = l; i < r; ++i)
#define per(i, r, l) for (int i = r-1; i >= l; --i)
typedef long long ll;
typedef pair<int, int> PI;
template<typename T> bool setmax(T &a, T b) { return (a < b ? a = b, 1 : 0); }
template<typename T> bool setmin(T &a, T b) { return (a > b ? a = b, 1 : 0); }
// // 比 unordered_map 更快的哈希表
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash {
// int operator()(int x) const { return x ^ RANDOM; }
// };
// typedef gp_hash_table<int, int, chash> hash_t;
template<typename T> struct BIT {
int n;
vector<T> tr;
BIT(int _n) {
n = _n;
tr.resize(n+1);
}
T prefix(int i) {
T res = 0;
for (; i; i -= i&(-i)) res += tr[i];
return res;
}
T query(int l, int r) { return prefix(r) - prefix(l-1); }
void modify(int i, T val) { for (; i <= n; i += i&(-i)) tr[i] += val; }
};
// const int N = 300010;
// hash_t bitc[N];
// void modify(int c, int p, int val) {
// }
void solve() {
int n, q; cin >> n >> q;
vector<int> c(n + 1), v(n + 1);
vector<BIT<int>> cbit(n + 1, BIT<int>(n));
BIT<int> vbit(n);
for (int i = 1; i <= n; i++) {
cin >> c[i];
cbit[c[i]].modify(i, 1);
}
for (int i = 1; i <= n; i++) {
cin >> v[i];
vbit.modify(i, v[i]);
}
while (q--) {
int t; cin >> t;
if (t == 1 || t == 2) {
int p, x; cin >> p >> x;
if (t == 1) {
cbit[c[p]].modify(p, -1);
c[p] = x;
cbit[c[p]].modify(p, 1);
} else {
vbit.modify(p, -v[p]);
v[p] = x;
vbit.modify(p, v[p]);
}
} else {
int x, k; cin >> x >> k;
vector<int> st(k);
for (int &i : st) cin >> i;
auto gao1 = [&]() {
auto ck1 = [&](int m) {
int tot = 0;
for (int color : st) {
// len = m
// [x - m + 1, x];
tot += cbit[color].query(x - m + 1, x);
}
assert(tot <= m);
return tot == m;
};
int l = 1, r = x;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (ck1(mid)) l = mid;
else r = mid - 1;
}
return l;
};
auto gao2 = [&]() {
auto ck2 = [&](int m) {
int tot = 0;
for (int color : st) {
tot += cbit[color].query(x, x + m - 1);
}
assert(tot <= m);
return tot == m;
};
int l = 1, r = n - x + 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (ck2(mid)) l = mid;
else r = mid - 1;
}
return l;
};
int L = x - gao1() + 1, R = x + gao2() - 1;
cout << vbit.query(L, R) << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int tt; cin >> tt;
while (tt--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
2 5 10 1 2 3 1 2 1 10 100 1000 10000 3 3 1 3 3 3 2 2 3 2 5 20000 2 3 200 3 3 2 1 3 3 3 3 1 2 3 1 3 4 2 1 100000 1 2 2 3 1 2 1 2 4 1 1 2 3 4 1000000 1000000 1000000 1000000 3 4 4 1 2 3 4
output:
100 110 1200 21211 100010 4000000
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 128ms
memory: 3616kb
input:
20000 15 15 1 1 3 3 2 3 3 3 3 3 2 3 2 3 3 634593973 158136379 707704004 998369647 831633445 263092797 937841412 451774682 552617416 483763379 50360475 794662797 74247465 537217773 901809831 3 6 4 1 3 5 10 3 5 7 1 2 3 4 5 9 10 3 4 3 3 8 9 2 13 608033129 3 15 2 3 5 1 9 3 3 8 4 1 3 7 10 2 6 727472865 3...
output:
-1605877610 -212109117 1706073651 1439027604 -1605877610 792730352 314932489 314932489 -319661484 831633445 692051585 -1512534670 697783016 883944422 184057757 287523250 184057757 696388752 184057757 1675459344 -1627274271 -1680256038 -287974923 1767091974 1053573761 1053573761 390631780 -2004751044...
result:
wrong answer 1st numbers differ - expected: '2689089686', found: '-1605877610'