QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645167 | #7926. Color Inversion on a Huge Chessboard | AFLeartLey0103# | WA | 91ms | 28612kb | C++14 | 2.5kb | 2024-10-16 17:08:02 | 2024-10-16 17:08:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 5e5+50;
int n, q;
class obj{
public:
mutable int l, r;
int color;
friend bool operator<(obj a, obj b){ return a.r < b.r; }
};
int col[maxn], row[maxn];
set<obj> scol, srow;
void edit_col(int u){
auto it = scol.lower_bound({0, u});
int l = it->l, r = it->r, color = it->color;
if(l == r){
auto lit = it, rit = it;
if(l != 1) lit--; if(r != n) rit++;
int _l = lit->l, _r = rit->r;
if(l != 1) scol.erase(lit); if(r != n) scol.erase(rit);
scol.erase(it);
scol.insert({_l, _r, color^1});
}
else if(l == u){
if(l == 1) {
it->l++; scol.insert({u, u, color^1});
}
else{
auto lit = it; lit--;
it->l++, lit->r++;
}
}
else if(r == u){
if(r == n) {
it->r--; scol.insert({u, u, color^1});
}
else{
auto rit = it; rit++;
it->r++, rit->l++;
}
}
else{
scol.erase(it);
scol.insert({l, u-1, color^1});
scol.insert({u+1, r, color^1});
scol.insert({u, u, color});
}
}
void edit_row(int u){
auto it = srow.lower_bound({0, u});
int l = it->l, r = it->r, color = it->color;
if(l == r){
auto lit = it, rit = it;
if(l != 1) lit--; if(r != n) rit++;
int _l = lit->l, _r = rit->r;
if(l != 1) srow.erase(lit); if(r != n) srow.erase(rit);
srow.erase(it);
srow.insert({_l, _r, color^1});
}
else if(l == u){
if(l == 1) {
it->l++;
srow.insert({u, u, color^1});
}
else{
auto lit = it; lit--;
it->l++, lit->r++;
}
}
else if(r == u){
if(r == n) {
it->r--;
srow.insert({u, u, color^1});
}
else{
auto rit = it; rit++;
it->r++, rit->l++;
}
}
else{
srow.erase(it);
srow.insert({l, u-1, color^1});
srow.insert({u+1, r, color^1});
srow.insert({u, u, color});
}
}
signed main(){
cin >> n >> q;
for(int i = 1, id = 0; i <= n; ++ i, id ^= 1){
scol.insert({i,i,id}); srow.insert({i,i,id});
}
while(q--){
string s; cin >> s;
int u; cin >> u;
if(s[0] == 'R'){
edit_row(u);
}
else {
edit_col(u);
}/*
for(auto i:scol) cerr << i.l << ' ' << i.r << ' ' << i.color << '\n';
for(auto i:scol) cerr << i.l << ' ' << i.r << ' ' << i.color << '\n';
cerr << "ans:";*/
cout << scol.size() * srow.size() << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
3 3 ROW 2 COLUMN 3 ROW 2
output:
3 2 6
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 91ms
memory: 28612kb
input:
200000 2 ROW 1 ROW 1
output:
39999800000 40000000000
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 1 COLUMN 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
1 100 COLUMN 1 COLUMN 1 ROW 1 ROW 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 COLUMN 1 ROW 1 COLUMN 1 ROW 1 COLUMN 1 COL...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
2 100 COLUMN 2 ROW 1 COLUMN 2 COLUMN 2 ROW 2 ROW 1 COLUMN 1 COLUMN 1 COLUMN 1 ROW 1 ROW 1 ROW 1 COLUMN 1 ROW 2 COLUMN 1 COLUMN 2 COLUMN 1 ROW 1 ROW 2 ROW 1 COLUMN 2 ROW 2 ROW 2 COLUMN 2 COLUMN 1 ROW 2 COLUMN 2 ROW 1 ROW 2 ROW 1 ROW 1 COLUMN 2 COLUMN 2 COLUMN 2 COLUMN 2 ROW 2 ROW 1 ROW 1 COLUMN 1 ROW...
output:
2 1 2 1 2 1 2 1 2 4 2 4 2 1 2 1 2 4 2 4 2 1 2 4 2 1 2 4 2 4 2 1 2 1 2 4 2 4 2 1 2 1 2 1 2 4 2 4 2 4 2 4 2 4 2 1 2 1 2 1 2 4 2 1 2 4 2 4 2 1 2 1 2 4 2 1 2 4 2 1 2 4 2 1 2 4 2 4 2 1 2 4 2 1 2 4 2 4 2 4
result:
ok 100 lines
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3576kb
input:
3 100 ROW 1 ROW 1 COLUMN 3 ROW 3 ROW 2 COLUMN 2 ROW 3 COLUMN 3 COLUMN 2 COLUMN 1 ROW 3 ROW 2 ROW 2 COLUMN 3 ROW 3 COLUMN 2 COLUMN 2 ROW 2 COLUMN 3 COLUMN 1 COLUMN 2 COLUMN 2 ROW 1 ROW 1 COLUMN 3 ROW 2 COLUMN 2 COLUMN 3 ROW 3 COLUMN 1 ROW 3 COLUMN 2 COLUMN 1 ROW 3 ROW 3 COLUMN 2 COLUMN 2 COLUMN 1 ROW...
output:
6 9 6 4 4 4 2 1 3 2 4 4 6 3 4 12 4 2 4 6 2 6 9 6 4 4 4 2 2 4 6 6 9 6 9 3 9 6 8 4 2 4 4 6 6 9 6 6 9 12 6 4 2 4 4 4 4 6 9 6 9 12 8 8 8 4 6 9 6 4 2 3 6 9 12 8 4 2 4 4 4 6 2 6 9 6 2 4 3 6 4 6 4 2 3 6 9 12 9 6
result:
wrong answer 13th lines differ - expected: '4', found: '6'