QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726652 | #8338. Quad Kingdoms Chess | beamishboys | WA | 36ms | 7688kb | C++23 | 2.4kb | 2024-11-09 05:09:19 | 2024-11-09 05:09:20 |
Judging History
answer
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
using namespace std;
using ll = long long;
const int bs = 3;
const int mn = 2e5+5;
const ll mod = 1e9+7;
mt19937_64 rng;
int vals[2][mn];
ll hashes[mn];
vector<pair<int, int>> blocks[2][mn/bs];
int n[2];
ll fix(ll n) {
return n;
}
void rebuild(int block, int o) {
int start = bs*block;
int blen = min(bs, n[o]-start);
//cout << "rebuild " << block << ' ' << o << ' ' << start << ' ' << blen << endl;
blocks[o][block].clear();
//cout << "clear" << endl;
for (int i = 0; i < blen; i++) {
int val = vals[o][i+start];
//cout << "read " << val << endl;
while (blocks[o][block].size() && val > blocks[o][block].back().first) blocks[o][block].pop_back();
//cout << "remove " << val << endl;
ll s = blocks[o][block].size() ? blocks[o][block].back().second : 0;
blocks[o][block].push_back({val, fix(hashes[val] + s)});
//cout << "push " << val << endl;
}
}
ll query(int o) {
int blockCnt = (n[o]+bs-1)/bs;
ll hi = 0;
ll out = 0;
for (int i = blockCnt-1; i >= 0; i--) {
auto ub = upper_bound(blocks[o][i].begin(), blocks[o][i].end(), pair<int, int>{ hi, -1 }, [&](auto a, auto b) { return a > b; });
//for (auto [p, q] : blocks[o][i]) cout << p << ' ' << q << endl;
//cout << endl;
if (ub == blocks[o][i].begin()) continue;
//cout << i << endl;
ub = prev(ub);
out = fix(out+ub->second);
hi = blocks[o][i][0].first;
//cout << out << ' ' << hi << endl;
}
//cout << endl;
return out;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i < mn; i++) hashes[i] = rng()%mod;
for (int i = 0; i < 2; i++) {
cin >> n[i];
for (int j = 0; j < n[i]; j++) cin >> vals[i][j];
for (int j = 0; j*bs < n[i]; j++) rebuild(j, i);
}
int q; cin >> q;
for (int i = 0; i < q; i++) {
int o; cin >> o;
o--;
int x; cin >> x;
x--;
int y; cin >> y;
vals[o][x] = y;
rebuild(x/bs, o);
//cout << query(0) << ' ' << query(1) << endl;
/*for (int j = 0; j < n[o]; j++) cout << vals[o][j] << ' ';
cout << endl;
for (int u = 0; u < 2; u++) {
for (int j = 0; j*bs < n[u]; j++) {
cout << "block " << j << endl;
for (auto [p, q] : blocks[u][j]) cout << p << ' ' << q << " - ";
cout << endl;
}
cout << endl;
query(u);
}*/
if (query(0) == query(1)) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5832kb
input:
5 1 2 3 4 5 5 5 4 3 2 1 8 1 1 5 1 4 2 1 2 4 1 5 1 1 5 5 2 1 4 2 3 5 2 5 5
output:
NO NO NO YES NO NO NO YES
result:
ok 8 tokens
Test #2:
score: 0
Accepted
time: 29ms
memory: 5620kb
input:
1 2 6 2 1 1 1 1 1 200000 2 6 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 4 1 2 1 2 1 1 1 1 1 2 2 5 1 1 1 1 1 1 2 1 1 1 2 6 1 1 1 2 1 1 2 1 1 2 2 3 1 1 1 1 2 1 1 2 6 2 1 1 2 2 4 1 1 1 2 2 6 1 1 1 2 1 1 1 2 5 2 2 6 2 1 1 1 2 4 2 2 5 2 2 6 2 1 1 1 2 5 1 2 6 2 1 1 2 1 1 1 1 1 1 2 4 1 1 1 2 1 1 2 1 1 2 2 3 2...
output:
NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO N...
result:
ok 200000 tokens
Test #3:
score: 0
Accepted
time: 25ms
memory: 5832kb
input:
6 2 1 1 2 1 2 1 1 200000 2 1 1 1 1 2 1 1 1 2 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 1 2 1 3 1 1 6 2 1 5 2 1 4 2 1 3 1 2 1 2 1 4 2 1 4 2 2 1 2 2 1 2 1 3 1 1 6 1 1 1 2 2 1 1 1 6 1 1 3 1 1 5 2 1 6 2 1 5 2 2 1 2 1 2 1 1 5 2 2 1 1 2 1 1 1 6 1 2 1 2 2 1 1 1 3 2 2 1 1 1 6 1 1 4 2 1 2 1 1 1 1 2 1 1 1 2 1 1 6 2 1 6 2...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 200000 tokens
Test #4:
score: -100
Wrong Answer
time: 36ms
memory: 7688kb
input:
6 1 3 1 2 1 2 6 2 1 3 3 3 1 200000 2 4 2 1 2 1 1 6 2 2 3 2 1 1 1 1 6 2 1 6 2 1 3 2 2 6 1 2 4 3 1 1 2 2 5 2 2 6 2 2 3 1 1 4 3 1 3 1 2 5 2 2 4 2 2 1 3 1 1 1 2 2 2 2 4 2 1 5 3 1 6 3 2 6 3 1 5 3 2 5 3 2 4 1 2 4 2 1 1 2 1 6 1 2 6 1 1 2 3 1 1 3 1 1 1 2 6 3 2 4 1 1 4 2 2 2 1 1 3 1 1 1 3 1 1 3 1 4 3 1 3 3 2...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
wrong answer 27th words differ - expected: 'YES', found: 'NO'