Submission #348359

# Submission time Handle Problem Language Result Execution time Memory
348359 2021-01-14T18:38:44 Z denkendoemeer New Home (APIO18_new_home) C++14
5 / 100
5000 ms 39552 KB
#include<bits/stdc++.h>
#define ll long long
const int inf=1e8;
using namespace std;
int x[310005],t[610005],st[1210005],ans[310005];
vector<array<int,2>>v1[310005];
array<int,4>v2[1210005];
array<int,3>qa[310005];
struct comp
{
    bool operator () (const int &a,const int &b) const
    {
        if (x[a]==x[b])
            return a<b;
        return x[a]<x[b];
    }
};
map<int,int,comp>mp;
int u2=0,n,k,q;
void calc()
{
    int i;
    for(i=0;i<k;i++){
        mp[n+1]=0;
        for(auto it:v1[i]){
            auto it1=mp.upper_bound(it[1]),it2=it1--;
            v2[u2++]={(x[it1->first]+x[it2->first]+1)/2,x[it2->first],it2->second,it[0]};
            it2->second=it[0];
            if (it1->first==it[1]){
                it2=it1--;
                v2[u2++]={(x[it1->first]+x[it[1]]+1)/2,x[it[1]],it2->second,it[0]};
                mp.erase(it2);
            }
            else
                mp[it[1]]=it[0];
        }
        v2[u2++]={0,2*inf,mp[n+1],2*n+1};
    }
    sort(v2,v2+u2);
    int j=0;
    for(i=0;i<q;i++){
        while(v2[j][0]<=qa[i][0]){
            int l=v2[j][2]+2*n+1;
            int r=v2[j][3]+2*n+1;
            while(l<r){
                if (l%2==1)
                    st[l]=max(v2[j][1],st[l]);
                if (r%2==1)
                    st[r-1]=max(v2[j][1],st[r-1]);
                ++l/=2;
                r=r/2;
            }
            ++j;
        }
        for(j=qa[i][2]+2*n+1;j>=1;j=j/2)
            ans[qa[i][1]]=max(ans[qa[i][1]],st[j]-qa[i][0]);
    }
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d%d%d",&n,&k,&q);
    int i;
    for(i=0;i<n;i++){
        int aux;
        scanf("%d%d%d%d",&x[i],&aux,&t[2*i],&t[2*i+1]);
        --aux;
        ++t[2*i+1];
        v1[aux].push_back({t[2*i],i});
        v1[aux].push_back({t[2*i+1],i});
    }
    x[n]=-2*inf;
    x[n+1]=2*inf;
    sort(t,t+2*n+1);
    for(i=0;i<k;i++){
        for(auto &it:v1[i])
            it[0]=lower_bound(t,t+2*n+1,it[0])-t;
        sort(v1[i].begin(),v1[i].end());
    }
    for(i=0;i<q;i++){
        scanf("%d%d",&qa[i][0],&qa[i][2]);
        qa[i][2]=upper_bound(t,t+2*n+1,qa[i][2])-t-1;
        qa[i][1]=i;
    }
    sort(qa,qa+q);
    mp[n]=0;
    calc();
    for(i=0;i<n;i++)
        x[i]=inf-x[i];
    for(i=0;i<q;i++)
        qa[i][0]=inf-qa[i][0];
    reverse(qa,qa+q);
    u2=0;
    memset(st,0,sizeof(st));
    calc();
    for(i=0;i<q;i++)
        if (ans[i]>=inf)
            printf("-1\n");
        else
            printf("%d\n",ans[i]);
return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     scanf("%d%d%d",&n,&k,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
new_home.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |         scanf("%d%d%d%d",&x[i],&aux,&t[2*i],&t[2*i+1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   82 |         scanf("%d%d",&qa[i][0],&qa[i][2]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12396 KB Output is correct
2 Correct 8 ms 12396 KB Output is correct
3 Correct 9 ms 12396 KB Output is correct
4 Correct 9 ms 12396 KB Output is correct
5 Correct 24 ms 12396 KB Output is correct
6 Correct 23 ms 12396 KB Output is correct
7 Correct 53 ms 12396 KB Output is correct
8 Correct 35 ms 12396 KB Output is correct
9 Correct 54 ms 12396 KB Output is correct
10 Correct 32 ms 12396 KB Output is correct
11 Correct 22 ms 12396 KB Output is correct
12 Correct 16 ms 12396 KB Output is correct
13 Correct 15 ms 12396 KB Output is correct
14 Correct 13 ms 12396 KB Output is correct
15 Correct 29 ms 12396 KB Output is correct
16 Correct 36 ms 12396 KB Output is correct
17 Correct 27 ms 12396 KB Output is correct
18 Correct 32 ms 12396 KB Output is correct
19 Correct 37 ms 12396 KB Output is correct
20 Correct 24 ms 12396 KB Output is correct
21 Correct 32 ms 12396 KB Output is correct
22 Correct 63 ms 12396 KB Output is correct
23 Correct 40 ms 12396 KB Output is correct
24 Correct 34 ms 12396 KB Output is correct
25 Correct 24 ms 12396 KB Output is correct
26 Correct 14 ms 12396 KB Output is correct
27 Correct 23 ms 12524 KB Output is correct
28 Correct 17 ms 12396 KB Output is correct
29 Correct 15 ms 12524 KB Output is correct
30 Correct 12 ms 12416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12396 KB Output is correct
2 Correct 8 ms 12396 KB Output is correct
3 Correct 9 ms 12396 KB Output is correct
4 Correct 9 ms 12396 KB Output is correct
5 Correct 24 ms 12396 KB Output is correct
6 Correct 23 ms 12396 KB Output is correct
7 Correct 53 ms 12396 KB Output is correct
8 Correct 35 ms 12396 KB Output is correct
9 Correct 54 ms 12396 KB Output is correct
10 Correct 32 ms 12396 KB Output is correct
11 Correct 22 ms 12396 KB Output is correct
12 Correct 16 ms 12396 KB Output is correct
13 Correct 15 ms 12396 KB Output is correct
14 Correct 13 ms 12396 KB Output is correct
15 Correct 29 ms 12396 KB Output is correct
16 Correct 36 ms 12396 KB Output is correct
17 Correct 27 ms 12396 KB Output is correct
18 Correct 32 ms 12396 KB Output is correct
19 Correct 37 ms 12396 KB Output is correct
20 Correct 24 ms 12396 KB Output is correct
21 Correct 32 ms 12396 KB Output is correct
22 Correct 63 ms 12396 KB Output is correct
23 Correct 40 ms 12396 KB Output is correct
24 Correct 34 ms 12396 KB Output is correct
25 Correct 24 ms 12396 KB Output is correct
26 Correct 14 ms 12396 KB Output is correct
27 Correct 23 ms 12524 KB Output is correct
28 Correct 17 ms 12396 KB Output is correct
29 Correct 15 ms 12524 KB Output is correct
30 Correct 12 ms 12416 KB Output is correct
31 Execution timed out 5055 ms 14900 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5056 ms 38892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5064 ms 39552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12396 KB Output is correct
2 Correct 8 ms 12396 KB Output is correct
3 Correct 9 ms 12396 KB Output is correct
4 Correct 9 ms 12396 KB Output is correct
5 Correct 24 ms 12396 KB Output is correct
6 Correct 23 ms 12396 KB Output is correct
7 Correct 53 ms 12396 KB Output is correct
8 Correct 35 ms 12396 KB Output is correct
9 Correct 54 ms 12396 KB Output is correct
10 Correct 32 ms 12396 KB Output is correct
11 Correct 22 ms 12396 KB Output is correct
12 Correct 16 ms 12396 KB Output is correct
13 Correct 15 ms 12396 KB Output is correct
14 Correct 13 ms 12396 KB Output is correct
15 Correct 29 ms 12396 KB Output is correct
16 Correct 36 ms 12396 KB Output is correct
17 Correct 27 ms 12396 KB Output is correct
18 Correct 32 ms 12396 KB Output is correct
19 Correct 37 ms 12396 KB Output is correct
20 Correct 24 ms 12396 KB Output is correct
21 Correct 32 ms 12396 KB Output is correct
22 Correct 63 ms 12396 KB Output is correct
23 Correct 40 ms 12396 KB Output is correct
24 Correct 34 ms 12396 KB Output is correct
25 Correct 24 ms 12396 KB Output is correct
26 Correct 14 ms 12396 KB Output is correct
27 Correct 23 ms 12524 KB Output is correct
28 Correct 17 ms 12396 KB Output is correct
29 Correct 15 ms 12524 KB Output is correct
30 Correct 12 ms 12416 KB Output is correct
31 Execution timed out 5055 ms 14900 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12396 KB Output is correct
2 Correct 8 ms 12396 KB Output is correct
3 Correct 9 ms 12396 KB Output is correct
4 Correct 9 ms 12396 KB Output is correct
5 Correct 24 ms 12396 KB Output is correct
6 Correct 23 ms 12396 KB Output is correct
7 Correct 53 ms 12396 KB Output is correct
8 Correct 35 ms 12396 KB Output is correct
9 Correct 54 ms 12396 KB Output is correct
10 Correct 32 ms 12396 KB Output is correct
11 Correct 22 ms 12396 KB Output is correct
12 Correct 16 ms 12396 KB Output is correct
13 Correct 15 ms 12396 KB Output is correct
14 Correct 13 ms 12396 KB Output is correct
15 Correct 29 ms 12396 KB Output is correct
16 Correct 36 ms 12396 KB Output is correct
17 Correct 27 ms 12396 KB Output is correct
18 Correct 32 ms 12396 KB Output is correct
19 Correct 37 ms 12396 KB Output is correct
20 Correct 24 ms 12396 KB Output is correct
21 Correct 32 ms 12396 KB Output is correct
22 Correct 63 ms 12396 KB Output is correct
23 Correct 40 ms 12396 KB Output is correct
24 Correct 34 ms 12396 KB Output is correct
25 Correct 24 ms 12396 KB Output is correct
26 Correct 14 ms 12396 KB Output is correct
27 Correct 23 ms 12524 KB Output is correct
28 Correct 17 ms 12396 KB Output is correct
29 Correct 15 ms 12524 KB Output is correct
30 Correct 12 ms 12416 KB Output is correct
31 Execution timed out 5055 ms 14900 KB Time limit exceeded
32 Halted 0 ms 0 KB -