#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
struct node1{
ll s, e, m, val, lazy;
node1 *l, *r;
node1(ll S, ll E){
s = S, e = E, m = (s+e)/2;
val = 0;
lazy = 0;
if(s != e){
l = new node1(s,m);
r = new node1(m + 1,e);
}
}
void propogate(){
if(lazy==0) return;
val = max(val,lazy);
if(s != e){ //not a leaf, send lazy tags to children (remember to write this if statement)
l->lazy = max(l -> lazy,lazy);
r->lazy = max(r -> lazy,lazy);
}
lazy = 0;
}
void update(int S, int E, ll V){
if(s == S && e == E) lazy = max(lazy,V);
else{
if(E <= m) l->update(S, E, V);
else if (m < S) r->update(S, E, V);
else l->update(S, m, V),r->update(m+1, E, V);
l->propogate(),r->propogate();
val = max(l->val,r->val);
}
}
ll query(int S, int E){
propogate(); //remember to propogate
if(s == S && e == E) return val;
else if(E <= m) return l->query(S, E);
else if(S >= m+1) return r->query(S, E);
else return max(l->query(S, m),r->query(m+1, E));
}
} *root1;
struct node{
ll s, e, m, val, lazy;
node *l, *r;
node(ll S, ll E){
s = S, e = E, m = (s+e)/2;
val = 0;
lazy = 0;
if(s != e){
l = new node(s,m);
r = new node(m + 1,e);
}
}
void propogate(){
if(lazy==0) return;
val += lazy*(e-s+1);
if(s != e){ //not a leaf, send lazy tags to children (remember to write this if statement)
l->lazy += lazy;
r->lazy += lazy;
}
lazy = 0;
}
void update(int S, int E, ll V){
if(s == S && e == E) lazy += V;
else{
if(E <= m) l->update(S, E, V);
else if (m < S) r->update(S, E, V);
else l->update(S, m, V),r->update(m+1, E, V);
l->propogate(),r->propogate();
val = l->val + r->val;
}
}
ll query(int S, int E){
propogate(); //remember to propogate
if(s == S && e == E) return val;
else if(E <= m) return l->query(S, E);
else if(S >= m+1) return r->query(S, E);
else return l->query(S, m) + r->query(m+1, E);
}
} *root2;
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,K;
cin>>N>>K;
root1 = new node1(0,MAXN);
root2 = new node(0,MAXN);
ll A[N], B[N], a[N], b[N];
vector<ll> d;
for(ll i = 0;i < N;i++){
cin>>A[i]>>B[i];
a[i] = A[i];
b[i] = B[i];
d.push_back(A[i]);
d.push_back(B[i]);
}
ll T[K];
for(ll i = 0;i < K;i++){
cin>>T[i];
d.push_back(T[i]);
}
sort(d.begin(),d.end());
d.resize(unique(d.begin(),d.end()) - d.begin());
for(ll i = 0;i < N;i++){
A[i] = lower_bound(d.begin(),d.end(),A[i]) - d.begin();
B[i] = lower_bound(d.begin(),d.end(),B[i]) - d.begin();
}
for(ll i = 0;i < K;i++){
T[i] = lower_bound(d.begin(),d.end(),T[i]) - d.begin();
}
vector<ll> v[MAXN]; //stores the i
for(ll i = 0;i < N;i++){
v[A[i]].push_back(i);
v[B[i]].push_back(i);
}
for(ll k = 0;k < K;k++){
root1 -> update(T[k],T[k],k + 1); //k is 1-indexed
}
ll sum = 0;
cout<<sum<<'\n';
}
Compilation message
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:89:17: warning: variable 'a' set but not used [-Wunused-but-set-variable]
89 | ll A[N], B[N], a[N], b[N];
| ^
fortune_telling2.cpp:89:23: warning: variable 'b' set but not used [-Wunused-but-set-variable]
89 | ll A[N], B[N], a[N], b[N];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
168 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
168 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
168 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |