#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l + r)>>1) + 1,r
#define pii pair<int,int>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace __gnu_pbds{
typedef tree<long long,
null_type,
less_equal<long long>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;
using namespace std;
const int N = 6000 + 5;
int S[N],T[N],X[N],Y[N],Z[N],ans[N];
int L,R,k;
map <int,int> mp;
ordered_set v[4*N];
ordered_set merge(ordered_set x, ordered_set y){
if (x.size() > y.size()) swap(x,y);
for (int i = 0; i < x.size(); i++)
y.insert(*(x.find_by_order(i)));
return y;
}
void upd(int h,int l,int r){
if (l == r){
v[h].insert(R);
return;
}
if (L > (l + r)/2) upd(right);
else upd(left);
v[h] = merge(v[h*2],v[h*2 + 1]);
}
int get(int h,int l,int r){
if (r < L || R < l) return 0;
if (L <= l && r <= R){
int len = v[h].size();
return len - v[h].order_of_key(k);
}
return get(left) + get(right);
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,q;
cin>>n>>q;
vector <int> v1;
vector <pair<pii,int> > vec;
for (int i = 1; i <= n; i++){
cin >> S[i] >> T[i];
v1.pb(S[i]);
vec.pb({{S[i] + T[i],2},i});
}
for (int i = 1; i <= q; i++){
cin >> X[i] >> Y[i] >> Z[i];
v1.pb(X[i]);
vec.pb({{Z[i],1},i});
}
sort(vec.begin(),vec.end());
sort(v1.begin(),v1.end());
int val = 0;
for (int i=0;i<(int)v1.size();i++){
if (!i || v1[i] != v1[i - 1]) ++val;
mp[v1[i]] = val;
}
for (int i=(int)vec.size()-1;i>=0;i--){
int id = vec[i].s;
if (vec[i].f.s == 2){
L = mp[S[id]];
R = T[id];
upd(1,1,n + q);
}else{
L = mp[X[id]];
R = n + q;
k = Y[id];
ans[id] = get(1,1,n + q);
}
}
for (int i = 1; i <= q; i++)
cout<<ans[i]<<endl;
}
Compilation message
examination.cpp: In function '__gnu_pbds::ordered_set merge(__gnu_pbds::ordered_set, __gnu_pbds::ordered_set)':
examination.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and '__gnu_pbds::detail::bin_search_tree_set<long long int, __gnu_pbds::null_type, std::less_equal<long long int>, __gnu_pbds::detail::tree_traits<long long int, __gnu_pbds::null_type, std::less_equal<long long int>, __gnu_pbds::tree_order_statistics_node_update, __gnu_pbds::rb_tree_tag, std::allocator<char> >, std::allocator<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1801 ms |
6448 KB |
Output is correct |
8 |
Correct |
1767 ms |
6228 KB |
Output is correct |
9 |
Correct |
1714 ms |
6380 KB |
Output is correct |
10 |
Correct |
1338 ms |
6500 KB |
Output is correct |
11 |
Execution timed out |
3052 ms |
4648 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1801 ms |
6448 KB |
Output is correct |
8 |
Correct |
1767 ms |
6228 KB |
Output is correct |
9 |
Correct |
1714 ms |
6380 KB |
Output is correct |
10 |
Correct |
1338 ms |
6500 KB |
Output is correct |
11 |
Execution timed out |
3052 ms |
4648 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |