#include <iostream>
#include <set>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int nmax=100005;
multiset<int> s[1000];
multiset<int>::iterator it1;
vector<int> v[3*nmax];
map<int,int> m;
int dp[10*nmax],norm[10*nmax],qq[10*nmax];
struct event
{
int val,wh,mag,tip;
}ev[3*nmax];
int ans[nmax];
int ap[nmax];
int n,k,q,i,j,x,t,a,b,nr,X,mn;
bool compev(event unu,event doi)
{
if(unu.val==doi.val) return unu.tip<doi.tip;
return unu.val<doi.val;
}
int main()
{
//freopen("data.in","r",stdin);
cin>>n>>k>>q;
if(n<=60000&&k<=400)
{
for(i=1; i<=n; i++)
{
cin>>x>>t>>a>>b;
ev[++nr]= {a,x,t,1};
ev[++nr]= {b+1,x,t,-1};
}
for(i=1; i<=q; i++)
{
cin>>x>>t;
ev[++nr]= {t,x,i,2};
}
sort(ev+1,ev+nr+1,compev);
for(i=1; i<=nr; i++)
{
if(ev[i].tip==1)
{
s[ev[i].mag].insert(ev[i].wh);
}
if(ev[i].tip==-1)
{
s[ev[i].mag].erase(s[ev[i].mag].lower_bound(ev[i].wh));
}
if(ev[i].tip==2)
{
X=ev[i].wh;
for(j=1; j<=k&&ans[ev[i].mag]!=-1; j++)
{
if(s[j].empty()) ans[ev[i].mag]=-1;
else
{
mn=1000*1000*100+1;
it1=s[j].lower_bound(X);
if(it1!=s[j].end()) mn=min(mn,(*it1)-X);
if(it1!=s[j].begin())
{
it1--;
mn=min(mn,X-(*it1));
}
ans[ev[i].mag]=max(ans[ev[i].mag],mn);
}
}
}
}
for(i=1; i<=q; i++)
cout<<ans[i]<<'\n';
return 0;
}
for(i=1;i<=n;i++)
{
cin>>x>>t>>a>>b;
v[t].push_back(x);
norm[++nr]=x;
}
for(i=1;i<=q;i++)
{
cin>>qq[i]>>t;
norm[++nr]=t;
}
sort(norm+1,norm+nr+1);
for(i=1;i<=nr;i++)
m[norm[i]]=i;
bool bus=0;
int st,dr,poz,p,med;
for(i=1;i<=k;i++)
{
if(v[i].empty())
bus=1;
else
{
sort(v[i].begin(),v[i].end());
dp[1]=max(dp[1],v[i][0]-norm[1]);
dp[n]=max(dp[n],norm[n]-v[i].back());
for(j=0;j<v[i].size()-1;j++)
{
st=v[i][j];dr=v[i][j+1];
med=(v[i][j]+v[i][j+1])/2;poz=0;
for(p=20;p>=0;p--)
{
if(poz+(1<<p)<=nr&&norm[poz+(1<<p)]<=med) poz+=(1<<p);
}
dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-st));
poz++;
if(poz>=m[st]&&poz<=m[dr])dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-dr));
poz-=2;
if(poz>=m[st]&&poz<=m[dr])dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-dr));
}
}
}
for(i=2;i<=nr;i++)
dp[i]=max(dp[i-1]-norm[i]-norm[i-1],dp[i]);
for(i=nr-1;i>=1;i--)
dp[i]=max(dp[i+1]-norm[i+1]-norm[i],dp[i]);
for(i=1;i<=q;i++)
{
qq[i]=m[qq[i]];
if(bus) cout<<"-1\n";
else cout<<dp[qq[i]]<<'\n';
}
return 0;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:104:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<v[i].size()-1;j++)
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7448 KB |
Output is correct |
2 |
Correct |
7 ms |
7524 KB |
Output is correct |
3 |
Correct |
7 ms |
7524 KB |
Output is correct |
4 |
Correct |
7 ms |
7632 KB |
Output is correct |
5 |
Correct |
8 ms |
7632 KB |
Output is correct |
6 |
Correct |
9 ms |
7632 KB |
Output is correct |
7 |
Correct |
9 ms |
7708 KB |
Output is correct |
8 |
Correct |
9 ms |
7708 KB |
Output is correct |
9 |
Correct |
9 ms |
7708 KB |
Output is correct |
10 |
Correct |
9 ms |
7708 KB |
Output is correct |
11 |
Correct |
8 ms |
7708 KB |
Output is correct |
12 |
Correct |
12 ms |
7708 KB |
Output is correct |
13 |
Correct |
11 ms |
7708 KB |
Output is correct |
14 |
Correct |
11 ms |
7744 KB |
Output is correct |
15 |
Correct |
10 ms |
7744 KB |
Output is correct |
16 |
Correct |
10 ms |
7744 KB |
Output is correct |
17 |
Correct |
11 ms |
7744 KB |
Output is correct |
18 |
Correct |
9 ms |
7744 KB |
Output is correct |
19 |
Correct |
9 ms |
7744 KB |
Output is correct |
20 |
Correct |
8 ms |
7744 KB |
Output is correct |
21 |
Correct |
9 ms |
7744 KB |
Output is correct |
22 |
Correct |
9 ms |
7744 KB |
Output is correct |
23 |
Correct |
9 ms |
7744 KB |
Output is correct |
24 |
Correct |
9 ms |
7744 KB |
Output is correct |
25 |
Correct |
9 ms |
7744 KB |
Output is correct |
26 |
Correct |
9 ms |
7744 KB |
Output is correct |
27 |
Correct |
9 ms |
7848 KB |
Output is correct |
28 |
Correct |
9 ms |
7848 KB |
Output is correct |
29 |
Correct |
9 ms |
7848 KB |
Output is correct |
30 |
Correct |
9 ms |
7848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7448 KB |
Output is correct |
2 |
Correct |
7 ms |
7524 KB |
Output is correct |
3 |
Correct |
7 ms |
7524 KB |
Output is correct |
4 |
Correct |
7 ms |
7632 KB |
Output is correct |
5 |
Correct |
8 ms |
7632 KB |
Output is correct |
6 |
Correct |
9 ms |
7632 KB |
Output is correct |
7 |
Correct |
9 ms |
7708 KB |
Output is correct |
8 |
Correct |
9 ms |
7708 KB |
Output is correct |
9 |
Correct |
9 ms |
7708 KB |
Output is correct |
10 |
Correct |
9 ms |
7708 KB |
Output is correct |
11 |
Correct |
8 ms |
7708 KB |
Output is correct |
12 |
Correct |
12 ms |
7708 KB |
Output is correct |
13 |
Correct |
11 ms |
7708 KB |
Output is correct |
14 |
Correct |
11 ms |
7744 KB |
Output is correct |
15 |
Correct |
10 ms |
7744 KB |
Output is correct |
16 |
Correct |
10 ms |
7744 KB |
Output is correct |
17 |
Correct |
11 ms |
7744 KB |
Output is correct |
18 |
Correct |
9 ms |
7744 KB |
Output is correct |
19 |
Correct |
9 ms |
7744 KB |
Output is correct |
20 |
Correct |
8 ms |
7744 KB |
Output is correct |
21 |
Correct |
9 ms |
7744 KB |
Output is correct |
22 |
Correct |
9 ms |
7744 KB |
Output is correct |
23 |
Correct |
9 ms |
7744 KB |
Output is correct |
24 |
Correct |
9 ms |
7744 KB |
Output is correct |
25 |
Correct |
9 ms |
7744 KB |
Output is correct |
26 |
Correct |
9 ms |
7744 KB |
Output is correct |
27 |
Correct |
9 ms |
7848 KB |
Output is correct |
28 |
Correct |
9 ms |
7848 KB |
Output is correct |
29 |
Correct |
9 ms |
7848 KB |
Output is correct |
30 |
Correct |
9 ms |
7848 KB |
Output is correct |
31 |
Correct |
3212 ms |
13980 KB |
Output is correct |
32 |
Correct |
161 ms |
13980 KB |
Output is correct |
33 |
Correct |
326 ms |
13980 KB |
Output is correct |
34 |
Correct |
2544 ms |
13980 KB |
Output is correct |
35 |
Correct |
1839 ms |
14016 KB |
Output is correct |
36 |
Correct |
393 ms |
14016 KB |
Output is correct |
37 |
Correct |
313 ms |
14016 KB |
Output is correct |
38 |
Correct |
229 ms |
14016 KB |
Output is correct |
39 |
Correct |
233 ms |
14016 KB |
Output is correct |
40 |
Correct |
233 ms |
14016 KB |
Output is correct |
41 |
Correct |
479 ms |
14016 KB |
Output is correct |
42 |
Correct |
407 ms |
14016 KB |
Output is correct |
43 |
Correct |
628 ms |
14092 KB |
Output is correct |
44 |
Correct |
440 ms |
14092 KB |
Output is correct |
45 |
Correct |
264 ms |
14092 KB |
Output is correct |
46 |
Correct |
204 ms |
14092 KB |
Output is correct |
47 |
Correct |
204 ms |
14092 KB |
Output is correct |
48 |
Correct |
192 ms |
14092 KB |
Output is correct |
49 |
Correct |
212 ms |
14092 KB |
Output is correct |
50 |
Correct |
376 ms |
14092 KB |
Output is correct |
51 |
Correct |
259 ms |
14092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2240 ms |
59220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2149 ms |
59220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7448 KB |
Output is correct |
2 |
Correct |
7 ms |
7524 KB |
Output is correct |
3 |
Correct |
7 ms |
7524 KB |
Output is correct |
4 |
Correct |
7 ms |
7632 KB |
Output is correct |
5 |
Correct |
8 ms |
7632 KB |
Output is correct |
6 |
Correct |
9 ms |
7632 KB |
Output is correct |
7 |
Correct |
9 ms |
7708 KB |
Output is correct |
8 |
Correct |
9 ms |
7708 KB |
Output is correct |
9 |
Correct |
9 ms |
7708 KB |
Output is correct |
10 |
Correct |
9 ms |
7708 KB |
Output is correct |
11 |
Correct |
8 ms |
7708 KB |
Output is correct |
12 |
Correct |
12 ms |
7708 KB |
Output is correct |
13 |
Correct |
11 ms |
7708 KB |
Output is correct |
14 |
Correct |
11 ms |
7744 KB |
Output is correct |
15 |
Correct |
10 ms |
7744 KB |
Output is correct |
16 |
Correct |
10 ms |
7744 KB |
Output is correct |
17 |
Correct |
11 ms |
7744 KB |
Output is correct |
18 |
Correct |
9 ms |
7744 KB |
Output is correct |
19 |
Correct |
9 ms |
7744 KB |
Output is correct |
20 |
Correct |
8 ms |
7744 KB |
Output is correct |
21 |
Correct |
9 ms |
7744 KB |
Output is correct |
22 |
Correct |
9 ms |
7744 KB |
Output is correct |
23 |
Correct |
9 ms |
7744 KB |
Output is correct |
24 |
Correct |
9 ms |
7744 KB |
Output is correct |
25 |
Correct |
9 ms |
7744 KB |
Output is correct |
26 |
Correct |
9 ms |
7744 KB |
Output is correct |
27 |
Correct |
9 ms |
7848 KB |
Output is correct |
28 |
Correct |
9 ms |
7848 KB |
Output is correct |
29 |
Correct |
9 ms |
7848 KB |
Output is correct |
30 |
Correct |
9 ms |
7848 KB |
Output is correct |
31 |
Correct |
3212 ms |
13980 KB |
Output is correct |
32 |
Correct |
161 ms |
13980 KB |
Output is correct |
33 |
Correct |
326 ms |
13980 KB |
Output is correct |
34 |
Correct |
2544 ms |
13980 KB |
Output is correct |
35 |
Correct |
1839 ms |
14016 KB |
Output is correct |
36 |
Correct |
393 ms |
14016 KB |
Output is correct |
37 |
Correct |
313 ms |
14016 KB |
Output is correct |
38 |
Correct |
229 ms |
14016 KB |
Output is correct |
39 |
Correct |
233 ms |
14016 KB |
Output is correct |
40 |
Correct |
233 ms |
14016 KB |
Output is correct |
41 |
Correct |
479 ms |
14016 KB |
Output is correct |
42 |
Correct |
407 ms |
14016 KB |
Output is correct |
43 |
Correct |
628 ms |
14092 KB |
Output is correct |
44 |
Correct |
440 ms |
14092 KB |
Output is correct |
45 |
Correct |
264 ms |
14092 KB |
Output is correct |
46 |
Correct |
204 ms |
14092 KB |
Output is correct |
47 |
Correct |
204 ms |
14092 KB |
Output is correct |
48 |
Correct |
192 ms |
14092 KB |
Output is correct |
49 |
Correct |
212 ms |
14092 KB |
Output is correct |
50 |
Correct |
376 ms |
14092 KB |
Output is correct |
51 |
Correct |
259 ms |
14092 KB |
Output is correct |
52 |
Incorrect |
276 ms |
59220 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7448 KB |
Output is correct |
2 |
Correct |
7 ms |
7524 KB |
Output is correct |
3 |
Correct |
7 ms |
7524 KB |
Output is correct |
4 |
Correct |
7 ms |
7632 KB |
Output is correct |
5 |
Correct |
8 ms |
7632 KB |
Output is correct |
6 |
Correct |
9 ms |
7632 KB |
Output is correct |
7 |
Correct |
9 ms |
7708 KB |
Output is correct |
8 |
Correct |
9 ms |
7708 KB |
Output is correct |
9 |
Correct |
9 ms |
7708 KB |
Output is correct |
10 |
Correct |
9 ms |
7708 KB |
Output is correct |
11 |
Correct |
8 ms |
7708 KB |
Output is correct |
12 |
Correct |
12 ms |
7708 KB |
Output is correct |
13 |
Correct |
11 ms |
7708 KB |
Output is correct |
14 |
Correct |
11 ms |
7744 KB |
Output is correct |
15 |
Correct |
10 ms |
7744 KB |
Output is correct |
16 |
Correct |
10 ms |
7744 KB |
Output is correct |
17 |
Correct |
11 ms |
7744 KB |
Output is correct |
18 |
Correct |
9 ms |
7744 KB |
Output is correct |
19 |
Correct |
9 ms |
7744 KB |
Output is correct |
20 |
Correct |
8 ms |
7744 KB |
Output is correct |
21 |
Correct |
9 ms |
7744 KB |
Output is correct |
22 |
Correct |
9 ms |
7744 KB |
Output is correct |
23 |
Correct |
9 ms |
7744 KB |
Output is correct |
24 |
Correct |
9 ms |
7744 KB |
Output is correct |
25 |
Correct |
9 ms |
7744 KB |
Output is correct |
26 |
Correct |
9 ms |
7744 KB |
Output is correct |
27 |
Correct |
9 ms |
7848 KB |
Output is correct |
28 |
Correct |
9 ms |
7848 KB |
Output is correct |
29 |
Correct |
9 ms |
7848 KB |
Output is correct |
30 |
Correct |
9 ms |
7848 KB |
Output is correct |
31 |
Correct |
3212 ms |
13980 KB |
Output is correct |
32 |
Correct |
161 ms |
13980 KB |
Output is correct |
33 |
Correct |
326 ms |
13980 KB |
Output is correct |
34 |
Correct |
2544 ms |
13980 KB |
Output is correct |
35 |
Correct |
1839 ms |
14016 KB |
Output is correct |
36 |
Correct |
393 ms |
14016 KB |
Output is correct |
37 |
Correct |
313 ms |
14016 KB |
Output is correct |
38 |
Correct |
229 ms |
14016 KB |
Output is correct |
39 |
Correct |
233 ms |
14016 KB |
Output is correct |
40 |
Correct |
233 ms |
14016 KB |
Output is correct |
41 |
Correct |
479 ms |
14016 KB |
Output is correct |
42 |
Correct |
407 ms |
14016 KB |
Output is correct |
43 |
Correct |
628 ms |
14092 KB |
Output is correct |
44 |
Correct |
440 ms |
14092 KB |
Output is correct |
45 |
Correct |
264 ms |
14092 KB |
Output is correct |
46 |
Correct |
204 ms |
14092 KB |
Output is correct |
47 |
Correct |
204 ms |
14092 KB |
Output is correct |
48 |
Correct |
192 ms |
14092 KB |
Output is correct |
49 |
Correct |
212 ms |
14092 KB |
Output is correct |
50 |
Correct |
376 ms |
14092 KB |
Output is correct |
51 |
Correct |
259 ms |
14092 KB |
Output is correct |
52 |
Incorrect |
2240 ms |
59220 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |