#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
const int INF = 1e9;
struct Data { int x, t, a, b; };
struct Query { int l, y, p; };
int N, K, Q, C;
Data A[MAXN*2+10];
Query query[MAXN+10];
vector<int> comp;
int ans[MAXN+10];
int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1; }
struct Line
{
int x, y;
Line() {}
Line(int x, int y) : x(x), y(y) {}
bool operator < (const Line &p) const { return pii(x, y)<pii(p.x, p.y); }
};
Line Line1(int x, int y) { return Line(x, y-x); }
Line Line2(int x, int y) { return Line(y, y-x); }
multiset<int> S[MAXN+10];
//==================================================
map<Line, pii> M1;
vector<Line> tree1[MAXN*12+10];
void update1(int node, int tl, int tr, int l, int r, Line val)
{
if(l<=tl && tr<=r) { tree1[node].push_back(val); return; }
if(r<tl || tr<l) return;
int mid=tl+tr>>1;
update1(node*2, tl, mid, l, r, val);
update1(node*2+1, mid+1, tr, l, r, val);
}
void pushLine1(int x, int y, int t)
{
return;
Line p=Line1(x, y);
if(M1[p].second==0) M1[p].first=t;
M1[p].second++;
}
void popLine1(int x, int y, int t)
{
return;
Line p=Line1(x, y);
M1[p].second--;
//if(M1[p].second==0) update1(1, 1, C, M1[p].first, t, p);
}
//==================================================
map<Line, pii> M2;
vector<Line> tree2[MAXN*12+10];
void update2(int node, int tl, int tr, int l, int r, Line val)
{
if(l<=tl && tr<=r) { tree2[node].push_back(val); return; }
if(r<tl || tr<l) return;
int mid=tl+tr>>1;
update2(node*2, tl, mid, l, r, val);
update2(node*2+1, mid+1, tr, l, r, val);
}
void pushLine2(int x, int y, int t)
{
return;
Line p=Line2(x, y);
if(M2[p].second==0) M2[p].first=t;
M2[p].second++;
}
void popLine2(int x, int y, int t)
{
return;
Line p=Line2(x, y);
M2[p].second--;
//if(M2[p].second==0) update2(1, 1, C, M2[p].first, t, p);
}
//==================================================
vector<Query> tree3[MAXN*12+10];
vector<int> tree4[MAXN*12+10];
multiset<int> SS; int cnt=0;
void update3(int node, int tl, int tr, int pos, Query val)
{
tree3[node].push_back(val);
if(tl==tr) return;
int mid=tl+tr>>1;
if(pos<=mid) update3(node*2, tl, mid, pos, val);
else update3(node*2+1, mid+1, tr, pos, val);
}
void update4(int node, int tl, int tr, int l, int r, int val)
{
if(l<=tl && tr<=r) { tree4[node].push_back(val); return; }
if(r<tl || tr<l) return;
int mid=tl+tr>>1;
update4(node*2, tl, mid, l, r, val);
update4(node*2+1, mid+1, tr, l, r, val);
}
void dfs(int node, int tl, int tr)
{
int i, j;
sort(tree1[node].begin(), tree1[node].end(), [&](const Line &p, const Line &q) { return p.x<q.x; });
sort(tree3[node].begin(), tree3[node].end(), [&](const Query &p, const Query &q) { return p.l<q.l; });
for(auto it : tree4[node])
{
if(SS.find(it)==SS.end()) cnt++;
SS.insert(it);
}
for(i=0, j=0; i<tree3[node].size(); i++)
{
Query now=tree3[node][i];
for(; j<tree1[node].size() && tree1[node][j].x<=now.l; j++)
{
Line t=tree1[node][j];
ans[now.p]=max(ans[now.p], t.y-(now.l-t.x));
}
}
sort(tree2[node].begin(), tree2[node].end(), [&](const Line &p, const Line &q) { return p.x>q.x; });
sort(tree3[node].begin(), tree3[node].end(), [&](const Query &p, const Query &q) { return p.l<q.l; });
for(i=0, j=0; i<tree3[node].size(); i++)
{
Query now=tree3[node][i];
for(; j<tree2[node].size() && tree2[node][j].x>=now.l; j++)
{
Line t=tree2[node][j];
ans[now.p]=max(ans[now.p], t.y-(t.x-now.l));
}
}
if(tl==tr)
{
if(cnt!=K) for(auto it : tree3[node]) ans[it.p]=-2;
for(auto it : tree4[node])
{
SS.erase(SS.find(it));
if(SS.find(it)==SS.end()) cnt--;
}
return;
}
int mid=tl+tr>>1;
dfs(node*2, tl, mid);
dfs(node*2+1, mid+1, tr);
for(auto it : tree4[node])
{
SS.erase(SS.find(it));
if(SS.find(it)==SS.end()) cnt--;
}
}
int main()
{
int i, j;
scanf("%d%d%d", &N, &K, &Q);
for(i=1; i<=N; i++)
{
int x, t, a, b;
scanf("%d%d%d%d", &x, &t, &a, &b); x*=2;
A[i*2-1]={x, t, a, 1};
A[i*2]={x, t, b, -1};
comp.push_back(a);
comp.push_back(b);
}
for(i=1; i<=Q; i++)
{
scanf("%d%d", &query[i].l, &query[i].y);
query[i].p=i;
comp.push_back(query[i].y); query[i].l*=2;
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
C=comp.size();
for(i=1; i<=2*N; i++) A[i].a=getcomp(A[i].a);
for(i=1; i<=N; i++) update4(1, 1, C, A[i*2-1].a, A[i*2].a, A[i*2].t);
for(i=1; i<=Q; i++) query[i].y=getcomp(query[i].y);
for(i=1; i<=Q; i++) update3(1, 1, C, query[i].y, query[i]);
sort(A+1, A+N+1, [&](const Data &p, const Data &q) { return p.a<q.a; });
for(i=1; i<=N; i++)
{
Data now=A[i];
int x, t, a, b;
x=now.x; t=now.t; a=now.a; b=now.b;
if(b==1)
{
/*
if(S[t].find(x)==S[t].end())
{
if(S[t].size()==0)
{
//pushLine1(0, x, a);
//pushLine2(x, INF, a);
}
else
{
auto it=S[t].lower_bound(x);
int l, r;
if(it==S[t].end())
{
l=*prev(it);
//popLine2(l, INF, a);
//pushLine2(l, l+x>>1, a);
//pushLine1(l+x>>1, x, a);
//pushLine2(x, INF, a);
}
else if(it==S[t].begin())
{
r=*it;
//popLine1(0, r, a);
//pushLine1(0, x, a);
//pushLine2(x, r+x>>1, a);
//pushLine1(r+x>>1, r, a);
}
else
{
r=*it, l=*prev(it);
//popLine2(l, l+r>>1, a);
//popLine1(l+r>>1, r, a);
//pushLine2(l, l+x>>1, a);
//pushLine1(l+x>>1, x, a);
//pushLine2(x, x+r>>1, a);
//pushLine1(x+r>>1, r, a);
}
}
}*/
S[t].insert(x);
}
else
{
S[t].erase(S[t].find(x));/*
if(S[t].find(x)==S[t].end())
{
if(S[t].size()==0)
{
//popLine1(0, x, a);
//popLine2(x, INF, a);
}
else
{
auto it=S[t].lower_bound(x);
int l, r;
if(it==S[t].end())
{
l=*prev(it);
//pushLine2(l, INF, a);
//popLine2(l, l+x>>1, a);
//popLine1(l+x>>1, x, a);
//popLine2(x, INF, a);
}
else if(it==S[t].begin())
{
r=*it;
//pushLine1(0, r, a);
//popLine1(0, x, a);
//popLine2(x, r+x>>1, a);
//popLine1(r+x>>1, r, a);
}
else
{
r=*it, l=*prev(it);
//pushLine2(l, l+r>>1, a);
//pushLine1(l+r>>1, r, a);
//popLine2(l, l+x>>1, a);
//popLine1(l+x>>1, x, a);
//popLine2(x, x+r>>1, a);
//popLine1(x+r>>1, r, a);
}
}
}*/
}
}
return 0;
dfs(1, 1, C);
for(i=1; i<=Q; i++) printf("%d\n", ans[i]/2);
}
Compilation message
new_home.cpp: In function 'void update1(int, int, int, int, int, Line)':
new_home.cpp:44:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
new_home.cpp: In function 'void update2(int, int, int, int, int, Line)':
new_home.cpp:74:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
new_home.cpp: In function 'void update3(int, int, int, int, Query)':
new_home.cpp:105:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
new_home.cpp: In function 'void update4(int, int, int, int, int, int)':
new_home.cpp:114:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
new_home.cpp: In function 'void dfs(int, int, int)':
new_home.cpp:131:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0, j=0; i<tree3[node].size(); i++)
~^~~~~~~~~~~~~~~~~~~
new_home.cpp:134:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; j<tree1[node].size() && tree1[node][j].x<=now.l; j++)
~^~~~~~~~~~~~~~~~~~~
new_home.cpp:144:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0, j=0; i<tree3[node].size(); i++)
~^~~~~~~~~~~~~~~~~~~
new_home.cpp:147:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; j<tree2[node].size() && tree2[node][j].x>=now.l; j++)
~^~~~~~~~~~~~~~~~~~~
new_home.cpp:166:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
new_home.cpp: In function 'int main()':
new_home.cpp:214:19: warning: variable 'a' set but not used [-Wunused-but-set-variable]
int x, t, a, b;
^
new_home.cpp:179:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
new_home.cpp:181:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &N, &K, &Q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:185:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &x, &t, &a, &b); x*=2;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:194:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &query[i].l, &query[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
1528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
1528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
3576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5 ms |
1544 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
1528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
1528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |