Submission #917872

# Submission time Handle Problem Language Result Execution time Memory
917872 2024-01-29T02:25:46 Z CSQ31 New Home (APIO18_new_home) C++17
5 / 100
5000 ms 306448 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXT = 3e6,MAXN = 3e5+1;
int n,q,k;
vector<int>ans(MAXN,-1),T;
multiset<int,greater<int>>lines[MAXT];
map<int,vector<pii>>pt;
map<int,int>crd;
int N;
void upd(int v,int l,int r,int pos){
    if(l==r){
        if(lines[l].empty())T[v] = -1e9;
        else T[v] = *lines[l].begin();
        return;
    }
    int tm = (l+r)/2;
    if(pos<=tm)upd(2*v,l,tm,pos);
    else upd(2*v+1,tm+1,r,pos);
    T[v] = max(T[2*v],T[2*v+1]);
}
int query(int v,int l,int r,int tl,int tr){
    if(l>r)return -1e9;
    if(l==tl && r==tr)return T[v];
    int tm = (tl+tr)/2;
    return max(query(2*v,l,min(r,tm),tl,tm),
               query(2*v+1,max(l,tm+1),r,tm+1,tr));
}
void add(int l,int r){
    int x = (l+r+1)/2;
    int y = r - x;
    //lines[crd[x]].insert(x+y);
    //upd(1,0,N,crd[x]);
}
void del(int l,int r){
    int x = (l+r+1)/2;
    int y = r - x;
   // lines[crd[x]].erase(lines[crd[x]].find(x+y));
    //upd(1,0,N,crd[x]);
}
bool debug = 0;
vector<int>comp;
void addcomp(int l,int r){
    int x = (l+r+1)/2;
    comp.pb(x);
}
vector<pii>sweep;
void solve(){
    vector<multiset<int>>store(k+1);
    //coordinate compress
    comp = {0};crd.clear();
    for(auto z:sweep){
        int t = z.fi;
        int x = z.se;
        if(t > k){
            comp.pb(x);
            continue;
        }
        if(t > 0){ 
            //add this guy
            if(store[t].find(x) != store[t].end()){
                store[t].insert(x);
                continue;
            }
            auto r = store[t].lb(x);
            bool lf = (r!=store[t].begin());
            bool rg = (r!=store[t].end());
            if(lf){
                auto l = r;
                l--;
                addcomp(*l,x);
            }
            if(rg)addcomp(x,*r);
            store[t].insert(x);
        }else{ 
            t*=-1;
            //remove this guy
            store[t].erase(store[t].find(x));
            if(store[t].find(x) != store[t].end())continue;
            
            auto r = store[t].lb(x);
            bool lf = (r!=store[t].begin());
            bool rg = (r!=store[t].end());
            if(lf && rg){
                auto l = r;
                l--;
                addcomp(*l,*r);
            }
        }
    }
    sort(all(comp));
    comp.resize(unique(all(comp)) - comp.begin());
    for(int i=0;i<sz(comp);i++)crd[comp[i]] = i;
    N = sz(comp)-1;
    T.assign(4*(N+1),-1e9);
    
    int open = 0;
    for(auto z : sweep){
        int t = z.fi;
        int x = z.se;
        //cout<<t<<" "<<x<<" "<<open<<'\n';
        if(t > k){
            t-=k+1;
            if(open != k){
                ans[t] = -1;
                continue;
            }
            for(int i=1;i<=k;i++){
                int mn = 1e9;
                for(int x1 : store[i]) mn = min(mn,abs(x-x1));
                ans[t] = max(ans[t],mn);
            }
            continue;
        }
        //cout<<"store "<<t<<" "<<x<<'\n';
        if(t>0){ 
            if(store[t].empty())open++;
            if(store[t].find(x) != store[t].end()){
                store[t].insert(x);
                continue;
            }
            auto r = store[t].lb(x);
            bool lf = (r!=store[t].begin());
            bool rg = (r!=store[t].end());
            if(!lf){
                add(-x,x); //line at 0
                if(rg)add(x,*r);
            }else{
                auto l = r;
                add(*l,x);
                if(rg){
                    add(x,*r);
                    del(*l,*r);
                }
            }
            store[t].insert(x);
        }else{ 
            t*=-1;
            store[t].erase(store[t].find(x));
            if(store[t].empty())open--;
            if(store[t].find(x) != store[t].end())continue;

            auto r = store[t].lb(x);
            bool lf = (r!=store[t].begin());
            bool rg = (r!=store[t].end());
            if(lf){
                auto l = r;
                l--;
                if(rg){
                    add(*l,*r);
                    del(*l,x);
                    del(x,*r);
                }else{
                    del(*l,x);
                }
            }else{
                del(-x,x);
                if(rg)add(-*r,*r);
            }
        }
        
    }


}
int main()
{
    owo
    cin>>n>>k>>q;
    for(int i=0;i<n;i++){
        int x,t,a,b;
        cin>>x>>t>>a>>b;
        pt[a].pb({t,x}); //add
        pt[b+1].pb({-t,x}); //remove
    }
    for(int i=0;i<q;i++){
        int l,y;
        cin>>l>>y;
        pt[y].pb({i+k+1,l});
    }
    for(auto z:pt){
        for(auto x:z.se){if(x.fi <= k)sweep.pb(x);}
        for(auto x:z.se){if(x.fi > k)sweep.pb(x);}
    }
    solve();
    for(pii &x:sweep)x.se = 100000000 - x.se;
    solve();
    for(int i=0;i<q;i++)cout<<ans[i]<<'\n';


}

