Submission #1088994

# Submission time Handle Problem Language Result Execution time Memory
1088994 2024-09-15T17:41:10 Z modwwe New Home (APIO18_new_home) C++17
47 / 100
5000 ms 232600 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(s[y].size()==0)dem++;

    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);
        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();
        dem=0;
    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:234:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  234 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp:245:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  245 |             if(s2==1&&s3==v2.size()) return 1e8+1;
      |                       ~~^~~~~~~~~~~
new_home.cpp:248:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  248 |             if(s3!=v2.size())s5=min(s5,abs(x-v2[s3]));
      |                ~~^~~~~~~~~~~
new_home.cpp: In function 'void phongbeo()':
new_home.cpp:282:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  282 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:291:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  291 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:296:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  296 |     for(int i=1; i<=m; i++)
      |     ^~~
new_home.cpp:298:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  298 |         dem=0;
      |         ^~~
new_home.cpp:299:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  299 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 84816 KB Output is correct
2 Correct 45 ms 84828 KB Output is correct
3 Correct 42 ms 84928 KB Output is correct
4 Correct 44 ms 84816 KB Output is correct
5 Correct 46 ms 85072 KB Output is correct
6 Correct 48 ms 85072 KB Output is correct
7 Correct 44 ms 85084 KB Output is correct
8 Correct 46 ms 85076 KB Output is correct
9 Correct 44 ms 85104 KB Output is correct
10 Correct 56 ms 85176 KB Output is correct
11 Correct 44 ms 85068 KB Output is correct
12 Correct 45 ms 85028 KB Output is correct
13 Correct 44 ms 85072 KB Output is correct
14 Correct 46 ms 84908 KB Output is correct
15 Correct 46 ms 84960 KB Output is correct
16 Correct 45 ms 85072 KB Output is correct
17 Correct 48 ms 85072 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 56 ms 85072 KB Output is correct
20 Correct 42 ms 84916 KB Output is correct
21 Correct 44 ms 85080 KB Output is correct
22 Correct 43 ms 84944 KB Output is correct
23 Correct 46 ms 85076 KB Output is correct
24 Correct 44 ms 85068 KB Output is correct
25 Correct 42 ms 85084 KB Output is correct
26 Correct 49 ms 85028 KB Output is correct
27 Correct 47 ms 85076 KB Output is correct
28 Correct 42 ms 85072 KB Output is correct
29 Correct 42 ms 85076 KB Output is correct
30 Correct 47 ms 85076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 84816 KB Output is correct
2 Correct 45 ms 84828 KB Output is correct
3 Correct 42 ms 84928 KB Output is correct
4 Correct 44 ms 84816 KB Output is correct
5 Correct 46 ms 85072 KB Output is correct
6 Correct 48 ms 85072 KB Output is correct
7 Correct 44 ms 85084 KB Output is correct
8 Correct 46 ms 85076 KB Output is correct
9 Correct 44 ms 85104 KB Output is correct
10 Correct 56 ms 85176 KB Output is correct
11 Correct 44 ms 85068 KB Output is correct
12 Correct 45 ms 85028 KB Output is correct
13 Correct 44 ms 85072 KB Output is correct
14 Correct 46 ms 84908 KB Output is correct
15 Correct 46 ms 84960 KB Output is correct
16 Correct 45 ms 85072 KB Output is correct
17 Correct 48 ms 85072 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 56 ms 85072 KB Output is correct
20 Correct 42 ms 84916 KB Output is correct
21 Correct 44 ms 85080 KB Output is correct
22 Correct 43 ms 84944 KB Output is correct
23 Correct 46 ms 85076 KB Output is correct
24 Correct 44 ms 85068 KB Output is correct
25 Correct 42 ms 85084 KB Output is correct
26 Correct 49 ms 85028 KB Output is correct
27 Correct 47 ms 85076 KB Output is correct
28 Correct 42 ms 85072 KB Output is correct
29 Correct 42 ms 85076 KB Output is correct
30 Correct 47 ms 85076 KB Output is correct
31 Correct 1195 ms 115884 KB Output is correct
32 Correct 103 ms 91980 KB Output is correct
33 Correct 1211 ms 112968 KB Output is correct
34 Correct 1184 ms 113668 KB Output is correct
35 Correct 1272 ms 115784 KB Output is correct
36 Correct 1232 ms 115188 KB Output is correct
37 Correct 996 ms 112140 KB Output is correct
38 Correct 999 ms 111640 KB Output is correct
39 Correct 867 ms 111352 KB Output is correct
40 Correct 859 ms 111380 KB Output is correct
41 Correct 780 ms 107108 KB Output is correct
42 Correct 535 ms 106824 KB Output is correct
43 Correct 70 ms 92860 KB Output is correct
44 Correct 754 ms 106988 KB Output is correct
45 Correct 815 ms 107080 KB Output is correct
46 Correct 962 ms 107056 KB Output is correct
47 Correct 378 ms 104864 KB Output is correct
48 Correct 451 ms 105036 KB Output is correct
49 Correct 538 ms 105952 KB Output is correct
50 Correct 443 ms 105804 KB Output is correct
51 Correct 593 ms 106060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5111 ms 201280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5110 ms 232600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 84816 KB Output is correct
2 Correct 45 ms 84828 KB Output is correct
3 Correct 42 ms 84928 KB Output is correct
4 Correct 44 ms 84816 KB Output is correct
5 Correct 46 ms 85072 KB Output is correct
6 Correct 48 ms 85072 KB Output is correct
7 Correct 44 ms 85084 KB Output is correct
8 Correct 46 ms 85076 KB Output is correct
9 Correct 44 ms 85104 KB Output is correct
10 Correct 56 ms 85176 KB Output is correct
11 Correct 44 ms 85068 KB Output is correct
12 Correct 45 ms 85028 KB Output is correct
13 Correct 44 ms 85072 KB Output is correct
14 Correct 46 ms 84908 KB Output is correct
15 Correct 46 ms 84960 KB Output is correct
16 Correct 45 ms 85072 KB Output is correct
17 Correct 48 ms 85072 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 56 ms 85072 KB Output is correct
20 Correct 42 ms 84916 KB Output is correct
21 Correct 44 ms 85080 KB Output is correct
22 Correct 43 ms 84944 KB Output is correct
23 Correct 46 ms 85076 KB Output is correct
24 Correct 44 ms 85068 KB Output is correct
25 Correct 42 ms 85084 KB Output is correct
26 Correct 49 ms 85028 KB Output is correct
27 Correct 47 ms 85076 KB Output is correct
28 Correct 42 ms 85072 KB Output is correct
29 Correct 42 ms 85076 KB Output is correct
30 Correct 47 ms 85076 KB Output is correct
31 Correct 1195 ms 115884 KB Output is correct
32 Correct 103 ms 91980 KB Output is correct
33 Correct 1211 ms 112968 KB Output is correct
34 Correct 1184 ms 113668 KB Output is correct
35 Correct 1272 ms 115784 KB Output is correct
36 Correct 1232 ms 115188 KB Output is correct
37 Correct 996 ms 112140 KB Output is correct
38 Correct 999 ms 111640 KB Output is correct
39 Correct 867 ms 111352 KB Output is correct
40 Correct 859 ms 111380 KB Output is correct
41 Correct 780 ms 107108 KB Output is correct
42 Correct 535 ms 106824 KB Output is correct
43 Correct 70 ms 92860 KB Output is correct
44 Correct 754 ms 106988 KB Output is correct
45 Correct 815 ms 107080 KB Output is correct
46 Correct 962 ms 107056 KB Output is correct
47 Correct 378 ms 104864 KB Output is correct
48 Correct 451 ms 105036 KB Output is correct
49 Correct 538 ms 105952 KB Output is correct
50 Correct 443 ms 105804 KB Output is correct
51 Correct 593 ms 106060 KB Output is correct
52 Correct 164 ms 102216 KB Output is correct
53 Correct 158 ms 100532 KB Output is correct
54 Correct 300 ms 108844 KB Output is correct
55 Correct 658 ms 106060 KB Output is correct
56 Correct 614 ms 105284 KB Output is correct
57 Correct 769 ms 106828 KB Output is correct
58 Correct 511 ms 106056 KB Output is correct
59 Correct 439 ms 105192 KB Output is correct
60 Correct 591 ms 106660 KB Output is correct
61 Correct 83 ms 98124 KB Output is correct
62 Correct 193 ms 102472 KB Output is correct
63 Correct 358 ms 106312 KB Output is correct
64 Correct 467 ms 107008 KB Output is correct
65 Correct 594 ms 106844 KB Output is correct
66 Correct 802 ms 107192 KB Output is correct
67 Correct 146 ms 95560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 84816 KB Output is correct
2 Correct 45 ms 84828 KB Output is correct
3 Correct 42 ms 84928 KB Output is correct
4 Correct 44 ms 84816 KB Output is correct
5 Correct 46 ms 85072 KB Output is correct
6 Correct 48 ms 85072 KB Output is correct
7 Correct 44 ms 85084 KB Output is correct
8 Correct 46 ms 85076 KB Output is correct
9 Correct 44 ms 85104 KB Output is correct
10 Correct 56 ms 85176 KB Output is correct
11 Correct 44 ms 85068 KB Output is correct
12 Correct 45 ms 85028 KB Output is correct
13 Correct 44 ms 85072 KB Output is correct
14 Correct 46 ms 84908 KB Output is correct
15 Correct 46 ms 84960 KB Output is correct
16 Correct 45 ms 85072 KB Output is correct
17 Correct 48 ms 85072 KB Output is correct
18 Correct 47 ms 85076 KB Output is correct
19 Correct 56 ms 85072 KB Output is correct
20 Correct 42 ms 84916 KB Output is correct
21 Correct 44 ms 85080 KB Output is correct
22 Correct 43 ms 84944 KB Output is correct
23 Correct 46 ms 85076 KB Output is correct
24 Correct 44 ms 85068 KB Output is correct
25 Correct 42 ms 85084 KB Output is correct
26 Correct 49 ms 85028 KB Output is correct
27 Correct 47 ms 85076 KB Output is correct
28 Correct 42 ms 85072 KB Output is correct
29 Correct 42 ms 85076 KB Output is correct
30 Correct 47 ms 85076 KB Output is correct
31 Correct 1195 ms 115884 KB Output is correct
32 Correct 103 ms 91980 KB Output is correct
33 Correct 1211 ms 112968 KB Output is correct
34 Correct 1184 ms 113668 KB Output is correct
35 Correct 1272 ms 115784 KB Output is correct
36 Correct 1232 ms 115188 KB Output is correct
37 Correct 996 ms 112140 KB Output is correct
38 Correct 999 ms 111640 KB Output is correct
39 Correct 867 ms 111352 KB Output is correct
40 Correct 859 ms 111380 KB Output is correct
41 Correct 780 ms 107108 KB Output is correct
42 Correct 535 ms 106824 KB Output is correct
43 Correct 70 ms 92860 KB Output is correct
44 Correct 754 ms 106988 KB Output is correct
45 Correct 815 ms 107080 KB Output is correct
46 Correct 962 ms 107056 KB Output is correct
47 Correct 378 ms 104864 KB Output is correct
48 Correct 451 ms 105036 KB Output is correct
49 Correct 538 ms 105952 KB Output is correct
50 Correct 443 ms 105804 KB Output is correct
51 Correct 593 ms 106060 KB Output is correct
52 Execution timed out 5111 ms 201280 KB Time limit exceeded
53 Halted 0 ms 0 KB -