D WA *15 求条
  • 板块灌水区
  • 楼主littlebug
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/21 21:39
  • 上次更新2024/12/22 09:38:54
查看原帖
D WA *15 求条
541634
littlebug楼主2024/12/21 21:39

rt,写了半天 D WA 了之后去开 E,发现 E 这么水(恼

但是 D 确实不知道为啥 WA 了

思路:先处理出走过的每行和每列,然后分别计算走过的房子数。留意需要去重了。

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>

#define int long long
#define il inline
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rpe(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair <int,int>
#define st first
#define nd second
#define mp make_pair
#define pb emplace_back
#define all(x) (x).begin(),(x).end()
template <typename T> il void clr(T &x) {T().swap(x);}

using namespace std;

const int MAXN=2e5+5;
int n,m,sx,sy,b[MAXN];
char a[MAXN];
map <int,vector<int>> p,q;
struct line{int y,l,r;}; vector <line> lin;
struct column{int x,l,r;}; vector <column> col;

signed main()
{
    //freopen(".in","r",stdin),freopen(".out","w",stdout);
    //ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(nullptr),cout.tie(nullptr);

    cin>>n>>m>>sx>>sy;
    {int x,y; rep(i,1,n) cin>>x>>y,p[y].pb(x);}
    rep(i,1,m) cin>>a[i]>>b[i];

    for(auto i=p.begin();i!=p.end();++i) sort(all(i->nd));
    //for(auto i:p) {cerr<<"qwq "<<i.st<<" : ";for(auto j:i.nd)cerr<<j<<' ';cerr<<'\n';}

    char op; int d,x=sx,y=sy,lx=sx,ly=sy,ans=0;
    rep(i,1,m)
    {
        op=a[i],d=b[i];
        switch(op)
        {
            case 'U': y+=d,col.pb((column){x,min(ly,y),max(ly,y)}); break;
            case 'D': y-=d,col.pb((column){x,min(ly,y),max(ly,y)}); break;
            case 'L': x-=d,lin.pb((line){y,min(lx,x),max(lx,x)}); break;
            case 'R': x+=d,lin.pb((line){y,min(lx,x),max(lx,x)}); break;
        }

        lx=x,ly=y;
    }

    cout<<x<<' '<<y<<' ';

    int l,r;
    for(auto qwq:lin)
    {
        y=qwq.y,l=qwq.l,r=qwq.r;
        if(p.count(y))
        {
            auto bg=lower_bound(all(p[y]),l),ed=upper_bound(all(p[y]),r);
            ans+=ed-bg;
            //cerr<<"y : "<<y<<' '<<ed-bg<<'\n';
            p[y].erase(bg,ed);
        }
    }
    
    //for(auto i:p) {cerr<<"quq "<<i.st<<" : ";for(auto j:i.nd)cerr<<j<<' ';cerr<<'\n';}

    //cerr<<ans<<'\n';
    
    for(auto i:p)
    {
        y=i.st;
        for(auto j:i.nd) x=j,q[x].pb(y);
    }
    for(auto i=q.begin();i!=q.end();++i) sort(all(i->nd));
    //for(auto i:q) {cerr<<"qaq "<<i.st<<" : ";for(auto j:i.nd)cerr<<j<<' ';cerr<<'\n';}
    
    for(auto qwq:col)
    {
        x=qwq.x,l=qwq.l,r=qwq.r;
        if(q.count(x))
        {
            auto bg=lower_bound(all(q[x]),l),ed=upper_bound(all(q[x]),r);
            ans+=ed-bg;
            //p[x].erase(bg,ed);
            //cerr<<"x : "<<x<<" | "<<"l="<<l<<",r="<<r<<" | "<<ed-bg<<'\n';
        }
    }

    cout<<ans;

    return 0;
}
2024/12/21 21:39
加载中...