Compilation message

new_home.cpp: In function 'void add(int, int)':
new_home.cpp:48:9: warning: unused variable 'y' [-Wunused-variable]
   48 |     int y = r - x;
      |         ^
new_home.cpp: In function 'void del(int, int)':
new_home.cpp:54:9: warning: unused variable 'y' [-Wunused-variable]
   54 |     int y = r - x;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 39 ms 142424 KB Output is correct
2 Correct 38 ms 142420 KB Output is correct
3 Correct 39 ms 142420 KB Output is correct
4 Correct 38 ms 142424 KB Output is correct
5 Correct 41 ms 142420 KB Output is correct
6 Correct 42 ms 142684 KB Output is correct
7 Correct 39 ms 142532 KB Output is correct
8 Correct 40 ms 142536 KB Output is correct
9 Correct 38 ms 142680 KB Output is correct
10 Correct 40 ms 142676 KB Output is correct
11 Correct 39 ms 142684 KB Output is correct
12 Correct 44 ms 142676 KB Output is correct
13 Correct 38 ms 142684 KB Output is correct
14 Correct 38 ms 142580 KB Output is correct
15 Correct 40 ms 142676 KB Output is correct
16 Correct 40 ms 142832 KB Output is correct
17 Correct 39 ms 142584 KB Output is correct
18 Correct 43 ms 142680 KB Output is correct
19 Correct 43 ms 142676 KB Output is correct
20 Correct 39 ms 142676 KB Output is correct
21 Correct 39 ms 142428 KB Output is correct
22 Correct 39 ms 142500 KB Output is correct
23 Correct 39 ms 142536 KB Output is correct
24 Correct 39 ms 142672 KB Output is correct
25 Correct 39 ms 142672 KB Output is correct
26 Correct 39 ms 142684 KB Output is correct
27 Correct 40 ms 142508 KB Output is correct
28 Correct 39 ms 142672 KB Output is correct
29 Correct 43 ms 142492 KB Output is correct
30 Correct 39 ms 142456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 142424 KB Output is correct
2 Correct 38 ms 142420 KB Output is correct
3 Correct 39 ms 142420 KB Output is correct
4 Correct 38 ms 142424 KB Output is correct
5 Correct 41 ms 142420 KB Output is correct
6 Correct 42 ms 142684 KB Output is correct
7 Correct 39 ms 142532 KB Output is correct
8 Correct 40 ms 142536 KB Output is correct
9 Correct 38 ms 142680 KB Output is correct
10 Correct 40 ms 142676 KB Output is correct
11 Correct 39 ms 142684 KB Output is correct
12 Correct 44 ms 142676 KB Output is correct
13 Correct 38 ms 142684 KB Output is correct
14 Correct 38 ms 142580 KB Output is correct
15 Correct 40 ms 142676 KB Output is correct
16 Correct 40 ms 142832 KB Output is correct
17 Correct 39 ms 142584 KB Output is correct
18 Correct 43 ms 142680 KB Output is correct
19 Correct 43 ms 142676 KB Output is correct
20 Correct 39 ms 142676 KB Output is correct
21 Correct 39 ms 142428 KB Output is correct
22 Correct 39 ms 142500 KB Output is correct
23 Correct 39 ms 142536 KB Output is correct
24 Correct 39 ms 142672 KB Output is correct
25 Correct 39 ms 142672 KB Output is correct
26 Correct 39 ms 142684 KB Output is correct
27 Correct 40 ms 142508 KB Output is correct
28 Correct 39 ms 142672 KB Output is correct
29 Correct 43 ms 142492 KB Output is correct
30 Correct 39 ms 142456 KB Output is correct
31 Execution timed out 5040 ms 180460 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5028 ms 254528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5051 ms 306448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 142424 KB Output is correct
2 Correct 38 ms 142420 KB Output is correct
3 Correct 39 ms 142420 KB Output is correct
4 Correct 38 ms 142424 KB Output is correct
5 Correct 41 ms 142420 KB Output is correct
6 Correct 42 ms 142684 KB Output is correct
7 Correct 39 ms 142532 KB Output is correct
8 Correct 40 ms 142536 KB Output is correct
9 Correct 38 ms 142680 KB Output is correct
10 Correct 40 ms 142676 KB Output is correct
11 Correct 39 ms 142684 KB Output is correct
12 Correct 44 ms 142676 KB Output is correct
13 Correct 38 ms 142684 KB Output is correct
14 Correct 38 ms 142580 KB Output is correct
15 Correct 40 ms 142676 KB Output is correct
16 Correct 40 ms 142832 KB Output is correct
17 Correct 39 ms 142584 KB Output is correct
18 Correct 43 ms 142680 KB Output is correct
19 Correct 43 ms 142676 KB Output is correct
20 Correct 39 ms 142676 KB Output is correct
21 Correct 39 ms 142428 KB Output is correct
22 Correct 39 ms 142500 KB Output is correct
23 Correct 39 ms 142536 KB Output is correct
24 Correct 39 ms 142672 KB Output is correct
25 Correct 39 ms 142672 KB Output is correct
26 Correct 39 ms 142684 KB Output is correct
27 Correct 40 ms 142508 KB Output is correct
28 Correct 39 ms 142672 KB Output is correct
29 Correct 43 ms 142492 KB Output is correct
30 Correct 39 ms 142456 KB Output is correct
31 Execution timed out 5040 ms 180460 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 142424 KB Output is correct
2 Correct 38 ms 142420 KB Output is correct
3 Correct 39 ms 142420 KB Output is correct
4 Correct 38 ms 142424 KB Output is correct
5 Correct 41 ms 142420 KB Output is correct
6 Correct 42 ms 142684 KB Output is correct
7 Correct 39 ms 142532 KB Output is correct
8 Correct 40 ms 142536 KB Output is correct
9 Correct 38 ms 142680 KB Output is correct
10 Correct 40 ms 142676 KB Output is correct
11 Correct 39 ms 142684 KB Output is correct
12 Correct 44 ms 142676 KB Output is correct
13 Correct 38 ms 142684 KB Output is correct
14 Correct 38 ms 142580 KB Output is correct
15 Correct 40 ms 142676 KB Output is correct
16 Correct 40 ms 142832 KB Output is correct
17 Correct 39 ms 142584 KB Output is correct
18 Correct 43 ms 142680 KB Output is correct
19 Correct 43 ms 142676 KB Output is correct
20 Correct 39 ms 142676 KB Output is correct
21 Correct 39 ms 142428 KB Output is correct
22 Correct 39 ms 142500 KB Output is correct
23 Correct 39 ms 142536 KB Output is correct
24 Correct 39 ms 142672 KB Output is correct
25 Correct 39 ms 142672 KB Output is correct
26 Correct 39 ms 142684 KB Output is correct
27 Correct 40 ms 142508 KB Output is correct
28 Correct 39 ms 142672 KB Output is correct
29 Correct 43 ms 142492 KB Output is correct
30 Correct 39 ms 142456 KB Output is correct
31 Execution timed out 5040 ms 180460 KB Time limit exceeded
32 Halted 0 ms 0 KB -