Submission #1088981

# Submission time Handle Problem Language Result Execution time Memory
1088981 2024-09-15T17:14:52 Z modwwe New Home (APIO18_new_home) C++17
47 / 100
5000 ms 238504 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 t[1200001];
    void upd(int node,int l,int r,int l1,int x)
    {
        if(l==r)
        {
            t[node]+=x;
            return;
        }
        int mid=l+r>>1;
        if(l1<=mid) upd(node<<1,l,mid,l1,x);
        else upd(node<<1|1,mid+1,r,l1,x);
        t[node]=t[node<<1]+t[node<<1|1];
    }
    int get(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1) return 0;
        if(l>=l1&&r<=r1) return t[node];
        int mid=l+r>>1;
        return get(node<<1,l,mid,l1,r1)+get(node<<1|1,mid+1,r,l1,r1);
    }
} 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)
            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(1,1,n,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(1,1,n,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);
    }
}
bool check(int x,int y)
{
    s2=lower_bound(v2.begin(),v2.end(),x-y)-v2.begin()+1;
    s3=upper_bound(v2.begin(),v2.end(),x+y)-v2.begin();
        return st.get(1,1,n,s2,s3)-fen.get(s2,s3)>=k;
}
int get(int x)
{
    l=0;
    r=1e8;
    while(l<=r)
    {
        int mid=l+r>>1;
        if(check(x,mid))r=mid-1;
        else l=mid+1;
    }
    return r+1;
}
void phongbeo()
{
    cin>>n>>k>>m;
    for(int i=1; i<=n; i++)
        cin>>l>>r>>s2>>s3,a[i]= {l,r,s2,s3},v3.pb(s2),v3.pb(s3+1),v2.pb(l);
    for(int i=1; i<=m; i++)
        cin>>l>>r,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++)
    {
        //cout<<i,down
        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, int, int, int)':
new_home.cpp:97:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp: In member function 'int IT::get(int, int, int, int, int)':
new_home.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp: In member function 'void BIT2D::fakeupd(int, int)':
new_home.cpp:117:13: warning: statement has no effect [-Wunused-value]
  117 |         for(x; x; x-=x&-x)
      |             ^
new_home.cpp: In member function 'void BIT2D::upd(int, int, int)':
new_home.cpp:134:13: warning: statement has no effect [-Wunused-value]
  134 |         for(x; x; x-=x&-x)
      |             ^
new_home.cpp:135:85: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |             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:141:13: warning: statement has no effect [-Wunused-value]
  141 |         for(x; x<=n; x+=x&-x)
      |             ^
new_home.cpp: In function 'int get(int)':
new_home.cpp:240:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  240 |         int mid=l+r>>1;
      |                 ~^~
new_home.cpp: In function 'void phongbeo()':
new_home.cpp:272:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  272 |     for(int i=1; i<=v3.size(); i++)
      |                  ~^~~~~~~~~~~
