# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
917896 |
2024-01-29T03:15:45 Z |
CSQ31 |
New Home (APIO18_new_home) |
C++17 |
|
5000 ms |
325080 KB |
#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),T;
multiset<int,greater<int>>lines[MAXT];
map<int,int>crd;
int N;
void upd(int v,int l,int r,int pos){
if(l==r){
if(lines[l].empty())T[v] = -1e9;
else T[v] = *lines[l].begin();
return;
}
int tm = (l+r)/2;
if(pos<=tm)upd(2*v,l,tm,pos);
else upd(2*v+1,tm+1,r,pos);
T[v] = max(T[2*v],T[2*v+1]);
}
int query(int v,int l,int r,int tl,int tr){
if(l>r)return -1e9;
if(l==tl && r==tr)return T[v];
int tm = (tl+tr)/2;
return max(query(2*v,l,min(r,tm),tl,tm),
query(2*v+1,max(l,tm+1),r,tm+1,tr));
}
int di(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 = di(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));
upd(1,0,N,i);
}
vector<pii>sweep;
vector<int>comp;
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--;
comp.pb(di(*l,x));
comp.pb(di(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--;
comp.pb(di(*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;
T.assign(4*(N+1),-1e9);
for(int i=1;i<=k;i++)change(-1e8,2e8,1);
//cout<<"TES"<<'\n';
//for(int x:comp)cout<<x<<" ";
//cout<<'\n';
for(auto z : sweep){
int t = z.fi;
int x = z.se;
if(t > k){
t-=k+1;
ans[t] = max(ans[t],query(1,0,crd[x],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(pii &x:sweep)x.se = 1e8 - x.se;
solve();
for(int i=0;i<q;i++){
if(ans[i]>=1e8)ans[i] = -1;
cout<<ans[i]<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
142420 KB |
Output is correct |
2 |
Correct |
39 ms |
142420 KB |
Output is correct |
3 |
Correct |
39 ms |
142420 KB |
Output is correct |
4 |
Correct |
38 ms |
142420 KB |
Output is correct |
5 |
Correct |
38 ms |
142572 KB |
Output is correct |
6 |
Correct |
41 ms |
142936 KB |
Output is correct |
7 |
Correct |
41 ms |
142676 KB |
Output is correct |
8 |
Correct |
40 ms |
142680 KB |
Output is correct |
9 |
Correct |
41 ms |
142676 KB |
Output is correct |
10 |
Correct |
41 ms |
142684 KB |
Output is correct |
11 |
Correct |
39 ms |
142672 KB |
Output is correct |
12 |
Correct |
40 ms |
142684 KB |
Output is correct |
13 |
Correct |
42 ms |
142684 KB |
Output is correct |
14 |
Correct |
44 ms |
142684 KB |
Output is correct |
15 |
Correct |
42 ms |
142684 KB |
Output is correct |
16 |
Correct |
40 ms |
142680 KB |
Output is correct |
17 |
Correct |
41 ms |
142684 KB |
Output is correct |
18 |
Correct |
41 ms |
142676 KB |
Output is correct |
19 |
Correct |
41 ms |
142788 KB |
Output is correct |
20 |
Correct |
41 ms |
142784 KB |
Output is correct |
21 |
Correct |
39 ms |
142424 KB |
Output is correct |
22 |
Correct |
41 ms |
142676 KB |
Output is correct |
23 |
Correct |
40 ms |
142780 KB |
Output is correct |
24 |
Correct |
41 ms |
142684 KB |
Output is correct |
25 |
Correct |
41 ms |
142676 KB |
Output is correct |
26 |
Correct |
42 ms |
142728 KB |
Output is correct |
27 |
Correct |
40 ms |
142416 KB |
Output is correct |
28 |
Correct |
45 ms |
142672 KB |
Output is correct |
29 |
Correct |
40 ms |
142684 KB |
Output is correct |
30 |
Correct |
39 ms |
142816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
142420 KB |
Output is correct |
2 |
Correct |
39 ms |
142420 KB |
Output is correct |
3 |
Correct |
39 ms |
142420 KB |
Output is correct |
4 |
Correct |
38 ms |
142420 KB |
Output is correct |
5 |
Correct |
38 ms |
142572 KB |
Output is correct |
6 |
Correct |
41 ms |
142936 KB |
Output is correct |
7 |
Correct |
41 ms |
142676 KB |
Output is correct |
8 |
Correct |
40 ms |
142680 KB |
Output is correct |
9 |
Correct |
41 ms |
142676 KB |
Output is correct |
10 |
Correct |
41 ms |
142684 KB |
Output is correct |
11 |
Correct |
39 ms |
142672 KB |
Output is correct |
12 |
Correct |
40 ms |
142684 KB |
Output is correct |
13 |
Correct |
42 ms |
142684 KB |
Output is correct |
14 |
Correct |
44 ms |
142684 KB |
Output is correct |
15 |
Correct |
42 ms |
142684 KB |
Output is correct |
16 |
Correct |
40 ms |
142680 KB |
Output is correct |
17 |
Correct |
41 ms |
142684 KB |
Output is correct |
18 |
Correct |
41 ms |
142676 KB |
Output is correct |
19 |
Correct |
41 ms |
142788 KB |
Output is correct |
20 |
Correct |
41 ms |
142784 KB |
Output is correct |
21 |
Correct |
39 ms |
142424 KB |
Output is correct |
22 |
Correct |
41 ms |
142676 KB |
Output is correct |
23 |
Correct |
40 ms |
142780 KB |
Output is correct |
24 |
Correct |
41 ms |
142684 KB |
Output is correct |
25 |
Correct |
41 ms |
142676 KB |
Output is correct |
26 |
Correct |
42 ms |
142728 KB |
Output is correct |
27 |
Correct |
40 ms |
142416 KB |
Output is correct |
28 |
Correct |
45 ms |
142672 KB |
Output is correct |
29 |
Correct |
40 ms |
142684 KB |
Output is correct |
30 |
Correct |
39 ms |
142816 KB |
Output is correct |
31 |
Correct |
1189 ms |
185028 KB |
Output is correct |
32 |
Correct |
167 ms |
148088 KB |
Output is correct |
33 |
Correct |
1139 ms |
187260 KB |
Output is correct |
34 |
Correct |
1166 ms |
184084 KB |
Output is correct |
35 |
Correct |
1292 ms |
187816 KB |
Output is correct |
36 |
Correct |
1202 ms |
191092 KB |
Output is correct |
37 |
Correct |
721 ms |
182508 KB |
Output is correct |
38 |
Correct |
710 ms |
185544 KB |
Output is correct |
39 |
Correct |
569 ms |
181904 KB |
Output is correct |
40 |
Correct |
620 ms |
185048 KB |
Output is correct |
41 |
Correct |
905 ms |
183272 KB |
Output is correct |
42 |
Correct |
884 ms |
186268 KB |
Output is correct |
43 |
Correct |
93 ms |
151528 KB |
Output is correct |
44 |
Correct |
877 ms |
183200 KB |
Output is correct |
45 |
Correct |
832 ms |
183020 KB |
Output is correct |
46 |
Correct |
788 ms |
182984 KB |
Output is correct |
47 |
Correct |
472 ms |
180876 KB |
Output is correct |
48 |
Correct |
503 ms |
183904 KB |
Output is correct |
49 |
Correct |
525 ms |
181704 KB |
Output is correct |
50 |
Correct |
589 ms |
185768 KB |
Output is correct |
51 |
Correct |
534 ms |
185032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5038 ms |
304024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5012 ms |
325080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
142420 KB |
Output is correct |
2 |
Correct |
39 ms |
142420 KB |
Output is correct |
3 |
Correct |
39 ms |
142420 KB |
Output is correct |
4 |
Correct |
38 ms |
142420 KB |
Output is correct |
5 |
Correct |
38 ms |
142572 KB |
Output is correct |
6 |
Correct |
41 ms |
142936 KB |
Output is correct |
7 |
Correct |
41 ms |
142676 KB |
Output is correct |
8 |
Correct |
40 ms |
142680 KB |
Output is correct |
9 |
Correct |
41 ms |
142676 KB |
Output is correct |
10 |
Correct |
41 ms |
142684 KB |
Output is correct |
11 |
Correct |
39 ms |
142672 KB |
Output is correct |
12 |
Correct |
40 ms |
142684 KB |
Output is correct |
13 |
Correct |
42 ms |
142684 KB |
Output is correct |
14 |
Correct |
44 ms |
142684 KB |
Output is correct |
15 |
Correct |
42 ms |
142684 KB |
Output is correct |
16 |
Correct |
40 ms |
142680 KB |
Output is correct |
17 |
Correct |
41 ms |
142684 KB |
Output is correct |
18 |
Correct |
41 ms |
142676 KB |
Output is correct |
19 |
Correct |
41 ms |
142788 KB |
Output is correct |
20 |
Correct |
41 ms |
142784 KB |
Output is correct |
21 |
Correct |
39 ms |
142424 KB |
Output is correct |
22 |
Correct |
41 ms |
142676 KB |
Output is correct |
23 |
Correct |
40 ms |
142780 KB |
Output is correct |
24 |
Correct |
41 ms |
142684 KB |
Output is correct |
25 |
Correct |
41 ms |
142676 KB |
Output is correct |
26 |
Correct |
42 ms |
142728 KB |
Output is correct |
27 |
Correct |
40 ms |
142416 KB |
Output is correct |
28 |
Correct |
45 ms |
142672 KB |
Output is correct |
29 |
Correct |
40 ms |
142684 KB |
Output is correct |
30 |
Correct |
39 ms |
142816 KB |
Output is correct |
31 |
Correct |
1189 ms |
185028 KB |
Output is correct |
32 |
Correct |
167 ms |
148088 KB |
Output is correct |
33 |
Correct |
1139 ms |
187260 KB |
Output is correct |
34 |
Correct |
1166 ms |
184084 KB |
Output is correct |
35 |
Correct |
1292 ms |
187816 KB |
Output is correct |
36 |
Correct |
1202 ms |
191092 KB |
Output is correct |
37 |
Correct |
721 ms |
182508 KB |
Output is correct |
38 |
Correct |
710 ms |
185544 KB |
Output is correct |
39 |
Correct |
569 ms |
181904 KB |
Output is correct |
40 |
Correct |
620 ms |
185048 KB |
Output is correct |
41 |
Correct |
905 ms |
183272 KB |
Output is correct |
42 |
Correct |
884 ms |
186268 KB |
Output is correct |
43 |
Correct |
93 ms |
151528 KB |
Output is correct |
44 |
Correct |
877 ms |
183200 KB |
Output is correct |
45 |
Correct |
832 ms |
183020 KB |
Output is correct |
46 |
Correct |
788 ms |
182984 KB |
Output is correct |
47 |
Correct |
472 ms |
180876 KB |
Output is correct |
48 |
Correct |
503 ms |
183904 KB |
Output is correct |
49 |
Correct |
525 ms |
181704 KB |
Output is correct |
50 |
Correct |
589 ms |
185768 KB |
Output is correct |
51 |
Correct |
534 ms |
185032 KB |
Output is correct |
52 |
Correct |
1072 ms |
195788 KB |
Output is correct |
53 |
Correct |
1059 ms |
192292 KB |
Output is correct |
54 |
Correct |
1214 ms |
190000 KB |
Output is correct |
55 |
Correct |
927 ms |
187584 KB |
Output is correct |
56 |
Correct |
837 ms |
190940 KB |
Output is correct |
57 |
Correct |
875 ms |
184428 KB |
Output is correct |
58 |
Correct |
965 ms |
187188 KB |
Output is correct |
59 |
Correct |
921 ms |
191192 KB |
Output is correct |
60 |
Correct |
865 ms |
187660 KB |
Output is correct |
61 |
Correct |
204 ms |
166188 KB |
Output is correct |
62 |
Correct |
1218 ms |
196304 KB |
Output is correct |
63 |
Correct |
1244 ms |
191556 KB |
Output is correct |
64 |
Correct |
1190 ms |
189180 KB |
Output is correct |
65 |
Correct |
1108 ms |
188304 KB |
Output is correct |
66 |
Correct |
928 ms |
183252 KB |
Output is correct |
67 |
Correct |
266 ms |
150468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
142420 KB |
Output is correct |
2 |
Correct |
39 ms |
142420 KB |
Output is correct |
3 |
Correct |
39 ms |
142420 KB |
Output is correct |
4 |
Correct |
38 ms |
142420 KB |
Output is correct |
5 |
Correct |
38 ms |
142572 KB |
Output is correct |
6 |
Correct |
41 ms |
142936 KB |
Output is correct |
7 |
Correct |
41 ms |
142676 KB |
Output is correct |
8 |
Correct |
40 ms |
142680 KB |
Output is correct |
9 |
Correct |
41 ms |
142676 KB |
Output is correct |
10 |
Correct |
41 ms |
142684 KB |
Output is correct |
11 |
Correct |
39 ms |
142672 KB |
Output is correct |
12 |
Correct |
40 ms |
142684 KB |
Output is correct |
13 |
Correct |
42 ms |
142684 KB |
Output is correct |
14 |
Correct |
44 ms |
142684 KB |
Output is correct |
15 |
Correct |
42 ms |
142684 KB |
Output is correct |
16 |
Correct |
40 ms |
142680 KB |
Output is correct |
17 |
Correct |
41 ms |
142684 KB |
Output is correct |
18 |
Correct |
41 ms |
142676 KB |
Output is correct |
19 |
Correct |
41 ms |
142788 KB |
Output is correct |
20 |
Correct |
41 ms |
142784 KB |
Output is correct |
21 |
Correct |
39 ms |
142424 KB |
Output is correct |
22 |
Correct |
41 ms |
142676 KB |
Output is correct |
23 |
Correct |
40 ms |
142780 KB |
Output is correct |
24 |
Correct |
41 ms |
142684 KB |
Output is correct |
25 |
Correct |
41 ms |
142676 KB |
Output is correct |
26 |
Correct |
42 ms |
142728 KB |
Output is correct |
27 |
Correct |
40 ms |
142416 KB |
Output is correct |
28 |
Correct |
45 ms |
142672 KB |
Output is correct |
29 |
Correct |
40 ms |
142684 KB |
Output is correct |
30 |
Correct |
39 ms |
142816 KB |
Output is correct |
31 |
Correct |
1189 ms |
185028 KB |
Output is correct |
32 |
Correct |
167 ms |
148088 KB |
Output is correct |
33 |
Correct |
1139 ms |
187260 KB |
Output is correct |
34 |
Correct |
1166 ms |
184084 KB |
Output is correct |
35 |
Correct |
1292 ms |
187816 KB |
Output is correct |
36 |
Correct |
1202 ms |
191092 KB |
Output is correct |
37 |
Correct |
721 ms |
182508 KB |
Output is correct |
38 |
Correct |
710 ms |
185544 KB |
Output is correct |
39 |
Correct |
569 ms |
181904 KB |
Output is correct |
40 |
Correct |
620 ms |
185048 KB |
Output is correct |
41 |
Correct |
905 ms |
183272 KB |
Output is correct |
42 |
Correct |
884 ms |
186268 KB |
Output is correct |
43 |
Correct |
93 ms |
151528 KB |
Output is correct |
44 |
Correct |
877 ms |
183200 KB |
Output is correct |
45 |
Correct |
832 ms |
183020 KB |
Output is correct |
46 |
Correct |
788 ms |
182984 KB |
Output is correct |
47 |
Correct |
472 ms |
180876 KB |
Output is correct |
48 |
Correct |
503 ms |
183904 KB |
Output is correct |
49 |
Correct |
525 ms |
181704 KB |
Output is correct |
50 |
Correct |
589 ms |
185768 KB |
Output is correct |
51 |
Correct |
534 ms |
185032 KB |
Output is correct |
52 |
Execution timed out |
5038 ms |
304024 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |