#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXT = 3e6,MAXN = 3e5+1;
int n,q,k;
vector<int>ans(MAXN,-1),T1,T2;
multiset<int,greater<int>>lines[MAXT],lines2[MAXT];
map<int,int>crd;
int N;
void upd1(int v,int l,int r,int pos){
if(l==r){
if(lines[l].empty())T1[v] = -1e9;
else T1[v] = *lines[l].begin();
return;
}
int tm = (l+r)/2;
if(pos<=tm)upd1(2*v,l,tm,pos);
else upd1(2*v+1,tm+1,r,pos);
T1[v] = max(T1[2*v],T1[2*v+1]);
}
int query1(int v,int l,int r,int tl,int tr){
if(l>r)return -1e9;
if(l==tl && r==tr)return T1[v];
int tm = (tl+tr)/2;
return max(query1(2*v,l,min(r,tm),tl,tm),
query1(2*v+1,max(l,tm+1),r,tm+1,tr));
}
void upd2(int v,int l,int r,int pos){
if(l==r){
if(lines2[l].empty())T2[v] = -1e9;
else T2[v] = *lines2[l].begin();
return;
}
int tm = (l+r)/2;
if(pos<=tm)upd2(2*v,l,tm,pos);
else upd2(2*v+1,tm+1,r,pos);
T2[v] = max(T2[2*v],T2[2*v+1]);
}
int query2(int v,int l,int r,int tl,int tr){
if(l>r)return -1e9;
if(l==tl && r==tr)return T2[v];
int tm = (tl+tr)/2;
return max(query2(2*v,l,min(r,tm),tl,tm),
query2(2*v+1,max(l,tm+1),r,tm+1,tr));
}
int fl(int a,int b){
if(a+b>=0)return (a+b)/2;
else return (a+b-1)/2;
}
int ci(int a,int b){
if(a+b>=0)return (a+b+1)/2;
else return (a+b)/2;
}
void change(int l,int r,bool mode){
int x = ci(l,r);
int y = r - x;
int i = crd[x];
if(mode)lines[i].insert(x+y);
else lines[i].erase(lines[i].find(x+y));
upd1(1,0,N,i);
x = fl(l,r);
i = crd[x];
if(mode)lines2[i].insert(-l);
else lines2[i].erase(lines2[i].find(-l));
upd2(1,0,N,i);
}
vector<pii>sweep;
vector<int>comp;
void addcomp(int a,int b){
int x = ci(a,b);
int y = fl(a,b);
comp.pb(x);
if(x!=y)comp.pb(y);
}
void solve(){
vector<multiset<int>>store(k+1);
//coordinate compress
for(int i=1;i<=k;i++){
store[i].insert(-1e8);
store[i].insert(2e8);
}
for(auto z:sweep){
int t = z.fi;
int x = z.se;
if(t > k){
comp.pb(x);
continue;
}
if(t>0){
if(store[t].find(x) != store[t].end()){
store[t].insert(x);
continue;
}
auto r = store[t].lb(x);
auto l = r;
l--;
addcomp(*l,x);
addcomp(x,*r);
store[t].insert(x);
}else{
t*=-1;
store[t].erase(store[t].find(x));
if(store[t].find(x) != store[t].end())continue;
auto r = store[t].lb(x);
auto l = r;
l--;
addcomp(*l,*r);
}
}
comp.pb(5e7);
sort(all(comp));
comp.resize(unique(all(comp)) - comp.begin());
for(int i=0;i<sz(comp);i++)crd[comp[i]] = i;
N = sz(comp)-1;
T1.assign(4*(N+1),-1e9);
T2.assign(4*(N+1),-1e9);
for(int i=1;i<=k;i++)change(-1e8,2e8,1);
//cout<<"TES"<<'\n';
for(auto z : sweep){
int t = z.fi;
int x = z.se;
if(t > k){
t-=k+1;
//cout<<"query "<<x<<" "<<crd[x]<<" "<<query1(1,0,crd[x],0,N)<<" "<<query2(1,crd[x],N,0,N)<<'\n';
ans[t] = max(ans[t],query1(1,0,crd[x],0,N) - x);
ans[t] = max(ans[t],query2(1,crd[x],N,0,N) + x);
continue;
}
if(t>0){
if(store[t].find(x) != store[t].end()){
store[t].insert(x);
continue;
}
auto r = store[t].lb(x);
auto l = r;
l--;
change(*l,x,1);
change(x,*r,1);
change(*l,*r,0);
store[t].insert(x);
}else{
t*=-1;
store[t].erase(store[t].find(x));
if(store[t].find(x) != store[t].end())continue;
auto r = store[t].lb(x);
auto l = r;
l--;
change(*l,*r,1);
change(x,*r,0);
change(*l,x,0);
}
}
for(int i=0;i<N;i++)lines[i].clear();
comp.clear();
crd.clear();
}
int main()
{
owo
map<int,vector<pii>>pt;
cin>>n>>k>>q;
for(int i=0;i<n;i++){
int x,t,a,b;
cin>>x>>t>>a>>b;
pt[a].pb({t,x}); //add
pt[b+1].pb({-t,x}); //remove
}
for(int i=0;i<q;i++){
int l,y;
cin>>l>>y;
pt[y].pb({i+k+1,l});
}
for(auto z:pt){
for(auto x:z.se){if(x.fi <= k)sweep.pb(x);}
for(auto x:z.se){if(x.fi > k)sweep.pb(x);}
}
solve();
for(int i=0;i<q;i++){
if(ans[i]>=1e8)ans[i] = -1;
cout<<ans[i]<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
283224 KB |
Output is correct |
2 |
Correct |
75 ms |
283220 KB |
Output is correct |
3 |
Correct |
74 ms |
283220 KB |
Output is correct |
4 |
Correct |
75 ms |
283220 KB |
Output is correct |
5 |
Correct |
77 ms |
283232 KB |
Output is correct |
6 |
Correct |
76 ms |
283728 KB |
Output is correct |
7 |
Correct |
77 ms |
283732 KB |
Output is correct |
8 |
Correct |
77 ms |
283728 KB |
Output is correct |
9 |
Correct |
77 ms |
283732 KB |
Output is correct |
10 |
Correct |
83 ms |
283732 KB |
Output is correct |
11 |
Correct |
76 ms |
283728 KB |
Output is correct |
12 |
Correct |
78 ms |
283660 KB |
Output is correct |
13 |
Correct |
76 ms |
283472 KB |
Output is correct |
14 |
Correct |
78 ms |
283476 KB |
Output is correct |
15 |
Correct |
80 ms |
283988 KB |
Output is correct |
16 |
Correct |
76 ms |
283728 KB |
Output is correct |
17 |
Correct |
78 ms |
283732 KB |
Output is correct |
18 |
Correct |
76 ms |
283728 KB |
Output is correct |
19 |
Correct |
80 ms |
283732 KB |
Output is correct |
20 |
Correct |
78 ms |
283636 KB |
Output is correct |
21 |
Correct |
77 ms |
283532 KB |
Output is correct |
22 |
Correct |
77 ms |
283732 KB |
Output is correct |
23 |
Correct |
76 ms |
283644 KB |
Output is correct |
24 |
Correct |
79 ms |
283648 KB |
Output is correct |
25 |
Correct |
77 ms |
283736 KB |
Output is correct |
26 |
Correct |
79 ms |
283636 KB |
Output is correct |
27 |
Correct |
77 ms |
283476 KB |
Output is correct |
28 |
Correct |
79 ms |
283732 KB |
Output is correct |
29 |
Correct |
81 ms |
283676 KB |
Output is correct |
30 |
Correct |
78 ms |
283664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
283224 KB |
Output is correct |
2 |
Correct |
75 ms |
283220 KB |
Output is correct |
3 |
Correct |
74 ms |
283220 KB |
Output is correct |
4 |
Correct |
75 ms |
283220 KB |
Output is correct |
5 |
Correct |
77 ms |
283232 KB |
Output is correct |
6 |
Correct |
76 ms |
283728 KB |
Output is correct |
7 |
Correct |
77 ms |
283732 KB |
Output is correct |
8 |
Correct |
77 ms |
283728 KB |
Output is correct |
9 |
Correct |
77 ms |
283732 KB |
Output is correct |
10 |
Correct |
83 ms |
283732 KB |
Output is correct |
11 |
Correct |
76 ms |
283728 KB |
Output is correct |
12 |
Correct |
78 ms |
283660 KB |
Output is correct |
13 |
Correct |
76 ms |
283472 KB |
Output is correct |
14 |
Correct |
78 ms |
283476 KB |
Output is correct |
15 |
Correct |
80 ms |
283988 KB |
Output is correct |
16 |
Correct |
76 ms |
283728 KB |
Output is correct |
17 |
Correct |
78 ms |
283732 KB |
Output is correct |
18 |
Correct |
76 ms |
283728 KB |
Output is correct |
19 |
Correct |
80 ms |
283732 KB |
Output is correct |
20 |
Correct |
78 ms |
283636 KB |
Output is correct |
21 |
Correct |
77 ms |
283532 KB |
Output is correct |
22 |
Correct |
77 ms |
283732 KB |
Output is correct |
23 |
Correct |
76 ms |
283644 KB |
Output is correct |
24 |
Correct |
79 ms |
283648 KB |
Output is correct |
25 |
Correct |
77 ms |
283736 KB |
Output is correct |
26 |
Correct |
79 ms |
283636 KB |
Output is correct |
27 |
Correct |
77 ms |
283476 KB |
Output is correct |
28 |
Correct |
79 ms |
283732 KB |
Output is correct |
29 |
Correct |
81 ms |
283676 KB |
Output is correct |
30 |
Correct |
78 ms |
283664 KB |
Output is correct |
31 |
Correct |
1185 ms |
339648 KB |
Output is correct |
32 |
Correct |
148 ms |
288072 KB |
Output is correct |
33 |
Correct |
1086 ms |
333636 KB |
Output is correct |
34 |
Correct |
1012 ms |
333520 KB |
Output is correct |
35 |
Correct |
1212 ms |
339648 KB |
Output is correct |
36 |
Correct |
1144 ms |
339320 KB |
Output is correct |
37 |
Correct |
659 ms |
331000 KB |
Output is correct |
38 |
Correct |
679 ms |
331248 KB |
Output is correct |
39 |
Correct |
570 ms |
330580 KB |
Output is correct |
40 |
Correct |
586 ms |
330492 KB |
Output is correct |
41 |
Correct |
836 ms |
332112 KB |
Output is correct |
42 |
Correct |
889 ms |
332168 KB |
Output is correct |
43 |
Correct |
120 ms |
289972 KB |
Output is correct |
44 |
Correct |
851 ms |
332240 KB |
Output is correct |
45 |
Correct |
852 ms |
332204 KB |
Output is correct |
46 |
Correct |
815 ms |
332240 KB |
Output is correct |
47 |
Correct |
491 ms |
329156 KB |
Output is correct |
48 |
Correct |
477 ms |
329240 KB |
Output is correct |
49 |
Correct |
570 ms |
330516 KB |
Output is correct |
50 |
Correct |
586 ms |
331160 KB |
Output is correct |
51 |
Correct |
548 ms |
330440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5047 ms |
514732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
532812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
283224 KB |
Output is correct |
2 |
Correct |
75 ms |
283220 KB |
Output is correct |
3 |
Correct |
74 ms |
283220 KB |
Output is correct |
4 |
Correct |
75 ms |
283220 KB |
Output is correct |
5 |
Correct |
77 ms |
283232 KB |
Output is correct |
6 |
Correct |
76 ms |
283728 KB |
Output is correct |
7 |
Correct |
77 ms |
283732 KB |
Output is correct |
8 |
Correct |
77 ms |
283728 KB |
Output is correct |
9 |
Correct |
77 ms |
283732 KB |
Output is correct |
10 |
Correct |
83 ms |
283732 KB |
Output is correct |
11 |
Correct |
76 ms |
283728 KB |
Output is correct |
12 |
Correct |
78 ms |
283660 KB |
Output is correct |
13 |
Correct |
76 ms |
283472 KB |
Output is correct |
14 |
Correct |
78 ms |
283476 KB |
Output is correct |
15 |
Correct |
80 ms |
283988 KB |
Output is correct |
16 |
Correct |
76 ms |
283728 KB |
Output is correct |
17 |
Correct |
78 ms |
283732 KB |
Output is correct |
18 |
Correct |
76 ms |
283728 KB |
Output is correct |
19 |
Correct |
80 ms |
283732 KB |
Output is correct |
20 |
Correct |
78 ms |
283636 KB |
Output is correct |
21 |
Correct |
77 ms |
283532 KB |
Output is correct |
22 |
Correct |
77 ms |
283732 KB |
Output is correct |
23 |
Correct |
76 ms |
283644 KB |
Output is correct |
24 |
Correct |
79 ms |
283648 KB |
Output is correct |
25 |
Correct |
77 ms |
283736 KB |
Output is correct |
26 |
Correct |
79 ms |
283636 KB |
Output is correct |
27 |
Correct |
77 ms |
283476 KB |
Output is correct |
28 |
Correct |
79 ms |
283732 KB |
Output is correct |
29 |
Correct |
81 ms |
283676 KB |
Output is correct |
30 |
Correct |
78 ms |
283664 KB |
Output is correct |
31 |
Correct |
1185 ms |
339648 KB |
Output is correct |
32 |
Correct |
148 ms |
288072 KB |
Output is correct |
33 |
Correct |
1086 ms |
333636 KB |
Output is correct |
34 |
Correct |
1012 ms |
333520 KB |
Output is correct |
35 |
Correct |
1212 ms |
339648 KB |
Output is correct |
36 |
Correct |
1144 ms |
339320 KB |
Output is correct |
37 |
Correct |
659 ms |
331000 KB |
Output is correct |
38 |
Correct |
679 ms |
331248 KB |
Output is correct |
39 |
Correct |
570 ms |
330580 KB |
Output is correct |
40 |
Correct |
586 ms |
330492 KB |
Output is correct |
41 |
Correct |
836 ms |
332112 KB |
Output is correct |
42 |
Correct |
889 ms |
332168 KB |
Output is correct |
43 |
Correct |
120 ms |
289972 KB |
Output is correct |
44 |
Correct |
851 ms |
332240 KB |
Output is correct |
45 |
Correct |
852 ms |
332204 KB |
Output is correct |
46 |
Correct |
815 ms |
332240 KB |
Output is correct |
47 |
Correct |
491 ms |
329156 KB |
Output is correct |
48 |
Correct |
477 ms |
329240 KB |
Output is correct |
49 |
Correct |
570 ms |
330516 KB |
Output is correct |
50 |
Correct |
586 ms |
331160 KB |
Output is correct |
51 |
Correct |
548 ms |
330440 KB |
Output is correct |
52 |
Correct |
1027 ms |
347056 KB |
Output is correct |
53 |
Correct |
956 ms |
341640 KB |
Output is correct |
54 |
Correct |
1138 ms |
340848 KB |
Output is correct |
55 |
Correct |
835 ms |
337224 KB |
Output is correct |
56 |
Correct |
820 ms |
339180 KB |
Output is correct |
57 |
Correct |
863 ms |
333768 KB |
Output is correct |
58 |
Correct |
904 ms |
337288 KB |
Output is correct |
59 |
Correct |
975 ms |
339656 KB |
Output is correct |
60 |
Correct |
891 ms |
333508 KB |
Output is correct |
61 |
Correct |
226 ms |
309736 KB |
Output is correct |
62 |
Correct |
1025 ms |
347068 KB |
Output is correct |
63 |
Correct |
1131 ms |
342268 KB |
Output is correct |
64 |
Correct |
1183 ms |
340164 KB |
Output is correct |
65 |
Correct |
1134 ms |
334740 KB |
Output is correct |
66 |
Correct |
936 ms |
332236 KB |
Output is correct |
67 |
Correct |
287 ms |
291388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
283224 KB |
Output is correct |
2 |
Correct |
75 ms |
283220 KB |
Output is correct |
3 |
Correct |
74 ms |
283220 KB |
Output is correct |
4 |
Correct |
75 ms |
283220 KB |
Output is correct |
5 |
Correct |
77 ms |
283232 KB |
Output is correct |
6 |
Correct |
76 ms |
283728 KB |
Output is correct |
7 |
Correct |
77 ms |
283732 KB |
Output is correct |
8 |
Correct |
77 ms |
283728 KB |
Output is correct |
9 |
Correct |
77 ms |
283732 KB |
Output is correct |
10 |
Correct |
83 ms |
283732 KB |
Output is correct |
11 |
Correct |
76 ms |
283728 KB |
Output is correct |
12 |
Correct |
78 ms |
283660 KB |
Output is correct |
13 |
Correct |
76 ms |
283472 KB |
Output is correct |
14 |
Correct |
78 ms |
283476 KB |
Output is correct |
15 |
Correct |
80 ms |
283988 KB |
Output is correct |
16 |
Correct |
76 ms |
283728 KB |
Output is correct |
17 |
Correct |
78 ms |
283732 KB |
Output is correct |
18 |
Correct |
76 ms |
283728 KB |
Output is correct |
19 |
Correct |
80 ms |
283732 KB |
Output is correct |
20 |
Correct |
78 ms |
283636 KB |
Output is correct |
21 |
Correct |
77 ms |
283532 KB |
Output is correct |
22 |
Correct |
77 ms |
283732 KB |
Output is correct |
23 |
Correct |
76 ms |
283644 KB |
Output is correct |
24 |
Correct |
79 ms |
283648 KB |
Output is correct |
25 |
Correct |
77 ms |
283736 KB |
Output is correct |
26 |
Correct |
79 ms |
283636 KB |
Output is correct |
27 |
Correct |
77 ms |
283476 KB |
Output is correct |
28 |
Correct |
79 ms |
283732 KB |
Output is correct |
29 |
Correct |
81 ms |
283676 KB |
Output is correct |
30 |
Correct |
78 ms |
283664 KB |
Output is correct |
31 |
Correct |
1185 ms |
339648 KB |
Output is correct |
32 |
Correct |
148 ms |
288072 KB |
Output is correct |
33 |
Correct |
1086 ms |
333636 KB |
Output is correct |
34 |
Correct |
1012 ms |
333520 KB |
Output is correct |
35 |
Correct |
1212 ms |
339648 KB |
Output is correct |
36 |
Correct |
1144 ms |
339320 KB |
Output is correct |
37 |
Correct |
659 ms |
331000 KB |
Output is correct |
38 |
Correct |
679 ms |
331248 KB |
Output is correct |
39 |
Correct |
570 ms |
330580 KB |
Output is correct |
40 |
Correct |
586 ms |
330492 KB |
Output is correct |
41 |
Correct |
836 ms |
332112 KB |
Output is correct |
42 |
Correct |
889 ms |
332168 KB |
Output is correct |
43 |
Correct |
120 ms |
289972 KB |
Output is correct |
44 |
Correct |
851 ms |
332240 KB |
Output is correct |
45 |
Correct |
852 ms |
332204 KB |
Output is correct |
46 |
Correct |
815 ms |
332240 KB |
Output is correct |
47 |
Correct |
491 ms |
329156 KB |
Output is correct |
48 |
Correct |
477 ms |
329240 KB |
Output is correct |
49 |
Correct |
570 ms |
330516 KB |
Output is correct |
50 |
Correct |
586 ms |
331160 KB |
Output is correct |
51 |
Correct |
548 ms |
330440 KB |
Output is correct |
52 |
Execution timed out |
5047 ms |
514732 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |