QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734966 | #7105. Pixel Art | mana | WA | 330ms | 17668kb | C++20 | 2.4kb | 2024-11-11 16:19:09 | 2024-11-11 16:19:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = int;
i64 n, m, k, summ, ans;
i64 res[100005][2], pre[100005], fa[100005], g[100005][4];
vector<i64> v[100005];vector<i64> e[100005];//分别存加入和删除
set<array<i64, 3>> st;
int find(int x){//查询父节点
while (x != fa[x]) x = fa[x] = fa[fa[x]];
return x;
}
bool merge(int x, int y){//合并 x 和 y 所在并查集
x = find(x), y = find(y);
if (x == y) return false;
ans--;
fa[y] = x;
return true;
}
void init(){
st.clear();
summ = ans = 0;
g[0][0] = g[0][1] = g[0][2] = g[0][3] = -1;
for(int i = 0; i <= n + 1; i++){
pre[i] = res[i][0] = res[i][1] = 0;
v[i].clear();
e[i].clear();
}
for(int i = 0; i <= k + 1; i++){
fa[i] = i;
}
}
void solve(){
i64 temp, sub, x, y;
cin >> n >> m >> k;
init();
for (int i = 1; i <= k; i++){
cin >> g[i][0] >> g[i][1] >> g[i][2] >> g[i][3];
if(g[i][0] == g[i][2]){//横边
res[g[i][0]][0] += g[i][3] - g[i][1] + 1;
}
else{//竖边
pre[g[i][0]]++;
pre[g[i][2]+1]--;
}
v[g[i][0]].push_back(i);
e[g[i][2] + 1].push_back(i);
}
for(int i = 1; i <= n; i++){//统计答案s
summ += pre[i];
res[i][0] += summ;
res[i][0] += res[i-1][0];
}
for(int i = 1; i <= n; i++){
for(auto x : v[i]){
auto it = st.lower_bound({g[x][1],0,0});
if(it != st.begin()){
--it;
}
while(it != st.end() && (*it)[0] <= g[x][3]){
if((*it)[1] >= g[x][1]){
merge((*it)[2], x);
it++;
}
else{
break;
}
}
}
for(auto x : e[i]){
st.erase({g[x][1],g[x][3],x});
}
for(auto x : v[i]){
ans++;
auto it = st.insert({g[x][1],g[x][3],x}).first;
auto it1 = it;
if(it != st.begin()){
it1 = prev(it);
if((*it1)[1] == (g[x][1] - 1)){
merge((*it1)[2], x);
}
}
auto it2 = next(it);
if(it2 != st.end()){
if((*it2)[0] == (g[x][3] + 1)){
merge((*it2)[2], x);
}
}
}
res[i][1] = ans;
cout << res[i][0] << ' ' << res[i][1] << '\n';
}
return;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
long long tt = 1;
cin >> tt;
while(tt--){solve();}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7764kb
input:
3 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2
result:
ok 7 lines
Test #2:
score: -100
Wrong Answer
time: 330ms
memory: 17668kb
input:
2130 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3 3 100 51 1 2 2 2 1 4 2 4 1 6 2 6 1 8 2 8 1 10 2 10 1 12 2 12 1 14 2 14 1 16 2 16 1 18 2 18 1 20 2 20 1 22 2 22 1 24 2 24 1 26 2 26 1 28 2 28 1 30 2 30 1 32 2 32 1 34 2 34 1 36 2 36 1 38 2 38 1 40 2 40 1 42 2 42 1 44 2 44 ...
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2 50 50 100 50 200 1 50 50 150 1 200 1 2 1 4 1 6 1 8 1 10 1 12 1 14 1 16 1 18 1 20 1 22 1 24 1 26 1 28 1 30 1 32 1 34 1 36 1 38 1 40 1 42 1 44 1 46 1 48 1 50 1 52 1 54 1 56 1 58 1 60 1 62 1 64 1 66 1 68 1 70 1 72 1 74 1 76 1 78 1 80 1 82 1 84 1 86 1 88 1 90 1 92 1 94 1 96 1...
result:
wrong answer 10129th lines differ - expected: '6 2', found: '6 3'