new_home.cpp:281:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  281 |     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++)
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 44 ms 84816 KB Output is correct
2 Correct 44 ms 84828 KB Output is correct
3 Correct 54 ms 84800 KB Output is correct
4 Correct 42 ms 84816 KB Output is correct
5 Correct 64 ms 84872 KB Output is correct
6 Correct 53 ms 85072 KB Output is correct
7 Correct 44 ms 84912 KB Output is correct
8 Correct 53 ms 85072 KB Output is correct
9 Correct 43 ms 85076 KB Output is correct
10 Correct 44 ms 85072 KB Output is correct
11 Correct 44 ms 85072 KB Output is correct
12 Correct 44 ms 85012 KB Output is correct
13 Correct 54 ms 85072 KB Output is correct
14 Correct 46 ms 84916 KB Output is correct
15 Correct 46 ms 85076 KB Output is correct
16 Correct 49 ms 85100 KB Output is correct
17 Correct 49 ms 84956 KB Output is correct
18 Correct 50 ms 85032 KB Output is correct
19 Correct 41 ms 85040 KB Output is correct
20 Correct 43 ms 85076 KB Output is correct
21 Correct 54 ms 84896 KB Output is correct
22 Correct 43 ms 85040 KB Output is correct
23 Correct 46 ms 85004 KB Output is correct
24 Correct 47 ms 85112 KB Output is correct
25 Correct 43 ms 85160 KB Output is correct
26 Correct 46 ms 84944 KB Output is correct
27 Correct 41 ms 85032 KB Output is correct
28 Correct 48 ms 85044 KB Output is correct
29 Correct 45 ms 84940 KB Output is correct
30 Correct 45 ms 85080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 84816 KB Output is correct
2 Correct 44 ms 84828 KB Output is correct
3 Correct 54 ms 84800 KB Output is correct
4 Correct 42 ms 84816 KB Output is correct
5 Correct 64 ms 84872 KB Output is correct
6 Correct 53 ms 85072 KB Output is correct
7 Correct 44 ms 84912 KB Output is correct
8 Correct 53 ms 85072 KB Output is correct
9 Correct 43 ms 85076 KB Output is correct
10 Correct 44 ms 85072 KB Output is correct
11 Correct 44 ms 85072 KB Output is correct
12 Correct 44 ms 85012 KB Output is correct
13 Correct 54 ms 85072 KB Output is correct
14 Correct 46 ms 84916 KB Output is correct
15 Correct 46 ms 85076 KB Output is correct
16 Correct 49 ms 85100 KB Output is correct
17 Correct 49 ms 84956 KB Output is correct
18 Correct 50 ms 85032 KB Output is correct
19 Correct 41 ms 85040 KB Output is correct
20 Correct 43 ms 85076 KB Output is correct
21 Correct 54 ms 84896 KB Output is correct
22 Correct 43 ms 85040 KB Output is correct
23 Correct 46 ms 85004 KB Output is correct
24 Correct 47 ms 85112 KB Output is correct
25 Correct 43 ms 85160 KB Output is correct
26 Correct 46 ms 84944 KB Output is correct
27 Correct 41 ms 85032 KB Output is correct
28 Correct 48 ms 85044 KB Output is correct
29 Correct 45 ms 84940 KB Output is correct
30 Correct 45 ms 85080 KB Output is correct
31 Correct 1792 ms 116192 KB Output is correct
32 Correct 201 ms 92012 KB Output is correct
33 Correct 1530 ms 113232 KB Output is correct
34 Correct 1503 ms 113932 KB Output is correct
35 Correct 1579 ms 116040 KB Output is correct
36 Correct 1564 ms 115464 KB Output is correct
37 Correct 1347 ms 112364 KB Output is correct
38 Correct 1318 ms 111808 KB Output is correct
39 Correct 1106 ms 111560 KB Output is correct
40 Correct 1144 ms 111708 KB Output is correct
41 Correct 1196 ms 107336 KB Output is correct
42 Correct 1079 ms 107076 KB Output is correct
43 Correct 148 ms 93000 KB Output is correct
44 Correct 1109 ms 107428 KB Output is correct
45 Correct 1168 ms 107336 KB Output is correct
46 Correct 1287 ms 107360 KB Output is correct
47 Correct 716 ms 105080 KB Output is correct
48 Correct 738 ms 105288 KB Output is correct
49 Correct 854 ms 106056 KB Output is correct
50 Correct 816 ms 106164 KB Output is correct
51 Correct 889 ms 106312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5111 ms 207124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5020 ms 238504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 84816 KB Output is correct
2 Correct 44 ms 84828 KB Output is correct
3 Correct 54 ms 84800 KB Output is correct
4 Correct 42 ms 84816 KB Output is correct
5 Correct 64 ms 84872 KB Output is correct
6 Correct 53 ms 85072 KB Output is correct
7 Correct 44 ms 84912 KB Output is correct
8 Correct 53 ms 85072 KB Output is correct
9 Correct 43 ms 85076 KB Output is correct
10 Correct 44 ms 85072 KB Output is correct
11 Correct 44 ms 85072 KB Output is correct
12 Correct 44 ms 85012 KB Output is correct
13 Correct 54 ms 85072 KB Output is correct
14 Correct 46 ms 84916 KB Output is correct
15 Correct 46 ms 85076 KB Output is correct
16 Correct 49 ms 85100 KB Output is correct
17 Correct 49 ms 84956 KB Output is correct
18 Correct 50 ms 85032 KB Output is correct
19 Correct 41 ms 85040 KB Output is correct
20 Correct 43 ms 85076 KB Output is correct
21 Correct 54 ms 84896 KB Output is correct
22 Correct 43 ms 85040 KB Output is correct
23 Correct 46 ms 85004 KB Output is correct
24 Correct 47 ms 85112 KB Output is correct
25 Correct 43 ms 85160 KB Output is correct
26 Correct 46 ms 84944 KB Output is correct
27 Correct 41 ms 85032 KB Output is correct
28 Correct 48 ms 85044 KB Output is correct
29 Correct 45 ms 84940 KB Output is correct
30 Correct 45 ms 85080 KB Output is correct
31 Correct 1792 ms 116192 KB Output is correct
32 Correct 201 ms 92012 KB Output is correct
33 Correct 1530 ms 113232 KB Output is correct
34 Correct 1503 ms 113932 KB Output is correct
35 Correct 1579 ms 116040 KB Output is correct
36 Correct 1564 ms 115464 KB Output is correct
37 Correct 1347 ms 112364 KB Output is correct
38 Correct 1318 ms 111808 KB Output is correct
39 Correct 1106 ms 111560 KB Output is correct
40 Correct 1144 ms 111708 KB Output is correct
41 Correct 1196 ms 107336 KB Output is correct
42 Correct 1079 ms 107076 KB Output is correct
43 Correct 148 ms 93000 KB Output is correct
44 Correct 1109 ms 107428 KB Output is correct
45 Correct 1168 ms 107336 KB Output is correct
46 Correct 1287 ms 107360 KB Output is correct
47 Correct 716 ms 105080 KB Output is correct
48 Correct 738 ms 105288 KB Output is correct
49 Correct 854 ms 106056 KB Output is correct
50 Correct 816 ms 106164 KB Output is correct
51 Correct 889 ms 106312 KB Output is correct
52 Correct 419 ms 102476 KB Output is correct
53 Correct 367 ms 100672 KB Output is correct
54 Correct 927 ms 109128 KB Output is correct
55 Correct 998 ms 106316 KB Output is correct
56 Correct 1008 ms 105960 KB Output is correct
57 Correct 1194 ms 107184 KB Output is correct
58 Correct 1033 ms 106184 KB Output is correct
59 Correct 1004 ms 105544 KB Output is correct
60 Correct 1073 ms 107164 KB Output is correct
61 Correct 119 ms 98120 KB Output is correct
62 Correct 445 ms 102760 KB Output is correct
63 Correct 876 ms 106588 KB Output is correct
64 Correct 917 ms 107336 KB Output is correct
65 Correct 1046 ms 107268 KB Output is correct
66 Correct 1065 ms 107340 KB Output is correct
67 Correct 284 ms 95464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 84816 KB Output is correct
2 Correct 44 ms 84828 KB Output is correct
3 Correct 54 ms 84800 KB Output is correct
4 Correct 42 ms 84816 KB Output is correct
5 Correct 64 ms 84872 KB Output is correct
6 Correct 53 ms 85072 KB Output is correct
7 Correct 44 ms 84912 KB Output is correct
8 Correct 53 ms 85072 KB Output is correct
9 Correct 43 ms 85076 KB Output is correct
10 Correct 44 ms 85072 KB Output is correct
11 Correct 44 ms 85072 KB Output is correct
12 Correct 44 ms 85012 KB Output is correct
13 Correct 54 ms 85072 KB Output is correct
14 Correct 46 ms 84916 KB Output is correct
15 Correct 46 ms 85076 KB Output is correct
16 Correct 49 ms 85100 KB Output is correct
17 Correct 49 ms 84956 KB Output is correct
18 Correct 50 ms 85032 KB Output is correct
19 Correct 41 ms 85040 KB Output is correct
20 Correct 43 ms 85076 KB Output is correct
21 Correct 54 ms 84896 KB Output is correct
22 Correct 43 ms 85040 KB Output is correct
23 Correct 46 ms 85004 KB Output is correct
24 Correct 47 ms 85112 KB Output is correct
25 Correct 43 ms 85160 KB Output is correct
26 Correct 46 ms 84944 KB Output is correct
27 Correct 41 ms 85032 KB Output is correct
28 Correct 48 ms 85044 KB Output is correct
29 Correct 45 ms 84940 KB Output is correct
30 Correct 45 ms 85080 KB Output is correct
31 Correct 1792 ms 116192 KB Output is correct
32 Correct 201 ms 92012 KB Output is correct
33 Correct 1530 ms 113232 KB Output is correct
34 Correct 1503 ms 113932 KB Output is correct
35 Correct 1579 ms 116040 KB Output is correct
36 Correct 1564 ms 115464 KB Output is correct
37 Correct 1347 ms 112364 KB Output is correct
38 Correct 1318 ms 111808 KB Output is correct
39 Correct 1106 ms 111560 KB Output is correct
40 Correct 1144 ms 111708 KB Output is correct
41 Correct 1196 ms 107336 KB Output is correct
42 Correct 1079 ms 107076 KB Output is correct
43 Correct 148 ms 93000 KB Output is correct
44 Correct 1109 ms 107428 KB Output is correct
45 Correct 1168 ms 107336 KB Output is correct
46 Correct 1287 ms 107360 KB Output is correct
47 Correct 716 ms 105080 KB Output is correct
48 Correct 738 ms 105288 KB Output is correct
49 Correct 854 ms 106056 KB Output is correct
50 Correct 816 ms 106164 KB Output is correct
51 Correct 889 ms 106312 KB Output is correct
52 Execution timed out 5111 ms 207124 KB Time limit exceeded
53 Halted 0 ms 0 KB -