Submission #348366

# Submission time Handle Problem Language Result Execution time Memory
348366 2021-01-14T18:49:17 Z denkendoemeer New Home (APIO18_new_home) C++14
100 / 100
2396 ms 67388 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,e;
    for(i=0;i<q;i++){
        while(j<u2 && 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(e=qa[i][2]+2*n+1;e>=1;e=e/2)
            ans[qa[i][1]]=max(ans[qa[i][1]],st[e]-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 8 ms 12396 KB Output is correct
4 Correct 8 ms 12396 KB Output is correct
5 Correct 9 ms 12396 KB Output is correct
6 Correct 9 ms 12396 KB Output is correct
7 Correct 9 ms 12396 KB Output is correct
8 Correct 9 ms 12396 KB Output is correct
9 Correct 9 ms 12396 KB Output is correct
10 Correct 9 ms 12396 KB Output is correct
11 Correct 8 ms 12396 KB Output is correct
12 Correct 8 ms 12396 KB Output is correct
13 Correct 9 ms 12396 KB Output is correct
14 Correct 9 ms 12396 KB Output is correct
15 Correct 9 ms 12396 KB Output is correct
16 Correct 9 ms 12396 KB Output is correct
17 Correct 9 ms 12396 KB Output is correct
18 Correct 9 ms 12396 KB Output is correct
19 Correct 9 ms 12396 KB Output is correct
20 Correct 9 ms 12396 KB Output is correct
21 Correct 8 ms 12396 KB Output is correct
22 Correct 8 ms 12396 KB Output is correct
23 Correct 8 ms 12396 KB Output is correct
24 Correct 8 ms 12396 KB Output is correct
25 Correct 9 ms 12396 KB Output is correct
26 Correct 8 ms 12396 KB Output is correct
27 Correct 9 ms 12396 KB Output is correct
28 Correct 10 ms 12396 KB Output is correct
29 Correct 10 ms 12396 KB Output is correct
30 Correct 8 ms 12396 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 8 ms 12396 KB Output is correct
4 Correct 8 ms 12396 KB Output is correct
5 Correct 9 ms 12396 KB Output is correct
6 Correct 9 ms 12396 KB Output is correct
7 Correct 9 ms 12396 KB Output is correct
8 Correct 9 ms 12396 KB Output is correct
9 Correct 9 ms 12396 KB Output is correct
10 Correct 9 ms 12396 KB Output is correct
11 Correct 8 ms 12396 KB Output is correct
12 Correct 8 ms 12396 KB Output is correct
13 Correct 9 ms 12396 KB Output is correct
14 Correct 9 ms 12396 KB Output is correct
15 Correct 9 ms 12396 KB Output is correct
16 Correct 9 ms 12396 KB Output is correct
17 Correct 9 ms 12396 KB Output is correct
18 Correct 9 ms 12396 KB Output is correct
19 Correct 9 ms 12396 KB Output is correct
20 Correct 9 ms 12396 KB Output is correct
21 Correct 8 ms 12396 KB Output is correct
22 Correct 8 ms 12396 KB Output is correct
23 Correct 8 ms 12396 KB Output is correct
24 Correct 8 ms 12396 KB Output is correct
25 Correct 9 ms 12396 KB Output is correct
26 Correct 8 ms 12396 KB Output is correct
27 Correct 9 ms 12396 KB Output is correct
28 Correct 10 ms 12396 KB Output is correct
29 Correct 10 ms 12396 KB Output is correct
30 Correct 8 ms 12396 KB Output is correct
31 Correct 254 ms 19180 KB Output is correct
32 Correct 215 ms 19044 KB Output is correct
33 Correct 281 ms 21612 KB Output is correct
34 Correct 245 ms 22204 KB Output is correct
35 Correct 261 ms 21448 KB Output is correct
36 Correct 292 ms 21612 KB Output is correct
37 Correct 264 ms 21484 KB Output is correct
38 Correct 252 ms 21084 KB Output is correct
39 Correct 213 ms 21088 KB Output is correct
40 Correct 222 ms 21344 KB Output is correct
41 Correct 187 ms 21356 KB Output is correct
42 Correct 184 ms 21612 KB Output is correct
43 Correct 137 ms 21376 KB Output is correct
44 Correct 187 ms 21740 KB Output is correct
45 Correct 205 ms 21612 KB Output is correct
46 Correct 165 ms 21400 KB Output is correct
47 Correct 154 ms 20972 KB Output is correct
48 Correct 154 ms 20828 KB Output is correct
49 Correct 163 ms 21248 KB Output is correct
50 Correct 181 ms 21868 KB Output is correct
51 Correct 170 ms 21168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 864 ms 46192 KB Output is correct
2 Correct 1185 ms 54980 KB Output is correct
3 Correct 978 ms 65388 KB Output is correct
4 Correct 902 ms 60388 KB Output is correct
5 Correct 1668 ms 67388 KB Output is correct
6 Correct 1237 ms 56312 KB Output is correct
7 Correct 840 ms 65564 KB Output is correct
8 Correct 797 ms 59768 KB Output is correct
9 Correct 778 ms 58108 KB Output is correct
10 Correct 956 ms 55824 KB Output is correct
11 Correct 847 ms 54100 KB Output is correct
12 Correct 840 ms 56232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1175 ms 44188 KB Output is correct
2 Correct 1128 ms 45664 KB Output is correct
3 Correct 1525 ms 54888 KB Output is correct
4 Correct 1234 ms 63344 KB Output is correct
5 Correct 1194 ms 57868 KB Output is correct
6 Correct 1128 ms 58252 KB Output is correct
7 Correct 2396 ms 66880 KB Output is correct
8 Correct 1622 ms 56004 KB Output is correct
9 Correct 1059 ms 64496 KB Output is correct
10 Correct 1014 ms 58916 KB Output is correct
11 Correct 1097 ms 57476 KB Output is correct
12 Correct 1240 ms 55400 KB Output is correct
13 Correct 887 ms 53704 KB Output is correct
14 Correct 899 ms 54612 KB Output is correct
15 Correct 977 ms 53760 KB Output is correct
16 Correct 1004 ms 55812 KB Output is correct
17 Correct 1052 ms 54172 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 8 ms 12396 KB Output is correct
4 Correct 8 ms 12396 KB Output is correct
5 Correct 9 ms 12396 KB Output is correct
6 Correct 9 ms 12396 KB Output is correct
7 Correct 9 ms 12396 KB Output is correct
8 Correct 9 ms 12396 KB Output is correct
9 Correct 9 ms 12396 KB Output is correct
10 Correct 9 ms 12396 KB Output is correct
11 Correct 8 ms 12396 KB Output is correct
12 Correct 8 ms 12396 KB Output is correct
13 Correct 9 ms 12396 KB Output is correct
14 Correct 9 ms 12396 KB Output is correct
15 Correct 9 ms 12396 KB Output is correct
16 Correct 9 ms 12396 KB Output is correct
17 Correct 9 ms 12396 KB Output is correct
18 Correct 9 ms 12396 KB Output is correct
19 Correct 9 ms 12396 KB Output is correct
20 Correct 9 ms 12396 KB Output is correct
21 Correct 8 ms 12396 KB Output is correct
22 Correct 8 ms 12396 KB Output is correct
23 Correct 8 ms 12396 KB Output is correct
24 Correct 8 ms 12396 KB Output is correct
25 Correct 9 ms 12396 KB Output is correct
26 Correct 8 ms 12396 KB Output is correct
27 Correct 9 ms 12396 KB Output is correct
28 Correct 10 ms 12396 KB Output is correct
29 Correct 10 ms 12396 KB Output is correct
30 Correct 8 ms 12396 KB Output is correct
31 Correct 254 ms 19180 KB Output is correct
32 Correct 215 ms 19044 KB Output is correct
33 Correct 281 ms 21612 KB Output is correct
34 Correct 245 ms 22204 KB Output is correct
35 Correct 261 ms 21448 KB Output is correct
36 Correct 292 ms 21612 KB Output is correct
37 Correct 264 ms 21484 KB Output is correct
38 Correct 252 ms 21084 KB Output is correct
39 Correct 213 ms 21088 KB Output is correct
40 Correct 222 ms 21344 KB Output is correct
41 Correct 187 ms 21356 KB Output is correct
42 Correct 184 ms 21612 KB Output is correct
43 Correct 137 ms 21376 KB Output is correct
44 Correct 187 ms 21740 KB Output is correct
45 Correct 205 ms 21612 KB Output is correct
46 Correct 165 ms 21400 KB Output is correct
47 Correct 154 ms 20972 KB Output is correct
48 Correct 154 ms 20828 KB Output is correct
49 Correct 163 ms 21248 KB Output is correct
50 Correct 181 ms 21868 KB Output is correct
51 Correct 170 ms 21168 KB Output is correct
52 Correct 243 ms 22892 KB Output is correct
53 Correct 247 ms 22892 KB Output is correct
54 Correct 229 ms 21996 KB Output is correct
55 Correct 202 ms 22252 KB Output is correct
56 Correct 209 ms 22508 KB Output is correct
57 Correct 193 ms 21740 KB Output is correct
58 Correct 214 ms 22160 KB Output is correct
59 Correct 212 ms 22380 KB Output is correct
60 Correct 191 ms 21996 KB Output is correct
61 Correct 155 ms 22764 KB Output is correct
62 Correct 233 ms 23120 KB Output is correct
63 Correct 222 ms 22252 KB Output is correct
64 Correct 217 ms 22000 KB Output is correct
65 Correct 210 ms 21740 KB Output is correct
66 Correct 209 ms 21780 KB Output is correct
67 Correct 189 ms 19692 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 8 ms 12396 KB Output is correct
4 Correct 8 ms 12396 KB Output is correct
5 Correct 9 ms 12396 KB Output is correct
6 Correct 9 ms 12396 KB Output is correct
7 Correct 9 ms 12396 KB Output is correct
8 Correct 9 ms 12396 KB Output is correct
9 Correct 9 ms 12396 KB Output is correct
10 Correct 9 ms 12396 KB Output is correct
11 Correct 8 ms 12396 KB Output is correct
12 Correct 8 ms 12396 KB Output is correct
13 Correct 9 ms 12396 KB Output is correct
14 Correct 9 ms 12396 KB Output is correct
15 Correct 9 ms 12396 KB Output is correct
16 Correct 9 ms 12396 KB Output is correct
17 Correct 9 ms 12396 KB Output is correct
18 Correct 9 ms 12396 KB Output is correct
19 Correct 9 ms 12396 KB Output is correct
20 Correct 9 ms 12396 KB Output is correct
21 Correct 8 ms 12396 KB Output is correct
22 Correct 8 ms 12396 KB Output is correct
23 Correct 8 ms 12396 KB Output is correct
24 Correct 8 ms 12396 KB Output is correct
25 Correct 9 ms 12396 KB Output is correct
26 Correct 8 ms 12396 KB Output is correct
27 Correct 9 ms 12396 KB Output is correct
28 Correct 10 ms 12396 KB Output is correct
29 Correct 10 ms 12396 KB Output is correct
30 Correct 8 ms 12396 KB Output is correct
31 Correct 254 ms 19180 KB Output is correct
32 Correct 215 ms 19044 KB Output is correct
33 Correct 281 ms 21612 KB Output is correct
34 Correct 245 ms 22204 KB Output is correct
35 Correct 261 ms 21448 KB Output is correct
36 Correct 292 ms 21612 KB Output is correct
37 Correct 264 ms 21484 KB Output is correct
38 Correct 252 ms 21084 KB Output is correct
39 Correct 213 ms 21088 KB Output is correct
40 Correct 222 ms 21344 KB Output is correct
41 Correct 187 ms 21356 KB Output is correct
42 Correct 184 ms 21612 KB Output is correct
43 Correct 137 ms 21376 KB Output is correct
44 Correct 187 ms 21740 KB Output is correct
45 Correct 205 ms 21612 KB Output is correct
46 Correct 165 ms 21400 KB Output is correct
47 Correct 154 ms 20972 KB Output is correct
48 Correct 154 ms 20828 KB Output is correct
49 Correct 163 ms 21248 KB Output is correct
50 Correct 181 ms 21868 KB Output is correct
51 Correct 170 ms 21168 KB Output is correct
52 Correct 864 ms 46192 KB Output is correct
53 Correct 1185 ms 54980 KB Output is correct
54 Correct 978 ms 65388 KB Output is correct
55 Correct 902 ms 60388 KB Output is correct
56 Correct 1668 ms 67388 KB Output is correct
57 Correct 1237 ms 56312 KB Output is correct
58 Correct 840 ms 65564 KB Output is correct
59 Correct 797 ms 59768 KB Output is correct
60 Correct 778 ms 58108 KB Output is correct
61 Correct 956 ms 55824 KB Output is correct
62 Correct 847 ms 54100 KB Output is correct
63 Correct 840 ms 56232 KB Output is correct
64 Correct 1175 ms 44188 KB Output is correct
65 Correct 1128 ms 45664 KB Output is correct
66 Correct 1525 ms 54888 KB Output is correct
67 Correct 1234 ms 63344 KB Output is correct
68 Correct 1194 ms 57868 KB Output is correct
69 Correct 1128 ms 58252 KB Output is correct
70 Correct 2396 ms 66880 KB Output is correct
71 Correct 1622 ms 56004 KB Output is correct
72 Correct 1059 ms 64496 KB Output is correct
73 Correct 1014 ms 58916 KB Output is correct
74 Correct 1097 ms 57476 KB Output is correct
75 Correct 1240 ms 55400 KB Output is correct
76 Correct 887 ms 53704 KB Output is correct
77 Correct 899 ms 54612 KB Output is correct
78 Correct 977 ms 53760 KB Output is correct
79 Correct 1004 ms 55812 KB Output is correct
80 Correct 1052 ms 54172 KB Output is correct
81 Correct 243 ms 22892 KB Output is correct
82 Correct 247 ms 22892 KB Output is correct
83 Correct 229 ms 21996 KB Output is correct
84 Correct 202 ms 22252 KB Output is correct
85 Correct 209 ms 22508 KB Output is correct
86 Correct 193 ms 21740 KB Output is correct
87 Correct 214 ms 22160 KB Output is correct
88 Correct 212 ms 22380 KB Output is correct
89 Correct 191 ms 21996 KB Output is correct
90 Correct 155 ms 22764 KB Output is correct
91 Correct 233 ms 23120 KB Output is correct
92 Correct 222 ms 22252 KB Output is correct
93 Correct 217 ms 22000 KB Output is correct
94 Correct 210 ms 21740 KB Output is correct
95 Correct 209 ms 21780 KB Output is correct
96 Correct 189 ms 19692 KB Output is correct
97 Correct 1519 ms 65328 KB Output is correct
98 Correct 1216 ms 45840 KB Output is correct
99 Correct 1719 ms 56184 KB Output is correct
100 Correct 1468 ms 65288 KB Output is correct
101 Correct 1370 ms 60460 KB Output is correct
102 Correct 1787 ms 56920 KB Output is correct
103 Correct 1385 ms 56364 KB Output is correct
104 Correct 1488 ms 55608 KB Output is correct
105 Correct 1195 ms 55620 KB Output is correct
106 Correct 1262 ms 55444 KB Output is correct
107 Correct 1108 ms 61388 KB Output is correct
108 Correct 1139 ms 62880 KB Output is correct
109 Correct 1087 ms 60504 KB Output is correct
110 Correct 1139 ms 61360 KB Output is correct
111 Correct 1191 ms 62440 KB Output is correct
112 Correct 1082 ms 59240 KB Output is correct
113 Correct 819 ms 64112 KB Output is correct
114 Correct 1286 ms 65908 KB Output is correct
115 Correct 1265 ms 61944 KB Output is correct
116 Correct 1229 ms 60460 KB Output is correct
117 Correct 1195 ms 59728 KB Output is correct
118 Correct 1102 ms 59436 KB Output is correct
119 Correct 939 ms 49124 KB Output is correct
120 Correct 716 ms 52372 KB Output is correct
121 Correct 776 ms 54124 KB Output is correct
122 Correct 781 ms 54244 KB Output is correct
123 Correct 852 ms 55364 KB Output is correct
124 Correct 935 ms 57428 KB Output is correct
125 Correct 822 ms 55740 KB Output is correct
126 Correct 993 ms 59744 KB Output is correct