답안 #1088993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088993 2024-09-15T17:40:23 Z modwwe 새 집 (APIO18_new_home) C++17
0 / 100
4418 ms 235904 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while(c<'0'||c>'9')
    {
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf=1e9;
const int mod2=1e9+9;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2,center;
int  i,s10,s12;
int kk;
int el=19;
main()
{
#ifndef ONLINE_JUDGE
   // fin(task);
   //  fou(task);
#endif
    NHP
    /// cin>>s1;
///modwwe
    phongbeo();
    checktime
}
vector<ic> v[900001];
vector<int> v2,v3;
map<int,int>cnt[300001];
set<int> s[300001];
vector<ib> ask[900001];
id a[300001];
int ans[300001];
ib b[300001];
struct IT
{
    int bit[300001];
    void upd(int x,int y)
    {
        for(x; x; x-=x&-x)
            bit[x]+=y;
    }
    int get(int x)
    {
        int s=0;
        for(x; x<=n; x+=x&-x) s+=bit[x];
        return s;
    }
    int gett(int x,int y)
    {
        return get(x)-get(y+1);
    }
} st;
struct BIT2D
{
    vector<int>bit[300001];
    vector<int> bit2[300001];

    void fakeupd(int x,int y)
    {
        for(x; x; x-=x&-x)
            bit[x].pb(y);
    }
    void setup()
    {
        for(int i=1; i<=n; i++)
        {
            if(bit[i].size()!=0)
            {
                sort(bit[i].begin(),bit[i].end());
                bit[i].erase(unique(bit[i].begin(), bit[i].end()), bit[i].end());
                bit2[i].assign(bit[i].size()+1,0);
            }
        }
    }
    void upd(int x,int y,int z)
    {
        for(x; x; x-=x&-x)
            if(bit[x].size()!=0)
                for(int y2=upper_bound(bit[x].begin(),bit[x].end(),y)-bit[x].begin(); y2<=bit[x].size(); y2+=y2&-y2)
                    bit2[x][y2]+=z;
    }
    int get(int x,int y)
    {
        int s=0;
        for(x; x<=n; x+=x&-x)
            if(bit[x].size()!=0)
                for(int y2=upper_bound(bit[x].begin(),bit[x].end(),y)-bit[x].begin(); y2; y2-=y2&-y2)
                    s+=bit2[x][y2];
        return s;
    }
} fen;
void fake_add(int x,int y)
{
    auto it=s[y].lower_bound(x);
    if(it!=s[y].end()) fen.fakeupd(x,*it);

    if(it!=s[y].begin())
    {
        it--;
        auto it2=it;
        fen.fakeupd(*it2,x);
    }
    if(cnt[y][x]==0)
        s[y].insert(x);
    cnt[y][x]++;
}
void fake_del(int x,int y)
{
    cnt[y][x]--;

    if(cnt[y][x]==0)
    {
        s[y].erase(x);
        auto it=s[y].lower_bound(x);
        s2=-1;
        if(it!=s[y].end()) s2=*it;
        if(it!=s[y].begin())
        {
            it--;
            auto it2=it;
            if(s2!=-1)
                fen.fakeupd(*it2,s2);
        }
    }
}
void add(int x,int y)
{
    auto it=s[y].lower_bound(x);
    s2=-1;
    st.upd(x,1);
    if(it!=s[y].end()) fen.upd(x,*it,1),s2=*it;
    if(it!=s[y].begin())
    {
        it--;
        auto it2=it;
        fen.upd(*it2,x,1);
        if(s2!=-1)
            fen.upd(*it2,s2,-1);
    }
    if(cnt[y][x]==0)
        s[y].insert(x),dem++;
    cnt[y][x]++;
}
void del(int x,int y)
{
    cnt[y][x]--;
    st.upd(x,-1);
    if(cnt[y][x]==0)
    {
        s[y].erase(x);
        if(s[y].size()==0) dem--;
        auto it=s[y].lower_bound(x);
        s2=-1;
        if(it!=s[y].end()) fen.upd(x,*it,-1),s2=*it;
        if(it!=s[y].begin())
        {

            it--;
            auto it2=it;
            fen.upd(*it2,x,-1);

            if(s2!=-1)
                fen.upd(*it2,s2,1);

        }
    }
    else
    {
        fen.upd(x,x,-1);
    }
}

int get(int x)
{
    l=0;
    r=1e8;
    while(l<=r)
    {
        int mid=l+r>>1;
        int y=mid;
        s2=lower_bound(v2.begin(),v2.end(),x-y)-v2.begin()+1;
        s3=upper_bound(v2.begin(),v2.end(),x+y)-v2.begin();
        if(st.gett(s2,s3)-fen.get(s2,s3)>=k)
        {
            s5=max({x-v2[s2-1],v2[s3-1]-x});
            r=s5-1;
        }
        else
        {
            if(s2==1&&s3==v2.size()) return 1e8+1;
            s5=1e8+1;
            if(s2!=1) s5=min(s5,abs(x-v2[s2-2]));
            if(s3!=v2.size())s5=min(s5,abs(x-v2[s3]));
            l=s5;
        }
    }
    return r+1;
}
void phongbeo()
{
    n=scan();
    k=scan();
    m=scan();
    for(int i=1; i<=n; i++)
        l=scan(),r=scan(),s2=scan(),s3=scan(),a[i]= {l,r,s2,s3},v3.pb(s2),v3.pb(s3+1),v2.pb(l);
    for(int i=1; i<=m; i++)
        l=scan(),r=scan(),b[i]= {l,r},v3.pb(r);
    sort(v2.begin(),v2.end());
    v2.erase(unique(v2.begin(), v2.end()), v2.end());
    sort(v3.begin(),v3.end());
    v3.erase(unique(v3.begin(), v3.end()), v3.end());
    for(int i=1; i<=n; i++)
    {
        s2=lower_bound(v3.begin(),v3.end(),a[i].c)-v3.begin()+1;
        s3=lower_bound(v3.begin(),v3.end(),a[i].d+1)-v3.begin()+1;
        l=lower_bound(v2.begin(),v2.end(),a[i].a)-v2.begin()+1;
        r=a[i].b;
        v[s2].pb({l,r,1}),v[s3].pb({l,r,-1});
    }
    for(int i=1; i<=m; i++)
    {
        l=b[i].a;
        r=b[i].b;
        r=lower_bound(v3.begin(),v3.end(),r)-v3.begin()+1;
        ask[r].pb({l,i});
    }
    for(int i=1; i<=v3.size(); i++)
    {
        for(auto f:v[i])
            if(f.c==1)
                fake_add(f.a,f.b);
            else
                fake_del(f.a,f.b);
    }
    fen.setup();
    for(int i=1; i<=v3.size(); i++)
    {
        for(auto f:v[i])
            if(f.c==1) cnt[f.b][f.a]=0;
    }
    for(int i=1; i<=m; i++)
        s[i].clear();
    for(int i=1; i<=v3.size(); i++)
    {
        for(auto f:v[i])
        {
            if(f.c==1)
            {
                add(f.a,f.b);
            }
            else
                del(f.a,f.b);
        }
        for(auto f:ask[i])
        {
             if(dem==k)
            ans[f.b]=get(f.a);
            else ans[f.b]=-1;
        }

    }
    for(int i=1; i<=m; i++)
    {
        if(ans[i]==1e8+1)
            cout<<-1;
        else cout<<ans[i];
        down
    }

}

Compilation message

new_home.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
new_home.cpp: In member function 'void IT::upd(int, int)':
new_home.cpp:92:13: warning: statement has no effect [-Wunused-value]
   92 |         for(x; x; x-=x&-x)
      |             ^
new_home.cpp: In member function 'int IT::get(int)':
new_home.cpp:98:13: warning: statement has no effect [-Wunused-value]
   98 |         for(x; x<=n; x+=x&-x) s+=bit[x];
      |             ^
new_home.cpp: In member function 'void BIT2D::fakeupd(int, int)':
new_home.cpp:113:13: warning: statement has no effect [-Wunused-value]
  113 |         for(x; x; x-=x&-x)
      |             ^
new_home.cpp: In member function 'void BIT2D::upd(int, int, int)':
new_home.cpp:130:13: warning: statement has no effect [-Wunused-value]
  130 |         for(x; x; x-=x&-x)
      |             ^
new_home.cpp:132:89: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |                 for(int y2=upper_bound(bit[x].begin(),bit[x].end(),y)-bit[x].begin(); y2<=bit[x].size(); y2+=y2&-y2)
      |                                                                                       ~~^~~~~~~~~~~~~~~
new_home.cpp: In member function 'int BIT2D::get(int, int)':
new_home.cpp:138:13: warning: statement has no effect [-Wunused-value]
  138 |         for(x; x<=n; x+=x&-x)
      |             ^
new_home.cpp: In function 'int get(int)':
new_home.cpp:232:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  232 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp:243:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  243 |             if(s2==1&&s3==v2.size()) return 1e8+1;
      |                       ~~^~~~~~~~~~~
new_home.cpp:246:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  246 |             if(s3!=v2.size())s5=min(s5,abs(x-v2[s3]));
      |                ~~^~~~~~~~~~~
new_home.cpp: In function 'void phongbeo()':
new_home.cpp:280:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  280 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:289:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  289 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:296:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  296 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 84812 KB Output is correct
2 Correct 42 ms 84828 KB Output is correct
3 Correct 40 ms 85008 KB Output is correct
4 Incorrect 40 ms 84984 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 84812 KB Output is correct
2 Correct 42 ms 84828 KB Output is correct
3 Correct 40 ms 85008 KB Output is correct
4 Incorrect 40 ms 84984 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2291 ms 204800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4418 ms 235904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 84812 KB Output is correct
2 Correct 42 ms 84828 KB Output is correct
3 Correct 40 ms 85008 KB Output is correct
4 Incorrect 40 ms 84984 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 84812 KB Output is correct
2 Correct 42 ms 84828 KB Output is correct
3 Correct 40 ms 85008 KB Output is correct
4 Incorrect 40 ms 84984 KB Output isn't correct
5 Halted 0 ms 0 KB -