QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645118 | #7926. Color Inversion on a Huge Chessboard | AFLeartLey0103# | WA | 94ms | 28808kb | C++14 | 2.0kb | 2024-10-16 16:56:50 | 2024-10-16 16:56:50 |
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) return;
auto lit = it; lit--;
it->l++, lit->r++;
}
else if(r == u){
if(r == n) return;
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) return;
auto lit = it; lit--;
it->l++, lit->r++;
}
else if(r == u){
if(r == n) return;
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);
}
cout << scol.size() * srow.size() << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
3 3 ROW 2 COLUMN 3 ROW 2
output:
3 2 6
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 94ms
memory: 28808kb
input:
200000 2 ROW 1 ROW 1
output:
39999800000 39999800000
result:
wrong answer 2nd lines differ - expected: '40000000000', found: '39999800000'