CF 1980 F1 Field Division (easy version) (*1900)
CF 1980 F1 Field Division (easy version) (*1900)
题意:
有一个大小为
思路:
显然,我们每次都贴着喷泉去走,面积才会最大。我们可以把面积根据喷泉的位置划分成一段一段来求解。
容易发现只有后面的喷泉的横坐标大于前面的横坐标才会拐弯。那么我们可以维护每一列的最大横坐标。
按照纵坐标顺序枚举所有喷泉的纵坐标计算即可。因为范围很大,那么用map维护即可。
接着看第二个问题,我们发现只有满足当前喷泉的横坐标是当前列的横坐标最大值并且大于前一个喷泉对应的
最大横坐标即可。这里开了一个st数组来维护前一个喷泉对应的最大横坐标。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(u) u.begin(), u.end()
#define endl '\n'
#define debug(x) cout<<#x<<":"<<x<<endl;
typedef pair<int, int> PII;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10, M = 105;
const int mod = 1e9 + 7;
const int cases = 1;
void Showball(){
int n,m,k;
cin>>n>>m>>k;
vector<PII> a(k+1);
map<int,int> rmax;
vector<int> col;
for(int i=1;i<=k;i++){
int x,y;
cin>>x>>y;
a[i]={x,y};
col.pb(y);
rmax[y]=max(rmax[y],x);
}
sort(all(col));
int len=unique(all(col))-col.begin();
LL ans=0;
int cur=0;
map<int,int> st;
int pre=1;
for(int i=0;i<len;i++){
int y=col[i];
ans+=1LL*(y-pre)*(n-cur);
st[y]=cur;
cur=max(cur,rmax[y]);
pre=y;
}
ans+=1LL*(m-pre+1)*(n-cur);
cout<<ans<<endl;
for(int i=1;i<=k;i++){
auto [x,y]=a[i];
if(x==rmax[y]&&x>st[y]) cout<<"1 ";
else cout<<"0 ";
}
cout<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T=1;
if(cases) cin>>T;
while(T--)
Showball();
return 0;
}
分类:
算法竞赛
标签:
CF板刷(1600-1900)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验