#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[nr]=max(dp[nr],norm[nr]-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>=1&&poz<=nr&&norm[poz]>=st&&norm[poz]<=dr)dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-st));
poz-=2;
if(poz>=1&&poz<=nr&&norm[poz]>=st&&norm[poz]<=dr)dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-st));
}
}
}
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 |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7572 KB |
Output is correct |
3 |
Correct |
7 ms |
7572 KB |
Output is correct |
4 |
Correct |
7 ms |
7572 KB |
Output is correct |
5 |
Correct |
9 ms |
7772 KB |
Output is correct |
6 |
Correct |
9 ms |
7772 KB |
Output is correct |
7 |
Correct |
9 ms |
7772 KB |
Output is correct |
8 |
Correct |
9 ms |
7772 KB |
Output is correct |
9 |
Correct |
9 ms |
7772 KB |
Output is correct |
10 |
Correct |
9 ms |
7772 KB |
Output is correct |
11 |
Correct |
9 ms |
7772 KB |
Output is correct |
12 |
Correct |
9 ms |
7772 KB |
Output is correct |
13 |
Correct |
9 ms |
7772 KB |
Output is correct |
14 |
Correct |
8 ms |
7772 KB |
Output is correct |
15 |
Correct |
10 ms |
7772 KB |
Output is correct |
16 |
Correct |
10 ms |
7772 KB |
Output is correct |
17 |
Correct |
9 ms |
7772 KB |
Output is correct |
18 |
Correct |
9 ms |
7772 KB |
Output is correct |
19 |
Correct |
9 ms |
7772 KB |
Output is correct |
20 |
Correct |
9 ms |
7772 KB |
Output is correct |
21 |
Correct |
9 ms |
7772 KB |
Output is correct |
22 |
Correct |
9 ms |
7772 KB |
Output is correct |
23 |
Correct |
10 ms |
7772 KB |
Output is correct |
24 |
Correct |
9 ms |
7772 KB |
Output is correct |
25 |
Correct |
9 ms |
7772 KB |
Output is correct |
26 |
Correct |
9 ms |
7772 KB |
Output is correct |
27 |
Correct |
8 ms |
7772 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
29 |
Correct |
9 ms |
7772 KB |
Output is correct |
30 |
Correct |
9 ms |
7772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7572 KB |
Output is correct |
3 |
Correct |
7 ms |
7572 KB |
Output is correct |
4 |
Correct |
7 ms |
7572 KB |
Output is correct |
5 |
Correct |
9 ms |
7772 KB |
Output is correct |
6 |
Correct |
9 ms |
7772 KB |
Output is correct |
7 |
Correct |
9 ms |
7772 KB |
Output is correct |
8 |
Correct |
9 ms |
7772 KB |
Output is correct |
9 |
Correct |
9 ms |
7772 KB |
Output is correct |
10 |
Correct |
9 ms |
7772 KB |
Output is correct |
11 |
Correct |
9 ms |
7772 KB |
Output is correct |
12 |
Correct |
9 ms |
7772 KB |
Output is correct |
13 |
Correct |
9 ms |
7772 KB |
Output is correct |
14 |
Correct |
8 ms |
7772 KB |
Output is correct |
15 |
Correct |
10 ms |
7772 KB |
Output is correct |
16 |
Correct |
10 ms |
7772 KB |
Output is correct |
17 |
Correct |
9 ms |
7772 KB |
Output is correct |
18 |
Correct |
9 ms |
7772 KB |
Output is correct |
19 |
Correct |
9 ms |
7772 KB |
Output is correct |
20 |
Correct |
9 ms |
7772 KB |
Output is correct |
21 |
Correct |
9 ms |
7772 KB |
Output is correct |
22 |
Correct |
9 ms |
7772 KB |
Output is correct |
23 |
Correct |
10 ms |
7772 KB |
Output is correct |
24 |
Correct |
9 ms |
7772 KB |
Output is correct |
25 |
Correct |
9 ms |
7772 KB |
Output is correct |
26 |
Correct |
9 ms |
7772 KB |
Output is correct |
27 |
Correct |
8 ms |
7772 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
29 |
Correct |
9 ms |
7772 KB |
Output is correct |
30 |
Correct |
9 ms |
7772 KB |
Output is correct |
31 |
Correct |
3157 ms |
14248 KB |
Output is correct |
32 |
Correct |
164 ms |
14248 KB |
Output is correct |
33 |
Correct |
346 ms |
14248 KB |
Output is correct |
34 |
Correct |
2683 ms |
14248 KB |
Output is correct |
35 |
Correct |
1494 ms |
14248 KB |
Output is correct |
36 |
Correct |
388 ms |
14248 KB |
Output is correct |
37 |
Correct |
350 ms |
14248 KB |
Output is correct |
38 |
Correct |
242 ms |
14248 KB |
Output is correct |
39 |
Correct |
248 ms |
14248 KB |
Output is correct |
40 |
Correct |
271 ms |
14248 KB |
Output is correct |
41 |
Correct |
513 ms |
14248 KB |
Output is correct |
42 |
Correct |
417 ms |
14248 KB |
Output is correct |
43 |
Correct |
593 ms |
14248 KB |
Output is correct |
44 |
Correct |
436 ms |
14248 KB |
Output is correct |
45 |
Correct |
268 ms |
14248 KB |
Output is correct |
46 |
Correct |
225 ms |
14248 KB |
Output is correct |
47 |
Correct |
191 ms |
14248 KB |
Output is correct |
48 |
Correct |
209 ms |
14248 KB |
Output is correct |
49 |
Correct |
217 ms |
14248 KB |
Output is correct |
50 |
Correct |
425 ms |
14248 KB |
Output is correct |
51 |
Correct |
203 ms |
14248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1671 ms |
59312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1712 ms |
59312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7572 KB |
Output is correct |
3 |
Correct |
7 ms |
7572 KB |
Output is correct |
4 |
Correct |
7 ms |
7572 KB |
Output is correct |
5 |
Correct |
9 ms |
7772 KB |
Output is correct |
6 |
Correct |
9 ms |
7772 KB |
Output is correct |
7 |
Correct |
9 ms |
7772 KB |
Output is correct |
8 |
Correct |
9 ms |
7772 KB |
Output is correct |
9 |
Correct |
9 ms |
7772 KB |
Output is correct |
10 |
Correct |
9 ms |
7772 KB |
Output is correct |
11 |
Correct |
9 ms |
7772 KB |
Output is correct |
12 |
Correct |
9 ms |
7772 KB |
Output is correct |
13 |
Correct |
9 ms |
7772 KB |
Output is correct |
14 |
Correct |
8 ms |
7772 KB |
Output is correct |
15 |
Correct |
10 ms |
7772 KB |
Output is correct |
16 |
Correct |
10 ms |
7772 KB |
Output is correct |
17 |
Correct |
9 ms |
7772 KB |
Output is correct |
18 |
Correct |
9 ms |
7772 KB |
Output is correct |
19 |
Correct |
9 ms |
7772 KB |
Output is correct |
20 |
Correct |
9 ms |
7772 KB |
Output is correct |
21 |
Correct |
9 ms |
7772 KB |
Output is correct |
22 |
Correct |
9 ms |
7772 KB |
Output is correct |
23 |
Correct |
10 ms |
7772 KB |
Output is correct |
24 |
Correct |
9 ms |
7772 KB |
Output is correct |
25 |
Correct |
9 ms |
7772 KB |
Output is correct |
26 |
Correct |
9 ms |
7772 KB |
Output is correct |
27 |
Correct |
8 ms |
7772 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
29 |
Correct |
9 ms |
7772 KB |
Output is correct |
30 |
Correct |
9 ms |
7772 KB |
Output is correct |
31 |
Correct |
3157 ms |
14248 KB |
Output is correct |
32 |
Correct |
164 ms |
14248 KB |
Output is correct |
33 |
Correct |
346 ms |
14248 KB |
Output is correct |
34 |
Correct |
2683 ms |
14248 KB |
Output is correct |
35 |
Correct |
1494 ms |
14248 KB |
Output is correct |
36 |
Correct |
388 ms |
14248 KB |
Output is correct |
37 |
Correct |
350 ms |
14248 KB |
Output is correct |
38 |
Correct |
242 ms |
14248 KB |
Output is correct |
39 |
Correct |
248 ms |
14248 KB |
Output is correct |
40 |
Correct |
271 ms |
14248 KB |
Output is correct |
41 |
Correct |
513 ms |
14248 KB |
Output is correct |
42 |
Correct |
417 ms |
14248 KB |
Output is correct |
43 |
Correct |
593 ms |
14248 KB |
Output is correct |
44 |
Correct |
436 ms |
14248 KB |
Output is correct |
45 |
Correct |
268 ms |
14248 KB |
Output is correct |
46 |
Correct |
225 ms |
14248 KB |
Output is correct |
47 |
Correct |
191 ms |
14248 KB |
Output is correct |
48 |
Correct |
209 ms |
14248 KB |
Output is correct |
49 |
Correct |
217 ms |
14248 KB |
Output is correct |
50 |
Correct |
425 ms |
14248 KB |
Output is correct |
51 |
Correct |
203 ms |
14248 KB |
Output is correct |
52 |
Incorrect |
320 ms |
59312 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7572 KB |
Output is correct |
3 |
Correct |
7 ms |
7572 KB |
Output is correct |
4 |
Correct |
7 ms |
7572 KB |
Output is correct |
5 |
Correct |
9 ms |
7772 KB |
Output is correct |
6 |
Correct |
9 ms |
7772 KB |
Output is correct |
7 |
Correct |
9 ms |
7772 KB |
Output is correct |
8 |
Correct |
9 ms |
7772 KB |
Output is correct |
9 |
Correct |
9 ms |
7772 KB |
Output is correct |
10 |
Correct |
9 ms |
7772 KB |
Output is correct |
11 |
Correct |
9 ms |
7772 KB |
Output is correct |
12 |
Correct |
9 ms |
7772 KB |
Output is correct |
13 |
Correct |
9 ms |
7772 KB |
Output is correct |
14 |
Correct |
8 ms |
7772 KB |
Output is correct |
15 |
Correct |
10 ms |
7772 KB |
Output is correct |
16 |
Correct |
10 ms |
7772 KB |
Output is correct |
17 |
Correct |
9 ms |
7772 KB |
Output is correct |
18 |
Correct |
9 ms |
7772 KB |
Output is correct |
19 |
Correct |
9 ms |
7772 KB |
Output is correct |
20 |
Correct |
9 ms |
7772 KB |
Output is correct |
21 |
Correct |
9 ms |
7772 KB |
Output is correct |
22 |
Correct |
9 ms |
7772 KB |
Output is correct |
23 |
Correct |
10 ms |
7772 KB |
Output is correct |
24 |
Correct |
9 ms |
7772 KB |
Output is correct |
25 |
Correct |
9 ms |
7772 KB |
Output is correct |
26 |
Correct |
9 ms |
7772 KB |
Output is correct |
27 |
Correct |
8 ms |
7772 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
29 |
Correct |
9 ms |
7772 KB |
Output is correct |
30 |
Correct |
9 ms |
7772 KB |
Output is correct |
31 |
Correct |
3157 ms |
14248 KB |
Output is correct |
32 |
Correct |
164 ms |
14248 KB |
Output is correct |
33 |
Correct |
346 ms |
14248 KB |
Output is correct |
34 |
Correct |
2683 ms |
14248 KB |
Output is correct |
35 |
Correct |
1494 ms |
14248 KB |
Output is correct |
36 |
Correct |
388 ms |
14248 KB |
Output is correct |
37 |
Correct |
350 ms |
14248 KB |
Output is correct |
38 |
Correct |
242 ms |
14248 KB |
Output is correct |
39 |
Correct |
248 ms |
14248 KB |
Output is correct |
40 |
Correct |
271 ms |
14248 KB |
Output is correct |
41 |
Correct |
513 ms |
14248 KB |
Output is correct |
42 |
Correct |
417 ms |
14248 KB |
Output is correct |
43 |
Correct |
593 ms |
14248 KB |
Output is correct |
44 |
Correct |
436 ms |
14248 KB |
Output is correct |
45 |
Correct |
268 ms |
14248 KB |
Output is correct |
46 |
Correct |
225 ms |
14248 KB |
Output is correct |
47 |
Correct |
191 ms |
14248 KB |
Output is correct |
48 |
Correct |
209 ms |
14248 KB |
Output is correct |
49 |
Correct |
217 ms |
14248 KB |
Output is correct |
50 |
Correct |
425 ms |
14248 KB |
Output is correct |
51 |
Correct |
203 ms |
14248 KB |
Output is correct |
52 |
Incorrect |
1671 ms |
59312 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |