Submission #1088991

# Submission time Handle Problem Language Result Execution time Memory
1088991 2024-09-15T17:38:03 Z modwwe New Home (APIO18_new_home) C++17
47 / 100
5000 ms 235528 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);
    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);
        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])
        {
            ans[f.b]=get(f.a);
        }

    }
    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:231:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  231 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp:242:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  242 |             if(s2==1&&s3==v2.size()) return 1e8+1;
      |                       ~~^~~~~~~~~~~
new_home.cpp:245:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  245 |             if(s3!=v2.size())s5=min(s5,abs(x-v2[s3]));
      |                ~~^~~~~~~~~~~
new_home.cpp: In function 'void phongbeo()':
new_home.cpp:279:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  279 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:288:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  288 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:295:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  295 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 41 ms 84848 KB Output is correct
2 Correct 52 ms 84824 KB Output is correct
3 Correct 42 ms 84952 KB Output is correct
4 Correct 41 ms 84964 KB Output is correct
5 Correct 42 ms 85072 KB Output is correct
6 Correct 43 ms 85080 KB Output is correct
7 Correct 41 ms 85076 KB Output is correct
8 Correct 48 ms 85076 KB Output is correct
9 Correct 43 ms 85016 KB Output is correct
10 Correct 43 ms 85076 KB Output is correct
11 Correct 42 ms 85080 KB Output is correct
12 Correct 46 ms 85072 KB Output is correct
13 Correct 47 ms 85076 KB Output is correct
14 Correct 48 ms 85080 KB Output is correct
15 Correct 48 ms 85048 KB Output is correct
16 Correct 47 ms 84952 KB Output is correct
17 Correct 49 ms 85076 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 46 ms 85076 KB Output is correct
20 Correct 47 ms 84956 KB Output is correct
21 Correct 44 ms 85076 KB Output is correct
22 Correct 47 ms 84996 KB Output is correct
23 Correct 45 ms 85108 KB Output is correct
24 Correct 46 ms 85076 KB Output is correct
25 Correct 55 ms 85076 KB Output is correct
26 Correct 47 ms 85076 KB Output is correct
27 Correct 46 ms 85072 KB Output is correct
28 Correct 45 ms 85072 KB Output is correct
29 Correct 53 ms 84904 KB Output is correct
30 Correct 49 ms 85040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 84848 KB Output is correct
2 Correct 52 ms 84824 KB Output is correct
3 Correct 42 ms 84952 KB Output is correct
4 Correct 41 ms 84964 KB Output is correct
5 Correct 42 ms 85072 KB Output is correct
6 Correct 43 ms 85080 KB Output is correct
7 Correct 41 ms 85076 KB Output is correct
8 Correct 48 ms 85076 KB Output is correct
9 Correct 43 ms 85016 KB Output is correct
10 Correct 43 ms 85076 KB Output is correct
11 Correct 42 ms 85080 KB Output is correct
12 Correct 46 ms 85072 KB Output is correct
13 Correct 47 ms 85076 KB Output is correct
14 Correct 48 ms 85080 KB Output is correct
15 Correct 48 ms 85048 KB Output is correct
16 Correct 47 ms 84952 KB Output is correct
17 Correct 49 ms 85076 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 46 ms 85076 KB Output is correct
20 Correct 47 ms 84956 KB Output is correct
21 Correct 44 ms 85076 KB Output is correct
22 Correct 47 ms 84996 KB Output is correct
23 Correct 45 ms 85108 KB Output is correct
24 Correct 46 ms 85076 KB Output is correct
25 Correct 55 ms 85076 KB Output is correct
26 Correct 47 ms 85076 KB Output is correct
27 Correct 46 ms 85072 KB Output is correct
28 Correct 45 ms 85072 KB Output is correct
29 Correct 53 ms 84904 KB Output is correct
30 Correct 49 ms 85040 KB Output is correct
31 Correct 1305 ms 115788 KB Output is correct
32 Correct 108 ms 91980 KB Output is correct
33 Correct 1265 ms 112952 KB Output is correct
34 Correct 1149 ms 113480 KB Output is correct
35 Correct 1226 ms 115784 KB Output is correct
36 Correct 1243 ms 115256 KB Output is correct
37 Correct 1053 ms 112196 KB Output is correct
38 Correct 1018 ms 111688 KB Output is correct
39 Correct 835 ms 111364 KB Output is correct
40 Correct 870 ms 111272 KB Output is correct
41 Correct 798 ms 106924 KB Output is correct
42 Correct 608 ms 106928 KB Output is correct
43 Correct 75 ms 93000 KB Output is correct
44 Correct 801 ms 107196 KB Output is correct
45 Correct 845 ms 107084 KB Output is correct
46 Correct 964 ms 107068 KB Output is correct
47 Correct 423 ms 104716 KB Output is correct
48 Correct 458 ms 105024 KB Output is correct
49 Correct 507 ms 105804 KB Output is correct
50 Correct 469 ms 106020 KB Output is correct
51 Correct 589 ms 106056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5021 ms 204304 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5099 ms 235528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 84848 KB Output is correct
2 Correct 52 ms 84824 KB Output is correct
3 Correct 42 ms 84952 KB Output is correct
4 Correct 41 ms 84964 KB Output is correct
5 Correct 42 ms 85072 KB Output is correct
6 Correct 43 ms 85080 KB Output is correct
7 Correct 41 ms 85076 KB Output is correct
8 Correct 48 ms 85076 KB Output is correct
9 Correct 43 ms 85016 KB Output is correct
10 Correct 43 ms 85076 KB Output is correct
11 Correct 42 ms 85080 KB Output is correct
12 Correct 46 ms 85072 KB Output is correct
13 Correct 47 ms 85076 KB Output is correct
14 Correct 48 ms 85080 KB Output is correct
15 Correct 48 ms 85048 KB Output is correct
16 Correct 47 ms 84952 KB Output is correct
17 Correct 49 ms 85076 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 46 ms 85076 KB Output is correct
20 Correct 47 ms 84956 KB Output is correct
21 Correct 44 ms 85076 KB Output is correct
22 Correct 47 ms 84996 KB Output is correct
23 Correct 45 ms 85108 KB Output is correct
24 Correct 46 ms 85076 KB Output is correct
25 Correct 55 ms 85076 KB Output is correct
26 Correct 47 ms 85076 KB Output is correct
27 Correct 46 ms 85072 KB Output is correct
28 Correct 45 ms 85072 KB Output is correct
29 Correct 53 ms 84904 KB Output is correct
30 Correct 49 ms 85040 KB Output is correct
31 Correct 1305 ms 115788 KB Output is correct
32 Correct 108 ms 91980 KB Output is correct
33 Correct 1265 ms 112952 KB Output is correct
34 Correct 1149 ms 113480 KB Output is correct
35 Correct 1226 ms 115784 KB Output is correct
36 Correct 1243 ms 115256 KB Output is correct
37 Correct 1053 ms 112196 KB Output is correct
38 Correct 1018 ms 111688 KB Output is correct
39 Correct 835 ms 111364 KB Output is correct
40 Correct 870 ms 111272 KB Output is correct
41 Correct 798 ms 106924 KB Output is correct
42 Correct 608 ms 106928 KB Output is correct
43 Correct 75 ms 93000 KB Output is correct
44 Correct 801 ms 107196 KB Output is correct
45 Correct 845 ms 107084 KB Output is correct
46 Correct 964 ms 107068 KB Output is correct
47 Correct 423 ms 104716 KB Output is correct
48 Correct 458 ms 105024 KB Output is correct
49 Correct 507 ms 105804 KB Output is correct
50 Correct 469 ms 106020 KB Output is correct
51 Correct 589 ms 106056 KB Output is correct
52 Correct 204 ms 102212 KB Output is correct
53 Correct 198 ms 100428 KB Output is correct
54 Correct 408 ms 108960 KB Output is correct
55 Correct 688 ms 106060 KB Output is correct
56 Correct 621 ms 105284 KB Output is correct
57 Correct 805 ms 106824 KB Output is correct
58 Correct 593 ms 105928 KB Output is correct
59 Correct 505 ms 105304 KB Output is correct
60 Correct 634 ms 106572 KB Output is correct
61 Correct 79 ms 98052 KB Output is correct
62 Correct 235 ms 102576 KB Output is correct
63 Correct 404 ms 106312 KB Output is correct
64 Correct 491 ms 106988 KB Output is correct
65 Correct 627 ms 107076 KB Output is correct
66 Correct 767 ms 107336 KB Output is correct
67 Correct 144 ms 95308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 84848 KB Output is correct
2 Correct 52 ms 84824 KB Output is correct
3 Correct 42 ms 84952 KB Output is correct
4 Correct 41 ms 84964 KB Output is correct
5 Correct 42 ms 85072 KB Output is correct
6 Correct 43 ms 85080 KB Output is correct
7 Correct 41 ms 85076 KB Output is correct
8 Correct 48 ms 85076 KB Output is correct
9 Correct 43 ms 85016 KB Output is correct
10 Correct 43 ms 85076 KB Output is correct
11 Correct 42 ms 85080 KB Output is correct
12 Correct 46 ms 85072 KB Output is correct
13 Correct 47 ms 85076 KB Output is correct
14 Correct 48 ms 85080 KB Output is correct
15 Correct 48 ms 85048 KB Output is correct
16 Correct 47 ms 84952 KB Output is correct
17 Correct 49 ms 85076 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 46 ms 85076 KB Output is correct
20 Correct 47 ms 84956 KB Output is correct
21 Correct 44 ms 85076 KB Output is correct
22 Correct 47 ms 84996 KB Output is correct
23 Correct 45 ms 85108 KB Output is correct
24 Correct 46 ms 85076 KB Output is correct
25 Correct 55 ms 85076 KB Output is correct
26 Correct 47 ms 85076 KB Output is correct
27 Correct 46 ms 85072 KB Output is correct
28 Correct 45 ms 85072 KB Output is correct
29 Correct 53 ms 84904 KB Output is correct
30 Correct 49 ms 85040 KB Output is correct
31 Correct 1305 ms 115788 KB Output is correct
32 Correct 108 ms 91980 KB Output is correct
33 Correct 1265 ms 112952 KB Output is correct
34 Correct 1149 ms 113480 KB Output is correct
35 Correct 1226 ms 115784 KB Output is correct
36 Correct 1243 ms 115256 KB Output is correct
37 Correct 1053 ms 112196 KB Output is correct
38 Correct 1018 ms 111688 KB Output is correct
39 Correct 835 ms 111364 KB Output is correct
40 Correct 870 ms 111272 KB Output is correct
41 Correct 798 ms 106924 KB Output is correct
42 Correct 608 ms 106928 KB Output is correct
43 Correct 75 ms 93000 KB Output is correct
44 Correct 801 ms 107196 KB Output is correct
45 Correct 845 ms 107084 KB Output is correct
46 Correct 964 ms 107068 KB Output is correct
47 Correct 423 ms 104716 KB Output is correct
48 Correct 458 ms 105024 KB Output is correct
49 Correct 507 ms 105804 KB Output is correct
50 Correct 469 ms 106020 KB Output is correct
51 Correct 589 ms 106056 KB Output is correct
52 Execution timed out 5021 ms 204304 KB Time limit exceeded
53 Halted 0 ms 0 KB -